UNPKG

1.88 MBJavaScriptView Raw
1/**
2 * @licstart The following is the entire license notice for the
3 * JavaScript code in this page
4 *
5 * Copyright 2023 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/******/ // The require scope
24/******/ var __webpack_require__ = {};
25/******/
26/************************************************************************/
27/******/ /* webpack/runtime/define property getters */
28/******/ (() => {
29/******/ // define getter functions for harmony exports
30/******/ __webpack_require__.d = (exports, definition) => {
31/******/ for(var key in definition) {
32/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
33/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
34/******/ }
35/******/ }
36/******/ };
37/******/ })();
38/******/
39/******/ /* webpack/runtime/hasOwnProperty shorthand */
40/******/ (() => {
41/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
42/******/ })();
43/******/
44/************************************************************************/
45var __webpack_exports__ = globalThis.pdfjsWorker = {};
46
47// EXPORTS
48__webpack_require__.d(__webpack_exports__, {
49 WorkerMessageHandler: () => (/* reexport */ WorkerMessageHandler)
50});
51
52;// CONCATENATED MODULE: ./src/shared/util.js
53const isNodeJS = typeof process === "object" && process + "" === "[object process]" && !process.versions.nw && !(process.versions.electron && process.type && process.type !== "browser");
54const IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
55const FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
56const MAX_IMAGE_SIZE_TO_CACHE = 10e6;
57const LINE_FACTOR = 1.35;
58const LINE_DESCENT_FACTOR = 0.35;
59const BASELINE_FACTOR = LINE_DESCENT_FACTOR / LINE_FACTOR;
60const RenderingIntentFlag = {
61 ANY: 0x01,
62 DISPLAY: 0x02,
63 PRINT: 0x04,
64 SAVE: 0x08,
65 ANNOTATIONS_FORMS: 0x10,
66 ANNOTATIONS_STORAGE: 0x20,
67 ANNOTATIONS_DISABLE: 0x40,
68 OPLIST: 0x100
69};
70const AnnotationMode = {
71 DISABLE: 0,
72 ENABLE: 1,
73 ENABLE_FORMS: 2,
74 ENABLE_STORAGE: 3
75};
76const AnnotationEditorPrefix = "pdfjs_internal_editor_";
77const AnnotationEditorType = {
78 DISABLE: -1,
79 NONE: 0,
80 FREETEXT: 3,
81 HIGHLIGHT: 9,
82 STAMP: 13,
83 INK: 15
84};
85const AnnotationEditorParamsType = {
86 RESIZE: 1,
87 CREATE: 2,
88 FREETEXT_SIZE: 11,
89 FREETEXT_COLOR: 12,
90 FREETEXT_OPACITY: 13,
91 INK_COLOR: 21,
92 INK_THICKNESS: 22,
93 INK_OPACITY: 23,
94 HIGHLIGHT_COLOR: 31,
95 HIGHLIGHT_DEFAULT_COLOR: 32,
96 HIGHLIGHT_THICKNESS: 33,
97 HIGHLIGHT_FREE: 34,
98 HIGHLIGHT_SHOW_ALL: 35
99};
100const PermissionFlag = {
101 PRINT: 0x04,
102 MODIFY_CONTENTS: 0x08,
103 COPY: 0x10,
104 MODIFY_ANNOTATIONS: 0x20,
105 FILL_INTERACTIVE_FORMS: 0x100,
106 COPY_FOR_ACCESSIBILITY: 0x200,
107 ASSEMBLE: 0x400,
108 PRINT_HIGH_QUALITY: 0x800
109};
110const TextRenderingMode = {
111 FILL: 0,
112 STROKE: 1,
113 FILL_STROKE: 2,
114 INVISIBLE: 3,
115 FILL_ADD_TO_PATH: 4,
116 STROKE_ADD_TO_PATH: 5,
117 FILL_STROKE_ADD_TO_PATH: 6,
118 ADD_TO_PATH: 7,
119 FILL_STROKE_MASK: 3,
120 ADD_TO_PATH_FLAG: 4
121};
122const ImageKind = {
123 GRAYSCALE_1BPP: 1,
124 RGB_24BPP: 2,
125 RGBA_32BPP: 3
126};
127const AnnotationType = {
128 TEXT: 1,
129 LINK: 2,
130 FREETEXT: 3,
131 LINE: 4,
132 SQUARE: 5,
133 CIRCLE: 6,
134 POLYGON: 7,
135 POLYLINE: 8,
136 HIGHLIGHT: 9,
137 UNDERLINE: 10,
138 SQUIGGLY: 11,
139 STRIKEOUT: 12,
140 STAMP: 13,
141 CARET: 14,
142 INK: 15,
143 POPUP: 16,
144 FILEATTACHMENT: 17,
145 SOUND: 18,
146 MOVIE: 19,
147 WIDGET: 20,
148 SCREEN: 21,
149 PRINTERMARK: 22,
150 TRAPNET: 23,
151 WATERMARK: 24,
152 THREED: 25,
153 REDACT: 26
154};
155const AnnotationReplyType = {
156 GROUP: "Group",
157 REPLY: "R"
158};
159const AnnotationFlag = {
160 INVISIBLE: 0x01,
161 HIDDEN: 0x02,
162 PRINT: 0x04,
163 NOZOOM: 0x08,
164 NOROTATE: 0x10,
165 NOVIEW: 0x20,
166 READONLY: 0x40,
167 LOCKED: 0x80,
168 TOGGLENOVIEW: 0x100,
169 LOCKEDCONTENTS: 0x200
170};
171const AnnotationFieldFlag = {
172 READONLY: 0x0000001,
173 REQUIRED: 0x0000002,
174 NOEXPORT: 0x0000004,
175 MULTILINE: 0x0001000,
176 PASSWORD: 0x0002000,
177 NOTOGGLETOOFF: 0x0004000,
178 RADIO: 0x0008000,
179 PUSHBUTTON: 0x0010000,
180 COMBO: 0x0020000,
181 EDIT: 0x0040000,
182 SORT: 0x0080000,
183 FILESELECT: 0x0100000,
184 MULTISELECT: 0x0200000,
185 DONOTSPELLCHECK: 0x0400000,
186 DONOTSCROLL: 0x0800000,
187 COMB: 0x1000000,
188 RICHTEXT: 0x2000000,
189 RADIOSINUNISON: 0x2000000,
190 COMMITONSELCHANGE: 0x4000000
191};
192const AnnotationBorderStyleType = {
193 SOLID: 1,
194 DASHED: 2,
195 BEVELED: 3,
196 INSET: 4,
197 UNDERLINE: 5
198};
199const AnnotationActionEventType = {
200 E: "Mouse Enter",
201 X: "Mouse Exit",
202 D: "Mouse Down",
203 U: "Mouse Up",
204 Fo: "Focus",
205 Bl: "Blur",
206 PO: "PageOpen",
207 PC: "PageClose",
208 PV: "PageVisible",
209 PI: "PageInvisible",
210 K: "Keystroke",
211 F: "Format",
212 V: "Validate",
213 C: "Calculate"
214};
215const DocumentActionEventType = {
216 WC: "WillClose",
217 WS: "WillSave",
218 DS: "DidSave",
219 WP: "WillPrint",
220 DP: "DidPrint"
221};
222const PageActionEventType = {
223 O: "PageOpen",
224 C: "PageClose"
225};
226const VerbosityLevel = {
227 ERRORS: 0,
228 WARNINGS: 1,
229 INFOS: 5
230};
231const CMapCompressionType = {
232 NONE: 0,
233 BINARY: 1
234};
235const OPS = {
236 dependency: 1,
237 setLineWidth: 2,
238 setLineCap: 3,
239 setLineJoin: 4,
240 setMiterLimit: 5,
241 setDash: 6,
242 setRenderingIntent: 7,
243 setFlatness: 8,
244 setGState: 9,
245 save: 10,
246 restore: 11,
247 transform: 12,
248 moveTo: 13,
249 lineTo: 14,
250 curveTo: 15,
251 curveTo2: 16,
252 curveTo3: 17,
253 closePath: 18,
254 rectangle: 19,
255 stroke: 20,
256 closeStroke: 21,
257 fill: 22,
258 eoFill: 23,
259 fillStroke: 24,
260 eoFillStroke: 25,
261 closeFillStroke: 26,
262 closeEOFillStroke: 27,
263 endPath: 28,
264 clip: 29,
265 eoClip: 30,
266 beginText: 31,
267 endText: 32,
268 setCharSpacing: 33,
269 setWordSpacing: 34,
270 setHScale: 35,
271 setLeading: 36,
272 setFont: 37,
273 setTextRenderingMode: 38,
274 setTextRise: 39,
275 moveText: 40,
276 setLeadingMoveText: 41,
277 setTextMatrix: 42,
278 nextLine: 43,
279 showText: 44,
280 showSpacedText: 45,
281 nextLineShowText: 46,
282 nextLineSetSpacingShowText: 47,
283 setCharWidth: 48,
284 setCharWidthAndBounds: 49,
285 setStrokeColorSpace: 50,
286 setFillColorSpace: 51,
287 setStrokeColor: 52,
288 setStrokeColorN: 53,
289 setFillColor: 54,
290 setFillColorN: 55,
291 setStrokeGray: 56,
292 setFillGray: 57,
293 setStrokeRGBColor: 58,
294 setFillRGBColor: 59,
295 setStrokeCMYKColor: 60,
296 setFillCMYKColor: 61,
297 shadingFill: 62,
298 beginInlineImage: 63,
299 beginImageData: 64,
300 endInlineImage: 65,
301 paintXObject: 66,
302 markPoint: 67,
303 markPointProps: 68,
304 beginMarkedContent: 69,
305 beginMarkedContentProps: 70,
306 endMarkedContent: 71,
307 beginCompat: 72,
308 endCompat: 73,
309 paintFormXObjectBegin: 74,
310 paintFormXObjectEnd: 75,
311 beginGroup: 76,
312 endGroup: 77,
313 beginAnnotation: 80,
314 endAnnotation: 81,
315 paintImageMaskXObject: 83,
316 paintImageMaskXObjectGroup: 84,
317 paintImageXObject: 85,
318 paintInlineImageXObject: 86,
319 paintInlineImageXObjectGroup: 87,
320 paintImageXObjectRepeat: 88,
321 paintImageMaskXObjectRepeat: 89,
322 paintSolidColorImageMask: 90,
323 constructPath: 91
324};
325const PasswordResponses = {
326 NEED_PASSWORD: 1,
327 INCORRECT_PASSWORD: 2
328};
329let verbosity = VerbosityLevel.WARNINGS;
330function setVerbosityLevel(level) {
331 if (Number.isInteger(level)) {
332 verbosity = level;
333 }
334}
335function getVerbosityLevel() {
336 return verbosity;
337}
338function info(msg) {
339 if (verbosity >= VerbosityLevel.INFOS) {
340 console.log(`Info: ${msg}`);
341 }
342}
343function warn(msg) {
344 if (verbosity >= VerbosityLevel.WARNINGS) {
345 console.log(`Warning: ${msg}`);
346 }
347}
348function unreachable(msg) {
349 throw new Error(msg);
350}
351function assert(cond, msg) {
352 if (!cond) {
353 unreachable(msg);
354 }
355}
356function _isValidProtocol(url) {
357 switch (url?.protocol) {
358 case "http:":
359 case "https:":
360 case "ftp:":
361 case "mailto:":
362 case "tel:":
363 return true;
364 default:
365 return false;
366 }
367}
368function createValidAbsoluteUrl(url, baseUrl = null, options = null) {
369 if (!url) {
370 return null;
371 }
372 try {
373 if (options && typeof url === "string") {
374 if (options.addDefaultProtocol && url.startsWith("www.")) {
375 const dots = url.match(/\./g);
376 if (dots?.length >= 2) {
377 url = `http://${url}`;
378 }
379 }
380 if (options.tryConvertEncoding) {
381 try {
382 url = stringToUTF8String(url);
383 } catch {}
384 }
385 }
386 const absoluteUrl = baseUrl ? new URL(url, baseUrl) : new URL(url);
387 if (_isValidProtocol(absoluteUrl)) {
388 return absoluteUrl;
389 }
390 } catch {}
391 return null;
392}
393function shadow(obj, prop, value, nonSerializable = false) {
394 Object.defineProperty(obj, prop, {
395 value,
396 enumerable: !nonSerializable,
397 configurable: true,
398 writable: false
399 });
400 return value;
401}
402const BaseException = function BaseExceptionClosure() {
403 function BaseException(message, name) {
404 if (this.constructor === BaseException) {
405 unreachable("Cannot initialize BaseException.");
406 }
407 this.message = message;
408 this.name = name;
409 }
410 BaseException.prototype = new Error();
411 BaseException.constructor = BaseException;
412 return BaseException;
413}();
414class PasswordException extends BaseException {
415 constructor(msg, code) {
416 super(msg, "PasswordException");
417 this.code = code;
418 }
419}
420class UnknownErrorException extends BaseException {
421 constructor(msg, details) {
422 super(msg, "UnknownErrorException");
423 this.details = details;
424 }
425}
426class InvalidPDFException extends BaseException {
427 constructor(msg) {
428 super(msg, "InvalidPDFException");
429 }
430}
431class MissingPDFException extends BaseException {
432 constructor(msg) {
433 super(msg, "MissingPDFException");
434 }
435}
436class UnexpectedResponseException extends BaseException {
437 constructor(msg, status) {
438 super(msg, "UnexpectedResponseException");
439 this.status = status;
440 }
441}
442class FormatError extends BaseException {
443 constructor(msg) {
444 super(msg, "FormatError");
445 }
446}
447class AbortException extends BaseException {
448 constructor(msg) {
449 super(msg, "AbortException");
450 }
451}
452function bytesToString(bytes) {
453 if (typeof bytes !== "object" || bytes?.length === undefined) {
454 unreachable("Invalid argument for bytesToString");
455 }
456 const length = bytes.length;
457 const MAX_ARGUMENT_COUNT = 8192;
458 if (length < MAX_ARGUMENT_COUNT) {
459 return String.fromCharCode.apply(null, bytes);
460 }
461 const strBuf = [];
462 for (let i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
463 const chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
464 const chunk = bytes.subarray(i, chunkEnd);
465 strBuf.push(String.fromCharCode.apply(null, chunk));
466 }
467 return strBuf.join("");
468}
469function stringToBytes(str) {
470 if (typeof str !== "string") {
471 unreachable("Invalid argument for stringToBytes");
472 }
473 const length = str.length;
474 const bytes = new Uint8Array(length);
475 for (let i = 0; i < length; ++i) {
476 bytes[i] = str.charCodeAt(i) & 0xff;
477 }
478 return bytes;
479}
480function string32(value) {
481 return String.fromCharCode(value >> 24 & 0xff, value >> 16 & 0xff, value >> 8 & 0xff, value & 0xff);
482}
483function objectSize(obj) {
484 return Object.keys(obj).length;
485}
486function objectFromMap(map) {
487 const obj = Object.create(null);
488 for (const [key, value] of map) {
489 obj[key] = value;
490 }
491 return obj;
492}
493function isLittleEndian() {
494 const buffer8 = new Uint8Array(4);
495 buffer8[0] = 1;
496 const view32 = new Uint32Array(buffer8.buffer, 0, 1);
497 return view32[0] === 1;
498}
499function isEvalSupported() {
500 try {
501 new Function("");
502 return true;
503 } catch {
504 return false;
505 }
506}
507class FeatureTest {
508 static get isLittleEndian() {
509 return shadow(this, "isLittleEndian", isLittleEndian());
510 }
511 static get isEvalSupported() {
512 return shadow(this, "isEvalSupported", isEvalSupported());
513 }
514 static get isOffscreenCanvasSupported() {
515 return shadow(this, "isOffscreenCanvasSupported", typeof OffscreenCanvas !== "undefined");
516 }
517 static get platform() {
518 if (typeof navigator !== "undefined" && typeof navigator?.platform === "string") {
519 return shadow(this, "platform", {
520 isMac: navigator.platform.includes("Mac")
521 });
522 }
523 return shadow(this, "platform", {
524 isMac: false
525 });
526 }
527 static get isCSSRoundSupported() {
528 return shadow(this, "isCSSRoundSupported", globalThis.CSS?.supports?.("width: round(1.5px, 1px)"));
529 }
530}
531const hexNumbers = Array.from(Array(256).keys(), n => n.toString(16).padStart(2, "0"));
532class Util {
533 static makeHexColor(r, g, b) {
534 return `#${hexNumbers[r]}${hexNumbers[g]}${hexNumbers[b]}`;
535 }
536 static scaleMinMax(transform, minMax) {
537 let temp;
538 if (transform[0]) {
539 if (transform[0] < 0) {
540 temp = minMax[0];
541 minMax[0] = minMax[2];
542 minMax[2] = temp;
543 }
544 minMax[0] *= transform[0];
545 minMax[2] *= transform[0];
546 if (transform[3] < 0) {
547 temp = minMax[1];
548 minMax[1] = minMax[3];
549 minMax[3] = temp;
550 }
551 minMax[1] *= transform[3];
552 minMax[3] *= transform[3];
553 } else {
554 temp = minMax[0];
555 minMax[0] = minMax[1];
556 minMax[1] = temp;
557 temp = minMax[2];
558 minMax[2] = minMax[3];
559 minMax[3] = temp;
560 if (transform[1] < 0) {
561 temp = minMax[1];
562 minMax[1] = minMax[3];
563 minMax[3] = temp;
564 }
565 minMax[1] *= transform[1];
566 minMax[3] *= transform[1];
567 if (transform[2] < 0) {
568 temp = minMax[0];
569 minMax[0] = minMax[2];
570 minMax[2] = temp;
571 }
572 minMax[0] *= transform[2];
573 minMax[2] *= transform[2];
574 }
575 minMax[0] += transform[4];
576 minMax[1] += transform[5];
577 minMax[2] += transform[4];
578 minMax[3] += transform[5];
579 }
580 static transform(m1, m2) {
581 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]];
582 }
583 static applyTransform(p, m) {
584 const xt = p[0] * m[0] + p[1] * m[2] + m[4];
585 const yt = p[0] * m[1] + p[1] * m[3] + m[5];
586 return [xt, yt];
587 }
588 static applyInverseTransform(p, m) {
589 const d = m[0] * m[3] - m[1] * m[2];
590 const xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
591 const yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
592 return [xt, yt];
593 }
594 static getAxialAlignedBoundingBox(r, m) {
595 const p1 = this.applyTransform(r, m);
596 const p2 = this.applyTransform(r.slice(2, 4), m);
597 const p3 = this.applyTransform([r[0], r[3]], m);
598 const p4 = this.applyTransform([r[2], r[1]], m);
599 return [Math.min(p1[0], p2[0], p3[0], p4[0]), Math.min(p1[1], p2[1], p3[1], p4[1]), Math.max(p1[0], p2[0], p3[0], p4[0]), Math.max(p1[1], p2[1], p3[1], p4[1])];
600 }
601 static inverseTransform(m) {
602 const d = m[0] * m[3] - m[1] * m[2];
603 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];
604 }
605 static singularValueDecompose2dScale(m) {
606 const transpose = [m[0], m[2], m[1], m[3]];
607 const a = m[0] * transpose[0] + m[1] * transpose[2];
608 const b = m[0] * transpose[1] + m[1] * transpose[3];
609 const c = m[2] * transpose[0] + m[3] * transpose[2];
610 const d = m[2] * transpose[1] + m[3] * transpose[3];
611 const first = (a + d) / 2;
612 const second = Math.sqrt((a + d) ** 2 - 4 * (a * d - c * b)) / 2;
613 const sx = first + second || 1;
614 const sy = first - second || 1;
615 return [Math.sqrt(sx), Math.sqrt(sy)];
616 }
617 static normalizeRect(rect) {
618 const r = rect.slice(0);
619 if (rect[0] > rect[2]) {
620 r[0] = rect[2];
621 r[2] = rect[0];
622 }
623 if (rect[1] > rect[3]) {
624 r[1] = rect[3];
625 r[3] = rect[1];
626 }
627 return r;
628 }
629 static intersect(rect1, rect2) {
630 const xLow = Math.max(Math.min(rect1[0], rect1[2]), Math.min(rect2[0], rect2[2]));
631 const xHigh = Math.min(Math.max(rect1[0], rect1[2]), Math.max(rect2[0], rect2[2]));
632 if (xLow > xHigh) {
633 return null;
634 }
635 const yLow = Math.max(Math.min(rect1[1], rect1[3]), Math.min(rect2[1], rect2[3]));
636 const yHigh = Math.min(Math.max(rect1[1], rect1[3]), Math.max(rect2[1], rect2[3]));
637 if (yLow > yHigh) {
638 return null;
639 }
640 return [xLow, yLow, xHigh, yHigh];
641 }
642 static #getExtremumOnCurve(x0, x1, x2, x3, y0, y1, y2, y3, t, minMax) {
643 if (t <= 0 || t >= 1) {
644 return;
645 }
646 const mt = 1 - t;
647 const tt = t * t;
648 const ttt = tt * t;
649 const x = mt * (mt * (mt * x0 + 3 * t * x1) + 3 * tt * x2) + ttt * x3;
650 const y = mt * (mt * (mt * y0 + 3 * t * y1) + 3 * tt * y2) + ttt * y3;
651 minMax[0] = Math.min(minMax[0], x);
652 minMax[1] = Math.min(minMax[1], y);
653 minMax[2] = Math.max(minMax[2], x);
654 minMax[3] = Math.max(minMax[3], y);
655 }
656 static #getExtremum(x0, x1, x2, x3, y0, y1, y2, y3, a, b, c, minMax) {
657 if (Math.abs(a) < 1e-12) {
658 if (Math.abs(b) >= 1e-12) {
659 this.#getExtremumOnCurve(x0, x1, x2, x3, y0, y1, y2, y3, -c / b, minMax);
660 }
661 return;
662 }
663 const delta = b ** 2 - 4 * c * a;
664 if (delta < 0) {
665 return;
666 }
667 const sqrtDelta = Math.sqrt(delta);
668 const a2 = 2 * a;
669 this.#getExtremumOnCurve(x0, x1, x2, x3, y0, y1, y2, y3, (-b + sqrtDelta) / a2, minMax);
670 this.#getExtremumOnCurve(x0, x1, x2, x3, y0, y1, y2, y3, (-b - sqrtDelta) / a2, minMax);
671 }
672 static bezierBoundingBox(x0, y0, x1, y1, x2, y2, x3, y3, minMax) {
673 if (minMax) {
674 minMax[0] = Math.min(minMax[0], x0, x3);
675 minMax[1] = Math.min(minMax[1], y0, y3);
676 minMax[2] = Math.max(minMax[2], x0, x3);
677 minMax[3] = Math.max(minMax[3], y0, y3);
678 } else {
679 minMax = [Math.min(x0, x3), Math.min(y0, y3), Math.max(x0, x3), Math.max(y0, y3)];
680 }
681 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);
682 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);
683 return minMax;
684 }
685}
686const 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];
687function stringToPDFString(str) {
688 if (str[0] >= "\xEF") {
689 let encoding;
690 if (str[0] === "\xFE" && str[1] === "\xFF") {
691 encoding = "utf-16be";
692 if (str.length % 2 === 1) {
693 str = str.slice(0, -1);
694 }
695 } else if (str[0] === "\xFF" && str[1] === "\xFE") {
696 encoding = "utf-16le";
697 if (str.length % 2 === 1) {
698 str = str.slice(0, -1);
699 }
700 } else if (str[0] === "\xEF" && str[1] === "\xBB" && str[2] === "\xBF") {
701 encoding = "utf-8";
702 }
703 if (encoding) {
704 try {
705 const decoder = new TextDecoder(encoding, {
706 fatal: true
707 });
708 const buffer = stringToBytes(str);
709 const decoded = decoder.decode(buffer);
710 if (!decoded.includes("\x1b")) {
711 return decoded;
712 }
713 return decoded.replaceAll(/\x1b[^\x1b]*(?:\x1b|$)/g, "");
714 } catch (ex) {
715 warn(`stringToPDFString: "${ex}".`);
716 }
717 }
718 }
719 const strBuf = [];
720 for (let i = 0, ii = str.length; i < ii; i++) {
721 const charCode = str.charCodeAt(i);
722 if (charCode === 0x1b) {
723 while (++i < ii && str.charCodeAt(i) !== 0x1b) {}
724 continue;
725 }
726 const code = PDFStringTranslateTable[charCode];
727 strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
728 }
729 return strBuf.join("");
730}
731function stringToUTF8String(str) {
732 return decodeURIComponent(escape(str));
733}
734function utf8StringToString(str) {
735 return unescape(encodeURIComponent(str));
736}
737function isArrayEqual(arr1, arr2) {
738 if (arr1.length !== arr2.length) {
739 return false;
740 }
741 for (let i = 0, ii = arr1.length; i < ii; i++) {
742 if (arr1[i] !== arr2[i]) {
743 return false;
744 }
745 }
746 return true;
747}
748function getModificationDate(date = new Date()) {
749 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")];
750 return buffer.join("");
751}
752let NormalizeRegex = null;
753let NormalizationMap = null;
754function normalizeUnicode(str) {
755 if (!NormalizeRegex) {
756 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;
757 NormalizationMap = new Map([["ſt", "ſt"]]);
758 }
759 return str.replaceAll(NormalizeRegex, (_, p1, p2) => p1 ? p1.normalize("NFKC") : NormalizationMap.get(p2));
760}
761function getUuid() {
762 if (typeof crypto !== "undefined" && typeof crypto?.randomUUID === "function") {
763 return crypto.randomUUID();
764 }
765 const buf = new Uint8Array(32);
766 if (typeof crypto !== "undefined" && typeof crypto?.getRandomValues === "function") {
767 crypto.getRandomValues(buf);
768 } else {
769 for (let i = 0; i < 32; i++) {
770 buf[i] = Math.floor(Math.random() * 255);
771 }
772 }
773 return bytesToString(buf);
774}
775const AnnotationPrefix = "pdfjs_internal_id_";
776
777;// CONCATENATED MODULE: ./src/core/primitives.js
778
779const CIRCULAR_REF = Symbol("CIRCULAR_REF");
780const EOF = Symbol("EOF");
781let CmdCache = Object.create(null);
782let NameCache = Object.create(null);
783let RefCache = Object.create(null);
784function clearPrimitiveCaches() {
785 CmdCache = Object.create(null);
786 NameCache = Object.create(null);
787 RefCache = Object.create(null);
788}
789class Name {
790 constructor(name) {
791 this.name = name;
792 }
793 static get(name) {
794 return NameCache[name] ||= new Name(name);
795 }
796}
797class Cmd {
798 constructor(cmd) {
799 this.cmd = cmd;
800 }
801 static get(cmd) {
802 return CmdCache[cmd] ||= new Cmd(cmd);
803 }
804}
805const nonSerializable = function nonSerializableClosure() {
806 return nonSerializable;
807};
808class Dict {
809 constructor(xref = null) {
810 this._map = Object.create(null);
811 this.xref = xref;
812 this.objId = null;
813 this.suppressEncryption = false;
814 this.__nonSerializable__ = nonSerializable;
815 }
816 assignXref(newXref) {
817 this.xref = newXref;
818 }
819 get size() {
820 return Object.keys(this._map).length;
821 }
822 get(key1, key2, key3) {
823 let value = this._map[key1];
824 if (value === undefined && key2 !== undefined) {
825 value = this._map[key2];
826 if (value === undefined && key3 !== undefined) {
827 value = this._map[key3];
828 }
829 }
830 if (value instanceof Ref && this.xref) {
831 return this.xref.fetch(value, this.suppressEncryption);
832 }
833 return value;
834 }
835 async getAsync(key1, key2, key3) {
836 let value = this._map[key1];
837 if (value === undefined && key2 !== undefined) {
838 value = this._map[key2];
839 if (value === undefined && key3 !== undefined) {
840 value = this._map[key3];
841 }
842 }
843 if (value instanceof Ref && this.xref) {
844 return this.xref.fetchAsync(value, this.suppressEncryption);
845 }
846 return value;
847 }
848 getArray(key1, key2, key3) {
849 let value = this._map[key1];
850 if (value === undefined && key2 !== undefined) {
851 value = this._map[key2];
852 if (value === undefined && key3 !== undefined) {
853 value = this._map[key3];
854 }
855 }
856 if (value instanceof Ref && this.xref) {
857 value = this.xref.fetch(value, this.suppressEncryption);
858 }
859 if (Array.isArray(value)) {
860 value = value.slice();
861 for (let i = 0, ii = value.length; i < ii; i++) {
862 if (value[i] instanceof Ref && this.xref) {
863 value[i] = this.xref.fetch(value[i], this.suppressEncryption);
864 }
865 }
866 }
867 return value;
868 }
869 getRaw(key) {
870 return this._map[key];
871 }
872 getKeys() {
873 return Object.keys(this._map);
874 }
875 getRawValues() {
876 return Object.values(this._map);
877 }
878 set(key, value) {
879 this._map[key] = value;
880 }
881 has(key) {
882 return this._map[key] !== undefined;
883 }
884 forEach(callback) {
885 for (const key in this._map) {
886 callback(key, this.get(key));
887 }
888 }
889 static get empty() {
890 const emptyDict = new Dict(null);
891 emptyDict.set = (key, value) => {
892 unreachable("Should not call `set` on the empty dictionary.");
893 };
894 return shadow(this, "empty", emptyDict);
895 }
896 static merge({
897 xref,
898 dictArray,
899 mergeSubDicts = false
900 }) {
901 const mergedDict = new Dict(xref),
902 properties = new Map();
903 for (const dict of dictArray) {
904 if (!(dict instanceof Dict)) {
905 continue;
906 }
907 for (const [key, value] of Object.entries(dict._map)) {
908 let property = properties.get(key);
909 if (property === undefined) {
910 property = [];
911 properties.set(key, property);
912 } else if (!mergeSubDicts || !(value instanceof Dict)) {
913 continue;
914 }
915 property.push(value);
916 }
917 }
918 for (const [name, values] of properties) {
919 if (values.length === 1 || !(values[0] instanceof Dict)) {
920 mergedDict._map[name] = values[0];
921 continue;
922 }
923 const subDict = new Dict(xref);
924 for (const dict of values) {
925 for (const [key, value] of Object.entries(dict._map)) {
926 if (subDict._map[key] === undefined) {
927 subDict._map[key] = value;
928 }
929 }
930 }
931 if (subDict.size > 0) {
932 mergedDict._map[name] = subDict;
933 }
934 }
935 properties.clear();
936 return mergedDict.size > 0 ? mergedDict : Dict.empty;
937 }
938 clone() {
939 const dict = new Dict(this.xref);
940 for (const key of this.getKeys()) {
941 dict.set(key, this.getRaw(key));
942 }
943 return dict;
944 }
945}
946class Ref {
947 constructor(num, gen) {
948 this.num = num;
949 this.gen = gen;
950 }
951 toString() {
952 if (this.gen === 0) {
953 return `${this.num}R`;
954 }
955 return `${this.num}R${this.gen}`;
956 }
957 static fromString(str) {
958 const ref = RefCache[str];
959 if (ref) {
960 return ref;
961 }
962 const m = /^(\d+)R(\d*)$/.exec(str);
963 if (!m || m[1] === "0") {
964 return null;
965 }
966 return RefCache[str] = new Ref(parseInt(m[1]), !m[2] ? 0 : parseInt(m[2]));
967 }
968 static get(num, gen) {
969 const key = gen === 0 ? `${num}R` : `${num}R${gen}`;
970 return RefCache[key] ||= new Ref(num, gen);
971 }
972}
973class RefSet {
974 constructor(parent = null) {
975 this._set = new Set(parent?._set);
976 }
977 has(ref) {
978 return this._set.has(ref.toString());
979 }
980 put(ref) {
981 this._set.add(ref.toString());
982 }
983 remove(ref) {
984 this._set.delete(ref.toString());
985 }
986 [Symbol.iterator]() {
987 return this._set.values();
988 }
989 clear() {
990 this._set.clear();
991 }
992}
993class RefSetCache {
994 constructor() {
995 this._map = new Map();
996 }
997 get size() {
998 return this._map.size;
999 }
1000 get(ref) {
1001 return this._map.get(ref.toString());
1002 }
1003 has(ref) {
1004 return this._map.has(ref.toString());
1005 }
1006 put(ref, obj) {
1007 this._map.set(ref.toString(), obj);
1008 }
1009 putAlias(ref, aliasRef) {
1010 this._map.set(ref.toString(), this.get(aliasRef));
1011 }
1012 [Symbol.iterator]() {
1013 return this._map.values();
1014 }
1015 clear() {
1016 this._map.clear();
1017 }
1018}
1019function isName(v, name) {
1020 return v instanceof Name && (name === undefined || v.name === name);
1021}
1022function isCmd(v, cmd) {
1023 return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
1024}
1025function isDict(v, type) {
1026 return v instanceof Dict && (type === undefined || isName(v.get("Type"), type));
1027}
1028function isRefsEqual(v1, v2) {
1029 return v1.num === v2.num && v1.gen === v2.gen;
1030}
1031
1032;// CONCATENATED MODULE: ./src/core/base_stream.js
1033
1034class BaseStream {
1035 constructor() {
1036 if (this.constructor === BaseStream) {
1037 unreachable("Cannot initialize BaseStream.");
1038 }
1039 }
1040 get length() {
1041 unreachable("Abstract getter `length` accessed");
1042 }
1043 get isEmpty() {
1044 unreachable("Abstract getter `isEmpty` accessed");
1045 }
1046 get isDataLoaded() {
1047 return shadow(this, "isDataLoaded", true);
1048 }
1049 getByte() {
1050 unreachable("Abstract method `getByte` called");
1051 }
1052 getBytes(length) {
1053 unreachable("Abstract method `getBytes` called");
1054 }
1055 peekByte() {
1056 const peekedByte = this.getByte();
1057 if (peekedByte !== -1) {
1058 this.pos--;
1059 }
1060 return peekedByte;
1061 }
1062 peekBytes(length) {
1063 const bytes = this.getBytes(length);
1064 this.pos -= bytes.length;
1065 return bytes;
1066 }
1067 getUint16() {
1068 const b0 = this.getByte();
1069 const b1 = this.getByte();
1070 if (b0 === -1 || b1 === -1) {
1071 return -1;
1072 }
1073 return (b0 << 8) + b1;
1074 }
1075 getInt32() {
1076 const b0 = this.getByte();
1077 const b1 = this.getByte();
1078 const b2 = this.getByte();
1079 const b3 = this.getByte();
1080 return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
1081 }
1082 getByteRange(begin, end) {
1083 unreachable("Abstract method `getByteRange` called");
1084 }
1085 getString(length) {
1086 return bytesToString(this.getBytes(length));
1087 }
1088 skip(n) {
1089 this.pos += n || 1;
1090 }
1091 reset() {
1092 unreachable("Abstract method `reset` called");
1093 }
1094 moveStart() {
1095 unreachable("Abstract method `moveStart` called");
1096 }
1097 makeSubStream(start, length, dict = null) {
1098 unreachable("Abstract method `makeSubStream` called");
1099 }
1100 getBaseStreams() {
1101 return null;
1102 }
1103}
1104
1105;// CONCATENATED MODULE: ./src/core/core_utils.js
1106
1107
1108
1109const PDF_VERSION_REGEXP = /^[1-9]\.\d$/;
1110function getLookupTableFactory(initializer) {
1111 let lookup;
1112 return function () {
1113 if (initializer) {
1114 lookup = Object.create(null);
1115 initializer(lookup);
1116 initializer = null;
1117 }
1118 return lookup;
1119 };
1120}
1121class MissingDataException extends BaseException {
1122 constructor(begin, end) {
1123 super(`Missing data [${begin}, ${end})`, "MissingDataException");
1124 this.begin = begin;
1125 this.end = end;
1126 }
1127}
1128class ParserEOFException extends BaseException {
1129 constructor(msg) {
1130 super(msg, "ParserEOFException");
1131 }
1132}
1133class XRefEntryException extends BaseException {
1134 constructor(msg) {
1135 super(msg, "XRefEntryException");
1136 }
1137}
1138class XRefParseException extends BaseException {
1139 constructor(msg) {
1140 super(msg, "XRefParseException");
1141 }
1142}
1143function arrayBuffersToBytes(arr) {
1144 const length = arr.length;
1145 if (length === 0) {
1146 return new Uint8Array(0);
1147 }
1148 if (length === 1) {
1149 return new Uint8Array(arr[0]);
1150 }
1151 let dataLength = 0;
1152 for (let i = 0; i < length; i++) {
1153 dataLength += arr[i].byteLength;
1154 }
1155 const data = new Uint8Array(dataLength);
1156 let pos = 0;
1157 for (let i = 0; i < length; i++) {
1158 const item = new Uint8Array(arr[i]);
1159 data.set(item, pos);
1160 pos += item.byteLength;
1161 }
1162 return data;
1163}
1164function getInheritableProperty({
1165 dict,
1166 key,
1167 getArray = false,
1168 stopWhenFound = true
1169}) {
1170 let values;
1171 const visited = new RefSet();
1172 while (dict instanceof Dict && !(dict.objId && visited.has(dict.objId))) {
1173 if (dict.objId) {
1174 visited.put(dict.objId);
1175 }
1176 const value = getArray ? dict.getArray(key) : dict.get(key);
1177 if (value !== undefined) {
1178 if (stopWhenFound) {
1179 return value;
1180 }
1181 (values ||= []).push(value);
1182 }
1183 dict = dict.get("Parent");
1184 }
1185 return values;
1186}
1187const 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"];
1188function toRomanNumerals(number, lowerCase = false) {
1189 assert(Number.isInteger(number) && number > 0, "The number should be a positive integer.");
1190 const romanBuf = [];
1191 let pos;
1192 while (number >= 1000) {
1193 number -= 1000;
1194 romanBuf.push("M");
1195 }
1196 pos = number / 100 | 0;
1197 number %= 100;
1198 romanBuf.push(ROMAN_NUMBER_MAP[pos]);
1199 pos = number / 10 | 0;
1200 number %= 10;
1201 romanBuf.push(ROMAN_NUMBER_MAP[10 + pos]);
1202 romanBuf.push(ROMAN_NUMBER_MAP[20 + number]);
1203 const romanStr = romanBuf.join("");
1204 return lowerCase ? romanStr.toLowerCase() : romanStr;
1205}
1206function log2(x) {
1207 if (x <= 0) {
1208 return 0;
1209 }
1210 return Math.ceil(Math.log2(x));
1211}
1212function readInt8(data, offset) {
1213 return data[offset] << 24 >> 24;
1214}
1215function readUint16(data, offset) {
1216 return data[offset] << 8 | data[offset + 1];
1217}
1218function readUint32(data, offset) {
1219 return (data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3]) >>> 0;
1220}
1221function isWhiteSpace(ch) {
1222 return ch === 0x20 || ch === 0x09 || ch === 0x0d || ch === 0x0a;
1223}
1224function parseXFAPath(path) {
1225 const positionPattern = /(.+)\[(\d+)\]$/;
1226 return path.split(".").map(component => {
1227 const m = component.match(positionPattern);
1228 if (m) {
1229 return {
1230 name: m[1],
1231 pos: parseInt(m[2], 10)
1232 };
1233 }
1234 return {
1235 name: component,
1236 pos: 0
1237 };
1238 });
1239}
1240function escapePDFName(str) {
1241 const buffer = [];
1242 let start = 0;
1243 for (let i = 0, ii = str.length; i < ii; i++) {
1244 const char = str.charCodeAt(i);
1245 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) {
1246 if (start < i) {
1247 buffer.push(str.substring(start, i));
1248 }
1249 buffer.push(`#${char.toString(16)}`);
1250 start = i + 1;
1251 }
1252 }
1253 if (buffer.length === 0) {
1254 return str;
1255 }
1256 if (start < str.length) {
1257 buffer.push(str.substring(start, str.length));
1258 }
1259 return buffer.join("");
1260}
1261function escapeString(str) {
1262 return str.replaceAll(/([()\\\n\r])/g, match => {
1263 if (match === "\n") {
1264 return "\\n";
1265 } else if (match === "\r") {
1266 return "\\r";
1267 }
1268 return `\\${match}`;
1269 });
1270}
1271function _collectJS(entry, xref, list, parents) {
1272 if (!entry) {
1273 return;
1274 }
1275 let parent = null;
1276 if (entry instanceof Ref) {
1277 if (parents.has(entry)) {
1278 return;
1279 }
1280 parent = entry;
1281 parents.put(parent);
1282 entry = xref.fetch(entry);
1283 }
1284 if (Array.isArray(entry)) {
1285 for (const element of entry) {
1286 _collectJS(element, xref, list, parents);
1287 }
1288 } else if (entry instanceof Dict) {
1289 if (isName(entry.get("S"), "JavaScript")) {
1290 const js = entry.get("JS");
1291 let code;
1292 if (js instanceof BaseStream) {
1293 code = js.getString();
1294 } else if (typeof js === "string") {
1295 code = js;
1296 }
1297 code &&= stringToPDFString(code).replaceAll("\x00", "");
1298 if (code) {
1299 list.push(code);
1300 }
1301 }
1302 _collectJS(entry.getRaw("Next"), xref, list, parents);
1303 }
1304 if (parent) {
1305 parents.remove(parent);
1306 }
1307}
1308function collectActions(xref, dict, eventType) {
1309 const actions = Object.create(null);
1310 const additionalActionsDicts = getInheritableProperty({
1311 dict,
1312 key: "AA",
1313 stopWhenFound: false
1314 });
1315 if (additionalActionsDicts) {
1316 for (let i = additionalActionsDicts.length - 1; i >= 0; i--) {
1317 const additionalActions = additionalActionsDicts[i];
1318 if (!(additionalActions instanceof Dict)) {
1319 continue;
1320 }
1321 for (const key of additionalActions.getKeys()) {
1322 const action = eventType[key];
1323 if (!action) {
1324 continue;
1325 }
1326 const actionDict = additionalActions.getRaw(key);
1327 const parents = new RefSet();
1328 const list = [];
1329 _collectJS(actionDict, xref, list, parents);
1330 if (list.length > 0) {
1331 actions[action] = list;
1332 }
1333 }
1334 }
1335 }
1336 if (dict.has("A")) {
1337 const actionDict = dict.get("A");
1338 const parents = new RefSet();
1339 const list = [];
1340 _collectJS(actionDict, xref, list, parents);
1341 if (list.length > 0) {
1342 actions.Action = list;
1343 }
1344 }
1345 return objectSize(actions) > 0 ? actions : null;
1346}
1347const XMLEntities = {
1348 0x3c: "&lt;",
1349 0x3e: "&gt;",
1350 0x26: "&amp;",
1351 0x22: "&quot;",
1352 0x27: "&apos;"
1353};
1354function* codePointIter(str) {
1355 for (let i = 0, ii = str.length; i < ii; i++) {
1356 const char = str.codePointAt(i);
1357 if (char > 0xd7ff && (char < 0xe000 || char > 0xfffd)) {
1358 i++;
1359 }
1360 yield char;
1361 }
1362}
1363function encodeToXmlString(str) {
1364 const buffer = [];
1365 let start = 0;
1366 for (let i = 0, ii = str.length; i < ii; i++) {
1367 const char = str.codePointAt(i);
1368 if (0x20 <= char && char <= 0x7e) {
1369 const entity = XMLEntities[char];
1370 if (entity) {
1371 if (start < i) {
1372 buffer.push(str.substring(start, i));
1373 }
1374 buffer.push(entity);
1375 start = i + 1;
1376 }
1377 } else {
1378 if (start < i) {
1379 buffer.push(str.substring(start, i));
1380 }
1381 buffer.push(`&#x${char.toString(16).toUpperCase()};`);
1382 if (char > 0xd7ff && (char < 0xe000 || char > 0xfffd)) {
1383 i++;
1384 }
1385 start = i + 1;
1386 }
1387 }
1388 if (buffer.length === 0) {
1389 return str;
1390 }
1391 if (start < str.length) {
1392 buffer.push(str.substring(start, str.length));
1393 }
1394 return buffer.join("");
1395}
1396function validateFontName(fontFamily, mustWarn = false) {
1397 const m = /^("|').*("|')$/.exec(fontFamily);
1398 if (m && m[1] === m[2]) {
1399 const re = new RegExp(`[^\\\\]${m[1]}`);
1400 if (re.test(fontFamily.slice(1, -1))) {
1401 if (mustWarn) {
1402 warn(`FontFamily contains unescaped ${m[1]}: ${fontFamily}.`);
1403 }
1404 return false;
1405 }
1406 } else {
1407 for (const ident of fontFamily.split(/[ \t]+/)) {
1408 if (/^(\d|(-(\d|-)))/.test(ident) || !/^[\w-\\]+$/.test(ident)) {
1409 if (mustWarn) {
1410 warn(`FontFamily contains invalid <custom-ident>: ${fontFamily}.`);
1411 }
1412 return false;
1413 }
1414 }
1415 }
1416 return true;
1417}
1418function validateCSSFont(cssFontInfo) {
1419 const DEFAULT_CSS_FONT_OBLIQUE = "14";
1420 const DEFAULT_CSS_FONT_WEIGHT = "400";
1421 const CSS_FONT_WEIGHT_VALUES = new Set(["100", "200", "300", "400", "500", "600", "700", "800", "900", "1000", "normal", "bold", "bolder", "lighter"]);
1422 const {
1423 fontFamily,
1424 fontWeight,
1425 italicAngle
1426 } = cssFontInfo;
1427 if (!validateFontName(fontFamily, true)) {
1428 return false;
1429 }
1430 const weight = fontWeight ? fontWeight.toString() : "";
1431 cssFontInfo.fontWeight = CSS_FONT_WEIGHT_VALUES.has(weight) ? weight : DEFAULT_CSS_FONT_WEIGHT;
1432 const angle = parseFloat(italicAngle);
1433 cssFontInfo.italicAngle = isNaN(angle) || angle < -90 || angle > 90 ? DEFAULT_CSS_FONT_OBLIQUE : italicAngle.toString();
1434 return true;
1435}
1436function recoverJsURL(str) {
1437 const URL_OPEN_METHODS = ["app.launchURL", "window.open", "xfa.host.gotoURL"];
1438 const regex = new RegExp("^\\s*(" + URL_OPEN_METHODS.join("|").replaceAll(".", "\\.") + ")\\((?:'|\")([^'\"]*)(?:'|\")(?:,\\s*(\\w+)\\)|\\))", "i");
1439 const jsUrl = regex.exec(str);
1440 if (jsUrl?.[2]) {
1441 const url = jsUrl[2];
1442 let newWindow = false;
1443 if (jsUrl[3] === "true" && jsUrl[1] === "app.launchURL") {
1444 newWindow = true;
1445 }
1446 return {
1447 url,
1448 newWindow
1449 };
1450 }
1451 return null;
1452}
1453function numberToString(value) {
1454 if (Number.isInteger(value)) {
1455 return value.toString();
1456 }
1457 const roundedValue = Math.round(value * 100);
1458 if (roundedValue % 100 === 0) {
1459 return (roundedValue / 100).toString();
1460 }
1461 if (roundedValue % 10 === 0) {
1462 return value.toFixed(1);
1463 }
1464 return value.toFixed(2);
1465}
1466function getNewAnnotationsMap(annotationStorage) {
1467 if (!annotationStorage) {
1468 return null;
1469 }
1470 const newAnnotationsByPage = new Map();
1471 for (const [key, value] of annotationStorage) {
1472 if (!key.startsWith(AnnotationEditorPrefix)) {
1473 continue;
1474 }
1475 let annotations = newAnnotationsByPage.get(value.pageIndex);
1476 if (!annotations) {
1477 annotations = [];
1478 newAnnotationsByPage.set(value.pageIndex, annotations);
1479 }
1480 annotations.push(value);
1481 }
1482 return newAnnotationsByPage.size > 0 ? newAnnotationsByPage : null;
1483}
1484function isAscii(str) {
1485 return /^[\x00-\x7F]*$/.test(str);
1486}
1487function stringToUTF16HexString(str) {
1488 const buf = [];
1489 for (let i = 0, ii = str.length; i < ii; i++) {
1490 const char = str.charCodeAt(i);
1491 buf.push((char >> 8 & 0xff).toString(16).padStart(2, "0"), (char & 0xff).toString(16).padStart(2, "0"));
1492 }
1493 return buf.join("");
1494}
1495function stringToUTF16String(str, bigEndian = false) {
1496 const buf = [];
1497 if (bigEndian) {
1498 buf.push("\xFE\xFF");
1499 }
1500 for (let i = 0, ii = str.length; i < ii; i++) {
1501 const char = str.charCodeAt(i);
1502 buf.push(String.fromCharCode(char >> 8 & 0xff), String.fromCharCode(char & 0xff));
1503 }
1504 return buf.join("");
1505}
1506function getRotationMatrix(rotation, width, height) {
1507 switch (rotation) {
1508 case 90:
1509 return [0, 1, -1, 0, width, 0];
1510 case 180:
1511 return [-1, 0, 0, -1, width, height];
1512 case 270:
1513 return [0, -1, 1, 0, 0, height];
1514 default:
1515 throw new Error("Invalid rotation");
1516 }
1517}
1518function getSizeInBytes(x) {
1519 return Math.ceil(Math.ceil(Math.log2(1 + x)) / 8);
1520}
1521
1522;// CONCATENATED MODULE: ./src/core/stream.js
1523
1524
1525class Stream extends BaseStream {
1526 constructor(arrayBuffer, start, length, dict) {
1527 super();
1528 this.bytes = arrayBuffer instanceof Uint8Array ? arrayBuffer : new Uint8Array(arrayBuffer);
1529 this.start = start || 0;
1530 this.pos = this.start;
1531 this.end = start + length || this.bytes.length;
1532 this.dict = dict;
1533 }
1534 get length() {
1535 return this.end - this.start;
1536 }
1537 get isEmpty() {
1538 return this.length === 0;
1539 }
1540 getByte() {
1541 if (this.pos >= this.end) {
1542 return -1;
1543 }
1544 return this.bytes[this.pos++];
1545 }
1546 getBytes(length) {
1547 const bytes = this.bytes;
1548 const pos = this.pos;
1549 const strEnd = this.end;
1550 if (!length) {
1551 return bytes.subarray(pos, strEnd);
1552 }
1553 let end = pos + length;
1554 if (end > strEnd) {
1555 end = strEnd;
1556 }
1557 this.pos = end;
1558 return bytes.subarray(pos, end);
1559 }
1560 getByteRange(begin, end) {
1561 if (begin < 0) {
1562 begin = 0;
1563 }
1564 if (end > this.end) {
1565 end = this.end;
1566 }
1567 return this.bytes.subarray(begin, end);
1568 }
1569 reset() {
1570 this.pos = this.start;
1571 }
1572 moveStart() {
1573 this.start = this.pos;
1574 }
1575 makeSubStream(start, length, dict = null) {
1576 return new Stream(this.bytes.buffer, start, length, dict);
1577 }
1578}
1579class StringStream extends Stream {
1580 constructor(str) {
1581 super(stringToBytes(str));
1582 }
1583}
1584class NullStream extends Stream {
1585 constructor() {
1586 super(new Uint8Array(0));
1587 }
1588}
1589
1590;// CONCATENATED MODULE: ./src/core/chunked_stream.js
1591
1592
1593
1594class ChunkedStream extends Stream {
1595 constructor(length, chunkSize, manager) {
1596 super(new Uint8Array(length), 0, length, null);
1597 this.chunkSize = chunkSize;
1598 this._loadedChunks = new Set();
1599 this.numChunks = Math.ceil(length / chunkSize);
1600 this.manager = manager;
1601 this.progressiveDataLength = 0;
1602 this.lastSuccessfulEnsureByteChunk = -1;
1603 }
1604 getMissingChunks() {
1605 const chunks = [];
1606 for (let chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
1607 if (!this._loadedChunks.has(chunk)) {
1608 chunks.push(chunk);
1609 }
1610 }
1611 return chunks;
1612 }
1613 get numChunksLoaded() {
1614 return this._loadedChunks.size;
1615 }
1616 get isDataLoaded() {
1617 return this.numChunksLoaded === this.numChunks;
1618 }
1619 onReceiveData(begin, chunk) {
1620 const chunkSize = this.chunkSize;
1621 if (begin % chunkSize !== 0) {
1622 throw new Error(`Bad begin offset: ${begin}`);
1623 }
1624 const end = begin + chunk.byteLength;
1625 if (end % chunkSize !== 0 && end !== this.bytes.length) {
1626 throw new Error(`Bad end offset: ${end}`);
1627 }
1628 this.bytes.set(new Uint8Array(chunk), begin);
1629 const beginChunk = Math.floor(begin / chunkSize);
1630 const endChunk = Math.floor((end - 1) / chunkSize) + 1;
1631 for (let curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
1632 this._loadedChunks.add(curChunk);
1633 }
1634 }
1635 onReceiveProgressiveData(data) {
1636 let position = this.progressiveDataLength;
1637 const beginChunk = Math.floor(position / this.chunkSize);
1638 this.bytes.set(new Uint8Array(data), position);
1639 position += data.byteLength;
1640 this.progressiveDataLength = position;
1641 const endChunk = position >= this.end ? this.numChunks : Math.floor(position / this.chunkSize);
1642 for (let curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
1643 this._loadedChunks.add(curChunk);
1644 }
1645 }
1646 ensureByte(pos) {
1647 if (pos < this.progressiveDataLength) {
1648 return;
1649 }
1650 const chunk = Math.floor(pos / this.chunkSize);
1651 if (chunk > this.numChunks) {
1652 return;
1653 }
1654 if (chunk === this.lastSuccessfulEnsureByteChunk) {
1655 return;
1656 }
1657 if (!this._loadedChunks.has(chunk)) {
1658 throw new MissingDataException(pos, pos + 1);
1659 }
1660 this.lastSuccessfulEnsureByteChunk = chunk;
1661 }
1662 ensureRange(begin, end) {
1663 if (begin >= end) {
1664 return;
1665 }
1666 if (end <= this.progressiveDataLength) {
1667 return;
1668 }
1669 const beginChunk = Math.floor(begin / this.chunkSize);
1670 if (beginChunk > this.numChunks) {
1671 return;
1672 }
1673 const endChunk = Math.min(Math.floor((end - 1) / this.chunkSize) + 1, this.numChunks);
1674 for (let chunk = beginChunk; chunk < endChunk; ++chunk) {
1675 if (!this._loadedChunks.has(chunk)) {
1676 throw new MissingDataException(begin, end);
1677 }
1678 }
1679 }
1680 nextEmptyChunk(beginChunk) {
1681 const numChunks = this.numChunks;
1682 for (let i = 0; i < numChunks; ++i) {
1683 const chunk = (beginChunk + i) % numChunks;
1684 if (!this._loadedChunks.has(chunk)) {
1685 return chunk;
1686 }
1687 }
1688 return null;
1689 }
1690 hasChunk(chunk) {
1691 return this._loadedChunks.has(chunk);
1692 }
1693 getByte() {
1694 const pos = this.pos;
1695 if (pos >= this.end) {
1696 return -1;
1697 }
1698 if (pos >= this.progressiveDataLength) {
1699 this.ensureByte(pos);
1700 }
1701 return this.bytes[this.pos++];
1702 }
1703 getBytes(length) {
1704 const bytes = this.bytes;
1705 const pos = this.pos;
1706 const strEnd = this.end;
1707 if (!length) {
1708 if (strEnd > this.progressiveDataLength) {
1709 this.ensureRange(pos, strEnd);
1710 }
1711 return bytes.subarray(pos, strEnd);
1712 }
1713 let end = pos + length;
1714 if (end > strEnd) {
1715 end = strEnd;
1716 }
1717 if (end > this.progressiveDataLength) {
1718 this.ensureRange(pos, end);
1719 }
1720 this.pos = end;
1721 return bytes.subarray(pos, end);
1722 }
1723 getByteRange(begin, end) {
1724 if (begin < 0) {
1725 begin = 0;
1726 }
1727 if (end > this.end) {
1728 end = this.end;
1729 }
1730 if (end > this.progressiveDataLength) {
1731 this.ensureRange(begin, end);
1732 }
1733 return this.bytes.subarray(begin, end);
1734 }
1735 makeSubStream(start, length, dict = null) {
1736 if (length) {
1737 if (start + length > this.progressiveDataLength) {
1738 this.ensureRange(start, start + length);
1739 }
1740 } else if (start >= this.progressiveDataLength) {
1741 this.ensureByte(start);
1742 }
1743 function ChunkedStreamSubstream() {}
1744 ChunkedStreamSubstream.prototype = Object.create(this);
1745 ChunkedStreamSubstream.prototype.getMissingChunks = function () {
1746 const chunkSize = this.chunkSize;
1747 const beginChunk = Math.floor(this.start / chunkSize);
1748 const endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
1749 const missingChunks = [];
1750 for (let chunk = beginChunk; chunk < endChunk; ++chunk) {
1751 if (!this._loadedChunks.has(chunk)) {
1752 missingChunks.push(chunk);
1753 }
1754 }
1755 return missingChunks;
1756 };
1757 Object.defineProperty(ChunkedStreamSubstream.prototype, "isDataLoaded", {
1758 get() {
1759 if (this.numChunksLoaded === this.numChunks) {
1760 return true;
1761 }
1762 return this.getMissingChunks().length === 0;
1763 },
1764 configurable: true
1765 });
1766 const subStream = new ChunkedStreamSubstream();
1767 subStream.pos = subStream.start = start;
1768 subStream.end = start + length || this.end;
1769 subStream.dict = dict;
1770 return subStream;
1771 }
1772 getBaseStreams() {
1773 return [this];
1774 }
1775}
1776class ChunkedStreamManager {
1777 constructor(pdfNetworkStream, args) {
1778 this.length = args.length;
1779 this.chunkSize = args.rangeChunkSize;
1780 this.stream = new ChunkedStream(this.length, this.chunkSize, this);
1781 this.pdfNetworkStream = pdfNetworkStream;
1782 this.disableAutoFetch = args.disableAutoFetch;
1783 this.msgHandler = args.msgHandler;
1784 this.currRequestId = 0;
1785 this._chunksNeededByRequest = new Map();
1786 this._requestsByChunk = new Map();
1787 this._promisesByRequest = new Map();
1788 this.progressiveDataLength = 0;
1789 this.aborted = false;
1790 this._loadedStreamCapability = Promise.withResolvers();
1791 }
1792 sendRequest(begin, end) {
1793 const rangeReader = this.pdfNetworkStream.getRangeReader(begin, end);
1794 if (!rangeReader.isStreamingSupported) {
1795 rangeReader.onProgress = this.onProgress.bind(this);
1796 }
1797 let chunks = [],
1798 loaded = 0;
1799 return new Promise((resolve, reject) => {
1800 const readChunk = ({
1801 value,
1802 done
1803 }) => {
1804 try {
1805 if (done) {
1806 const chunkData = arrayBuffersToBytes(chunks);
1807 chunks = null;
1808 resolve(chunkData);
1809 return;
1810 }
1811 loaded += value.byteLength;
1812 if (rangeReader.isStreamingSupported) {
1813 this.onProgress({
1814 loaded
1815 });
1816 }
1817 chunks.push(value);
1818 rangeReader.read().then(readChunk, reject);
1819 } catch (e) {
1820 reject(e);
1821 }
1822 };
1823 rangeReader.read().then(readChunk, reject);
1824 }).then(data => {
1825 if (this.aborted) {
1826 return;
1827 }
1828 this.onReceiveData({
1829 chunk: data,
1830 begin
1831 });
1832 });
1833 }
1834 requestAllChunks(noFetch = false) {
1835 if (!noFetch) {
1836 const missingChunks = this.stream.getMissingChunks();
1837 this._requestChunks(missingChunks);
1838 }
1839 return this._loadedStreamCapability.promise;
1840 }
1841 _requestChunks(chunks) {
1842 const requestId = this.currRequestId++;
1843 const chunksNeeded = new Set();
1844 this._chunksNeededByRequest.set(requestId, chunksNeeded);
1845 for (const chunk of chunks) {
1846 if (!this.stream.hasChunk(chunk)) {
1847 chunksNeeded.add(chunk);
1848 }
1849 }
1850 if (chunksNeeded.size === 0) {
1851 return Promise.resolve();
1852 }
1853 const capability = Promise.withResolvers();
1854 this._promisesByRequest.set(requestId, capability);
1855 const chunksToRequest = [];
1856 for (const chunk of chunksNeeded) {
1857 let requestIds = this._requestsByChunk.get(chunk);
1858 if (!requestIds) {
1859 requestIds = [];
1860 this._requestsByChunk.set(chunk, requestIds);
1861 chunksToRequest.push(chunk);
1862 }
1863 requestIds.push(requestId);
1864 }
1865 if (chunksToRequest.length > 0) {
1866 const groupedChunksToRequest = this.groupChunks(chunksToRequest);
1867 for (const groupedChunk of groupedChunksToRequest) {
1868 const begin = groupedChunk.beginChunk * this.chunkSize;
1869 const end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
1870 this.sendRequest(begin, end).catch(capability.reject);
1871 }
1872 }
1873 return capability.promise.catch(reason => {
1874 if (this.aborted) {
1875 return;
1876 }
1877 throw reason;
1878 });
1879 }
1880 getStream() {
1881 return this.stream;
1882 }
1883 requestRange(begin, end) {
1884 end = Math.min(end, this.length);
1885 const beginChunk = this.getBeginChunk(begin);
1886 const endChunk = this.getEndChunk(end);
1887 const chunks = [];
1888 for (let chunk = beginChunk; chunk < endChunk; ++chunk) {
1889 chunks.push(chunk);
1890 }
1891 return this._requestChunks(chunks);
1892 }
1893 requestRanges(ranges = []) {
1894 const chunksToRequest = [];
1895 for (const range of ranges) {
1896 const beginChunk = this.getBeginChunk(range.begin);
1897 const endChunk = this.getEndChunk(range.end);
1898 for (let chunk = beginChunk; chunk < endChunk; ++chunk) {
1899 if (!chunksToRequest.includes(chunk)) {
1900 chunksToRequest.push(chunk);
1901 }
1902 }
1903 }
1904 chunksToRequest.sort(function (a, b) {
1905 return a - b;
1906 });
1907 return this._requestChunks(chunksToRequest);
1908 }
1909 groupChunks(chunks) {
1910 const groupedChunks = [];
1911 let beginChunk = -1;
1912 let prevChunk = -1;
1913 for (let i = 0, ii = chunks.length; i < ii; ++i) {
1914 const chunk = chunks[i];
1915 if (beginChunk < 0) {
1916 beginChunk = chunk;
1917 }
1918 if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
1919 groupedChunks.push({
1920 beginChunk,
1921 endChunk: prevChunk + 1
1922 });
1923 beginChunk = chunk;
1924 }
1925 if (i + 1 === chunks.length) {
1926 groupedChunks.push({
1927 beginChunk,
1928 endChunk: chunk + 1
1929 });
1930 }
1931 prevChunk = chunk;
1932 }
1933 return groupedChunks;
1934 }
1935 onProgress(args) {
1936 this.msgHandler.send("DocProgress", {
1937 loaded: this.stream.numChunksLoaded * this.chunkSize + args.loaded,
1938 total: this.length
1939 });
1940 }
1941 onReceiveData(args) {
1942 const chunk = args.chunk;
1943 const isProgressive = args.begin === undefined;
1944 const begin = isProgressive ? this.progressiveDataLength : args.begin;
1945 const end = begin + chunk.byteLength;
1946 const beginChunk = Math.floor(begin / this.chunkSize);
1947 const endChunk = end < this.length ? Math.floor(end / this.chunkSize) : Math.ceil(end / this.chunkSize);
1948 if (isProgressive) {
1949 this.stream.onReceiveProgressiveData(chunk);
1950 this.progressiveDataLength = end;
1951 } else {
1952 this.stream.onReceiveData(begin, chunk);
1953 }
1954 if (this.stream.isDataLoaded) {
1955 this._loadedStreamCapability.resolve(this.stream);
1956 }
1957 const loadedRequests = [];
1958 for (let curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
1959 const requestIds = this._requestsByChunk.get(curChunk);
1960 if (!requestIds) {
1961 continue;
1962 }
1963 this._requestsByChunk.delete(curChunk);
1964 for (const requestId of requestIds) {
1965 const chunksNeeded = this._chunksNeededByRequest.get(requestId);
1966 if (chunksNeeded.has(curChunk)) {
1967 chunksNeeded.delete(curChunk);
1968 }
1969 if (chunksNeeded.size > 0) {
1970 continue;
1971 }
1972 loadedRequests.push(requestId);
1973 }
1974 }
1975 if (!this.disableAutoFetch && this._requestsByChunk.size === 0) {
1976 let nextEmptyChunk;
1977 if (this.stream.numChunksLoaded === 1) {
1978 const lastChunk = this.stream.numChunks - 1;
1979 if (!this.stream.hasChunk(lastChunk)) {
1980 nextEmptyChunk = lastChunk;
1981 }
1982 } else {
1983 nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
1984 }
1985 if (Number.isInteger(nextEmptyChunk)) {
1986 this._requestChunks([nextEmptyChunk]);
1987 }
1988 }
1989 for (const requestId of loadedRequests) {
1990 const capability = this._promisesByRequest.get(requestId);
1991 this._promisesByRequest.delete(requestId);
1992 capability.resolve();
1993 }
1994 this.msgHandler.send("DocProgress", {
1995 loaded: this.stream.numChunksLoaded * this.chunkSize,
1996 total: this.length
1997 });
1998 }
1999 onError(err) {
2000 this._loadedStreamCapability.reject(err);
2001 }
2002 getBeginChunk(begin) {
2003 return Math.floor(begin / this.chunkSize);
2004 }
2005 getEndChunk(end) {
2006 return Math.floor((end - 1) / this.chunkSize) + 1;
2007 }
2008 abort(reason) {
2009 this.aborted = true;
2010 this.pdfNetworkStream?.cancelAllRequests(reason);
2011 for (const capability of this._promisesByRequest.values()) {
2012 capability.reject(reason);
2013 }
2014 }
2015}
2016
2017;// CONCATENATED MODULE: ./src/core/colorspace.js
2018
2019
2020
2021
2022function resizeRgbImage(src, dest, w1, h1, w2, h2, alpha01) {
2023 const COMPONENTS = 3;
2024 alpha01 = alpha01 !== 1 ? 0 : alpha01;
2025 const xRatio = w1 / w2;
2026 const yRatio = h1 / h2;
2027 let newIndex = 0,
2028 oldIndex;
2029 const xScaled = new Uint16Array(w2);
2030 const w1Scanline = w1 * COMPONENTS;
2031 for (let i = 0; i < w2; i++) {
2032 xScaled[i] = Math.floor(i * xRatio) * COMPONENTS;
2033 }
2034 for (let i = 0; i < h2; i++) {
2035 const py = Math.floor(i * yRatio) * w1Scanline;
2036 for (let j = 0; j < w2; j++) {
2037 oldIndex = py + xScaled[j];
2038 dest[newIndex++] = src[oldIndex++];
2039 dest[newIndex++] = src[oldIndex++];
2040 dest[newIndex++] = src[oldIndex++];
2041 newIndex += alpha01;
2042 }
2043 }
2044}
2045class ColorSpace {
2046 constructor(name, numComps) {
2047 if (this.constructor === ColorSpace) {
2048 unreachable("Cannot initialize ColorSpace.");
2049 }
2050 this.name = name;
2051 this.numComps = numComps;
2052 }
2053 getRgb(src, srcOffset) {
2054 const rgb = new Uint8ClampedArray(3);
2055 this.getRgbItem(src, srcOffset, rgb, 0);
2056 return rgb;
2057 }
2058 getRgbItem(src, srcOffset, dest, destOffset) {
2059 unreachable("Should not call ColorSpace.getRgbItem");
2060 }
2061 getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
2062 unreachable("Should not call ColorSpace.getRgbBuffer");
2063 }
2064 getOutputLength(inputLength, alpha01) {
2065 unreachable("Should not call ColorSpace.getOutputLength");
2066 }
2067 isPassthrough(bits) {
2068 return false;
2069 }
2070 isDefaultDecode(decodeMap, bpc) {
2071 return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
2072 }
2073 fillRgb(dest, originalWidth, originalHeight, width, height, actualHeight, bpc, comps, alpha01) {
2074 const count = originalWidth * originalHeight;
2075 let rgbBuf = null;
2076 const numComponentColors = 1 << bpc;
2077 const needsResizing = originalHeight !== height || originalWidth !== width;
2078 if (this.isPassthrough(bpc)) {
2079 rgbBuf = comps;
2080 } else if (this.numComps === 1 && count > numComponentColors && this.name !== "DeviceGray" && this.name !== "DeviceRGB") {
2081 const allColors = bpc <= 8 ? new Uint8Array(numComponentColors) : new Uint16Array(numComponentColors);
2082 for (let i = 0; i < numComponentColors; i++) {
2083 allColors[i] = i;
2084 }
2085 const colorMap = new Uint8ClampedArray(numComponentColors * 3);
2086 this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc, 0);
2087 if (!needsResizing) {
2088 let destPos = 0;
2089 for (let i = 0; i < count; ++i) {
2090 const key = comps[i] * 3;
2091 dest[destPos++] = colorMap[key];
2092 dest[destPos++] = colorMap[key + 1];
2093 dest[destPos++] = colorMap[key + 2];
2094 destPos += alpha01;
2095 }
2096 } else {
2097 rgbBuf = new Uint8Array(count * 3);
2098 let rgbPos = 0;
2099 for (let i = 0; i < count; ++i) {
2100 const key = comps[i] * 3;
2101 rgbBuf[rgbPos++] = colorMap[key];
2102 rgbBuf[rgbPos++] = colorMap[key + 1];
2103 rgbBuf[rgbPos++] = colorMap[key + 2];
2104 }
2105 }
2106 } else if (!needsResizing) {
2107 this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc, alpha01);
2108 } else {
2109 rgbBuf = new Uint8ClampedArray(count * 3);
2110 this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc, 0);
2111 }
2112 if (rgbBuf) {
2113 if (needsResizing) {
2114 resizeRgbImage(rgbBuf, dest, originalWidth, originalHeight, width, height, alpha01);
2115 } else {
2116 let destPos = 0,
2117 rgbPos = 0;
2118 for (let i = 0, ii = width * actualHeight; i < ii; i++) {
2119 dest[destPos++] = rgbBuf[rgbPos++];
2120 dest[destPos++] = rgbBuf[rgbPos++];
2121 dest[destPos++] = rgbBuf[rgbPos++];
2122 destPos += alpha01;
2123 }
2124 }
2125 }
2126 }
2127 get usesZeroToOneRange() {
2128 return shadow(this, "usesZeroToOneRange", true);
2129 }
2130 static _cache(cacheKey, xref, localColorSpaceCache, parsedColorSpace) {
2131 if (!localColorSpaceCache) {
2132 throw new Error('ColorSpace._cache - expected "localColorSpaceCache" argument.');
2133 }
2134 if (!parsedColorSpace) {
2135 throw new Error('ColorSpace._cache - expected "parsedColorSpace" argument.');
2136 }
2137 let csName, csRef;
2138 if (cacheKey instanceof Ref) {
2139 csRef = cacheKey;
2140 cacheKey = xref.fetch(cacheKey);
2141 }
2142 if (cacheKey instanceof Name) {
2143 csName = cacheKey.name;
2144 }
2145 if (csName || csRef) {
2146 localColorSpaceCache.set(csName, csRef, parsedColorSpace);
2147 }
2148 }
2149 static getCached(cacheKey, xref, localColorSpaceCache) {
2150 if (!localColorSpaceCache) {
2151 throw new Error('ColorSpace.getCached - expected "localColorSpaceCache" argument.');
2152 }
2153 if (cacheKey instanceof Ref) {
2154 const localColorSpace = localColorSpaceCache.getByRef(cacheKey);
2155 if (localColorSpace) {
2156 return localColorSpace;
2157 }
2158 try {
2159 cacheKey = xref.fetch(cacheKey);
2160 } catch (ex) {
2161 if (ex instanceof MissingDataException) {
2162 throw ex;
2163 }
2164 }
2165 }
2166 if (cacheKey instanceof Name) {
2167 const localColorSpace = localColorSpaceCache.getByName(cacheKey.name);
2168 if (localColorSpace) {
2169 return localColorSpace;
2170 }
2171 }
2172 return null;
2173 }
2174 static async parseAsync({
2175 cs,
2176 xref,
2177 resources = null,
2178 pdfFunctionFactory,
2179 localColorSpaceCache
2180 }) {
2181 const parsedColorSpace = this._parse(cs, xref, resources, pdfFunctionFactory);
2182 this._cache(cs, xref, localColorSpaceCache, parsedColorSpace);
2183 return parsedColorSpace;
2184 }
2185 static parse({
2186 cs,
2187 xref,
2188 resources = null,
2189 pdfFunctionFactory,
2190 localColorSpaceCache
2191 }) {
2192 const cachedColorSpace = this.getCached(cs, xref, localColorSpaceCache);
2193 if (cachedColorSpace) {
2194 return cachedColorSpace;
2195 }
2196 const parsedColorSpace = this._parse(cs, xref, resources, pdfFunctionFactory);
2197 this._cache(cs, xref, localColorSpaceCache, parsedColorSpace);
2198 return parsedColorSpace;
2199 }
2200 static _parse(cs, xref, resources = null, pdfFunctionFactory) {
2201 cs = xref.fetchIfRef(cs);
2202 if (cs instanceof Name) {
2203 switch (cs.name) {
2204 case "G":
2205 case "DeviceGray":
2206 return this.singletons.gray;
2207 case "RGB":
2208 case "DeviceRGB":
2209 return this.singletons.rgb;
2210 case "CMYK":
2211 case "DeviceCMYK":
2212 return this.singletons.cmyk;
2213 case "Pattern":
2214 return new PatternCS(null);
2215 default:
2216 if (resources instanceof Dict) {
2217 const colorSpaces = resources.get("ColorSpace");
2218 if (colorSpaces instanceof Dict) {
2219 const resourcesCS = colorSpaces.get(cs.name);
2220 if (resourcesCS) {
2221 if (resourcesCS instanceof Name) {
2222 return this._parse(resourcesCS, xref, resources, pdfFunctionFactory);
2223 }
2224 cs = resourcesCS;
2225 break;
2226 }
2227 }
2228 }
2229 throw new FormatError(`Unrecognized ColorSpace: ${cs.name}`);
2230 }
2231 }
2232 if (Array.isArray(cs)) {
2233 const mode = xref.fetchIfRef(cs[0]).name;
2234 let params, numComps, baseCS, whitePoint, blackPoint, gamma;
2235 switch (mode) {
2236 case "G":
2237 case "DeviceGray":
2238 return this.singletons.gray;
2239 case "RGB":
2240 case "DeviceRGB":
2241 return this.singletons.rgb;
2242 case "CMYK":
2243 case "DeviceCMYK":
2244 return this.singletons.cmyk;
2245 case "CalGray":
2246 params = xref.fetchIfRef(cs[1]);
2247 whitePoint = params.getArray("WhitePoint");
2248 blackPoint = params.getArray("BlackPoint");
2249 gamma = params.get("Gamma");
2250 return new CalGrayCS(whitePoint, blackPoint, gamma);
2251 case "CalRGB":
2252 params = xref.fetchIfRef(cs[1]);
2253 whitePoint = params.getArray("WhitePoint");
2254 blackPoint = params.getArray("BlackPoint");
2255 gamma = params.getArray("Gamma");
2256 const matrix = params.getArray("Matrix");
2257 return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
2258 case "ICCBased":
2259 const stream = xref.fetchIfRef(cs[1]);
2260 const dict = stream.dict;
2261 numComps = dict.get("N");
2262 const alt = dict.get("Alternate");
2263 if (alt) {
2264 const altCS = this._parse(alt, xref, resources, pdfFunctionFactory);
2265 if (altCS.numComps === numComps) {
2266 return altCS;
2267 }
2268 warn("ICCBased color space: Ignoring incorrect /Alternate entry.");
2269 }
2270 if (numComps === 1) {
2271 return this.singletons.gray;
2272 } else if (numComps === 3) {
2273 return this.singletons.rgb;
2274 } else if (numComps === 4) {
2275 return this.singletons.cmyk;
2276 }
2277 break;
2278 case "Pattern":
2279 baseCS = cs[1] || null;
2280 if (baseCS) {
2281 baseCS = this._parse(baseCS, xref, resources, pdfFunctionFactory);
2282 }
2283 return new PatternCS(baseCS);
2284 case "I":
2285 case "Indexed":
2286 baseCS = this._parse(cs[1], xref, resources, pdfFunctionFactory);
2287 const hiVal = xref.fetchIfRef(cs[2]) + 1;
2288 const lookup = xref.fetchIfRef(cs[3]);
2289 return new IndexedCS(baseCS, hiVal, lookup);
2290 case "Separation":
2291 case "DeviceN":
2292 const name = xref.fetchIfRef(cs[1]);
2293 numComps = Array.isArray(name) ? name.length : 1;
2294 baseCS = this._parse(cs[2], xref, resources, pdfFunctionFactory);
2295 const tintFn = pdfFunctionFactory.create(cs[3]);
2296 return new AlternateCS(numComps, baseCS, tintFn);
2297 case "Lab":
2298 params = xref.fetchIfRef(cs[1]);
2299 whitePoint = params.getArray("WhitePoint");
2300 blackPoint = params.getArray("BlackPoint");
2301 const range = params.getArray("Range");
2302 return new LabCS(whitePoint, blackPoint, range);
2303 default:
2304 throw new FormatError(`Unimplemented ColorSpace object: ${mode}`);
2305 }
2306 }
2307 throw new FormatError(`Unrecognized ColorSpace object: ${cs}`);
2308 }
2309 static isDefaultDecode(decode, numComps) {
2310 if (!Array.isArray(decode)) {
2311 return true;
2312 }
2313 if (numComps * 2 !== decode.length) {
2314 warn("The decode map is not the correct length");
2315 return true;
2316 }
2317 for (let i = 0, ii = decode.length; i < ii; i += 2) {
2318 if (decode[i] !== 0 || decode[i + 1] !== 1) {
2319 return false;
2320 }
2321 }
2322 return true;
2323 }
2324 static get singletons() {
2325 return shadow(this, "singletons", {
2326 get gray() {
2327 return shadow(this, "gray", new DeviceGrayCS());
2328 },
2329 get rgb() {
2330 return shadow(this, "rgb", new DeviceRgbCS());
2331 },
2332 get cmyk() {
2333 return shadow(this, "cmyk", new DeviceCmykCS());
2334 }
2335 });
2336 }
2337}
2338class AlternateCS extends ColorSpace {
2339 constructor(numComps, base, tintFn) {
2340 super("Alternate", numComps);
2341 this.base = base;
2342 this.tintFn = tintFn;
2343 this.tmpBuf = new Float32Array(base.numComps);
2344 }
2345 getRgbItem(src, srcOffset, dest, destOffset) {
2346 const tmpBuf = this.tmpBuf;
2347 this.tintFn(src, srcOffset, tmpBuf, 0);
2348 this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
2349 }
2350 getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
2351 const tintFn = this.tintFn;
2352 const base = this.base;
2353 const scale = 1 / ((1 << bits) - 1);
2354 const baseNumComps = base.numComps;
2355 const usesZeroToOneRange = base.usesZeroToOneRange;
2356 const isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) && alpha01 === 0;
2357 let pos = isPassthrough ? destOffset : 0;
2358 const baseBuf = isPassthrough ? dest : new Uint8ClampedArray(baseNumComps * count);
2359 const numComps = this.numComps;
2360 const scaled = new Float32Array(numComps);
2361 const tinted = new Float32Array(baseNumComps);
2362 let i, j;
2363 for (i = 0; i < count; i++) {
2364 for (j = 0; j < numComps; j++) {
2365 scaled[j] = src[srcOffset++] * scale;
2366 }
2367 tintFn(scaled, 0, tinted, 0);
2368 if (usesZeroToOneRange) {
2369 for (j = 0; j < baseNumComps; j++) {
2370 baseBuf[pos++] = tinted[j] * 255;
2371 }
2372 } else {
2373 base.getRgbItem(tinted, 0, baseBuf, pos);
2374 pos += baseNumComps;
2375 }
2376 }
2377 if (!isPassthrough) {
2378 base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
2379 }
2380 }
2381 getOutputLength(inputLength, alpha01) {
2382 return this.base.getOutputLength(inputLength * this.base.numComps / this.numComps, alpha01);
2383 }
2384}
2385class PatternCS extends ColorSpace {
2386 constructor(baseCS) {
2387 super("Pattern", null);
2388 this.base = baseCS;
2389 }
2390 isDefaultDecode(decodeMap, bpc) {
2391 unreachable("Should not call PatternCS.isDefaultDecode");
2392 }
2393}
2394class IndexedCS extends ColorSpace {
2395 constructor(base, highVal, lookup) {
2396 super("Indexed", 1);
2397 this.base = base;
2398 this.highVal = highVal;
2399 const length = base.numComps * highVal;
2400 this.lookup = new Uint8Array(length);
2401 if (lookup instanceof BaseStream) {
2402 const bytes = lookup.getBytes(length);
2403 this.lookup.set(bytes);
2404 } else if (typeof lookup === "string") {
2405 for (let i = 0; i < length; ++i) {
2406 this.lookup[i] = lookup.charCodeAt(i) & 0xff;
2407 }
2408 } else {
2409 throw new FormatError(`IndexedCS - unrecognized lookup table: ${lookup}`);
2410 }
2411 }
2412 getRgbItem(src, srcOffset, dest, destOffset) {
2413 const numComps = this.base.numComps;
2414 const start = src[srcOffset] * numComps;
2415 this.base.getRgbBuffer(this.lookup, start, 1, dest, destOffset, 8, 0);
2416 }
2417 getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
2418 const base = this.base;
2419 const numComps = base.numComps;
2420 const outputDelta = base.getOutputLength(numComps, alpha01);
2421 const lookup = this.lookup;
2422 for (let i = 0; i < count; ++i) {
2423 const lookupPos = src[srcOffset++] * numComps;
2424 base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
2425 destOffset += outputDelta;
2426 }
2427 }
2428 getOutputLength(inputLength, alpha01) {
2429 return this.base.getOutputLength(inputLength * this.base.numComps, alpha01);
2430 }
2431 isDefaultDecode(decodeMap, bpc) {
2432 if (!Array.isArray(decodeMap)) {
2433 return true;
2434 }
2435 if (decodeMap.length !== 2) {
2436 warn("Decode map length is not correct");
2437 return true;
2438 }
2439 if (!Number.isInteger(bpc) || bpc < 1) {
2440 warn("Bits per component is not correct");
2441 return true;
2442 }
2443 return decodeMap[0] === 0 && decodeMap[1] === (1 << bpc) - 1;
2444 }
2445}
2446class DeviceGrayCS extends ColorSpace {
2447 constructor() {
2448 super("DeviceGray", 1);
2449 }
2450 getRgbItem(src, srcOffset, dest, destOffset) {
2451 const c = src[srcOffset] * 255;
2452 dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
2453 }
2454 getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
2455 const scale = 255 / ((1 << bits) - 1);
2456 let j = srcOffset,
2457 q = destOffset;
2458 for (let i = 0; i < count; ++i) {
2459 const c = scale * src[j++];
2460 dest[q++] = c;
2461 dest[q++] = c;
2462 dest[q++] = c;
2463 q += alpha01;
2464 }
2465 }
2466 getOutputLength(inputLength, alpha01) {
2467 return inputLength * (3 + alpha01);
2468 }
2469}
2470class DeviceRgbCS extends ColorSpace {
2471 constructor() {
2472 super("DeviceRGB", 3);
2473 }
2474 getRgbItem(src, srcOffset, dest, destOffset) {
2475 dest[destOffset] = src[srcOffset] * 255;
2476 dest[destOffset + 1] = src[srcOffset + 1] * 255;
2477 dest[destOffset + 2] = src[srcOffset + 2] * 255;
2478 }
2479 getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
2480 if (bits === 8 && alpha01 === 0) {
2481 dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
2482 return;
2483 }
2484 const scale = 255 / ((1 << bits) - 1);
2485 let j = srcOffset,
2486 q = destOffset;
2487 for (let i = 0; i < count; ++i) {
2488 dest[q++] = scale * src[j++];
2489 dest[q++] = scale * src[j++];
2490 dest[q++] = scale * src[j++];
2491 q += alpha01;
2492 }
2493 }
2494 getOutputLength(inputLength, alpha01) {
2495 return inputLength * (3 + alpha01) / 3 | 0;
2496 }
2497 isPassthrough(bits) {
2498 return bits === 8;
2499 }
2500}
2501class DeviceCmykCS extends ColorSpace {
2502 constructor() {
2503 super("DeviceCMYK", 4);
2504 }
2505 #toRgb(src, srcOffset, srcScale, dest, destOffset) {
2506 const c = src[srcOffset] * srcScale;
2507 const m = src[srcOffset + 1] * srcScale;
2508 const y = src[srcOffset + 2] * srcScale;
2509 const k = src[srcOffset + 3] * srcScale;
2510 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);
2511 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);
2512 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);
2513 }
2514 getRgbItem(src, srcOffset, dest, destOffset) {
2515 this.#toRgb(src, srcOffset, 1, dest, destOffset);
2516 }
2517 getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
2518 const scale = 1 / ((1 << bits) - 1);
2519 for (let i = 0; i < count; i++) {
2520 this.#toRgb(src, srcOffset, scale, dest, destOffset);
2521 srcOffset += 4;
2522 destOffset += 3 + alpha01;
2523 }
2524 }
2525 getOutputLength(inputLength, alpha01) {
2526 return inputLength / 4 * (3 + alpha01) | 0;
2527 }
2528}
2529class CalGrayCS extends ColorSpace {
2530 constructor(whitePoint, blackPoint, gamma) {
2531 super("CalGray", 1);
2532 if (!whitePoint) {
2533 throw new FormatError("WhitePoint missing - required for color space CalGray");
2534 }
2535 [this.XW, this.YW, this.ZW] = whitePoint;
2536 [this.XB, this.YB, this.ZB] = blackPoint || [0, 0, 0];
2537 this.G = gamma || 1;
2538 if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
2539 throw new FormatError(`Invalid WhitePoint components for ${this.name}, no fallback available`);
2540 }
2541 if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
2542 info(`Invalid BlackPoint for ${this.name}, falling back to default.`);
2543 this.XB = this.YB = this.ZB = 0;
2544 }
2545 if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
2546 warn(`${this.name}, BlackPoint: XB: ${this.XB}, YB: ${this.YB}, ` + `ZB: ${this.ZB}, only default values are supported.`);
2547 }
2548 if (this.G < 1) {
2549 info(`Invalid Gamma: ${this.G} for ${this.name}, falling back to default.`);
2550 this.G = 1;
2551 }
2552 }
2553 #toRgb(src, srcOffset, dest, destOffset, scale) {
2554 const A = src[srcOffset] * scale;
2555 const AG = A ** this.G;
2556 const L = this.YW * AG;
2557 const val = Math.max(295.8 * L ** 0.3333333333333333 - 40.8, 0);
2558 dest[destOffset] = val;
2559 dest[destOffset + 1] = val;
2560 dest[destOffset + 2] = val;
2561 }
2562 getRgbItem(src, srcOffset, dest, destOffset) {
2563 this.#toRgb(src, srcOffset, dest, destOffset, 1);
2564 }
2565 getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
2566 const scale = 1 / ((1 << bits) - 1);
2567 for (let i = 0; i < count; ++i) {
2568 this.#toRgb(src, srcOffset, dest, destOffset, scale);
2569 srcOffset += 1;
2570 destOffset += 3 + alpha01;
2571 }
2572 }
2573 getOutputLength(inputLength, alpha01) {
2574 return inputLength * (3 + alpha01);
2575 }
2576}
2577class CalRGBCS extends ColorSpace {
2578 static #BRADFORD_SCALE_MATRIX = new Float32Array([0.8951, 0.2664, -0.1614, -0.7502, 1.7135, 0.0367, 0.0389, -0.0685, 1.0296]);
2579 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]);
2580 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]);
2581 static #FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
2582 static #tempNormalizeMatrix = new Float32Array(3);
2583 static #tempConvertMatrix1 = new Float32Array(3);
2584 static #tempConvertMatrix2 = new Float32Array(3);
2585 static #DECODE_L_CONSTANT = ((8 + 16) / 116) ** 3 / 8.0;
2586 constructor(whitePoint, blackPoint, gamma, matrix) {
2587 super("CalRGB", 3);
2588 if (!whitePoint) {
2589 throw new FormatError("WhitePoint missing - required for color space CalRGB");
2590 }
2591 const [XW, YW, ZW] = this.whitePoint = whitePoint;
2592 const [XB, YB, ZB] = this.blackPoint = blackPoint || new Float32Array(3);
2593 [this.GR, this.GG, this.GB] = gamma || new Float32Array([1, 1, 1]);
2594 [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]);
2595 if (XW < 0 || ZW < 0 || YW !== 1) {
2596 throw new FormatError(`Invalid WhitePoint components for ${this.name}, no fallback available`);
2597 }
2598 if (XB < 0 || YB < 0 || ZB < 0) {
2599 info(`Invalid BlackPoint for ${this.name} [${XB}, ${YB}, ${ZB}], ` + "falling back to default.");
2600 this.blackPoint = new Float32Array(3);
2601 }
2602 if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
2603 info(`Invalid Gamma [${this.GR}, ${this.GG}, ${this.GB}] for ` + `${this.name}, falling back to default.`);
2604 this.GR = this.GG = this.GB = 1;
2605 }
2606 }
2607 #matrixProduct(a, b, result) {
2608 result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
2609 result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
2610 result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
2611 }
2612 #toFlat(sourceWhitePoint, LMS, result) {
2613 result[0] = LMS[0] * 1 / sourceWhitePoint[0];
2614 result[1] = LMS[1] * 1 / sourceWhitePoint[1];
2615 result[2] = LMS[2] * 1 / sourceWhitePoint[2];
2616 }
2617 #toD65(sourceWhitePoint, LMS, result) {
2618 const D65X = 0.95047;
2619 const D65Y = 1;
2620 const D65Z = 1.08883;
2621 result[0] = LMS[0] * D65X / sourceWhitePoint[0];
2622 result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
2623 result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
2624 }
2625 #sRGBTransferFunction(color) {
2626 if (color <= 0.0031308) {
2627 return this.#adjustToRange(0, 1, 12.92 * color);
2628 }
2629 if (color >= 0.99554525) {
2630 return 1;
2631 }
2632 return this.#adjustToRange(0, 1, (1 + 0.055) * color ** (1 / 2.4) - 0.055);
2633 }
2634 #adjustToRange(min, max, value) {
2635 return Math.max(min, Math.min(max, value));
2636 }
2637 #decodeL(L) {
2638 if (L < 0) {
2639 return -this.#decodeL(-L);
2640 }
2641 if (L > 8.0) {
2642 return ((L + 16) / 116) ** 3;
2643 }
2644 return L * CalRGBCS.#DECODE_L_CONSTANT;
2645 }
2646 #compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
2647 if (sourceBlackPoint[0] === 0 && sourceBlackPoint[1] === 0 && sourceBlackPoint[2] === 0) {
2648 result[0] = XYZ_Flat[0];
2649 result[1] = XYZ_Flat[1];
2650 result[2] = XYZ_Flat[2];
2651 return;
2652 }
2653 const zeroDecodeL = this.#decodeL(0);
2654 const X_DST = zeroDecodeL;
2655 const X_SRC = this.#decodeL(sourceBlackPoint[0]);
2656 const Y_DST = zeroDecodeL;
2657 const Y_SRC = this.#decodeL(sourceBlackPoint[1]);
2658 const Z_DST = zeroDecodeL;
2659 const Z_SRC = this.#decodeL(sourceBlackPoint[2]);
2660 const X_Scale = (1 - X_DST) / (1 - X_SRC);
2661 const X_Offset = 1 - X_Scale;
2662 const Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
2663 const Y_Offset = 1 - Y_Scale;
2664 const Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
2665 const Z_Offset = 1 - Z_Scale;
2666 result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
2667 result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
2668 result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
2669 }
2670 #normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
2671 if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
2672 result[0] = XYZ_In[0];
2673 result[1] = XYZ_In[1];
2674 result[2] = XYZ_In[2];
2675 return;
2676 }
2677 const LMS = result;
2678 this.#matrixProduct(CalRGBCS.#BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
2679 const LMS_Flat = CalRGBCS.#tempNormalizeMatrix;
2680 this.#toFlat(sourceWhitePoint, LMS, LMS_Flat);
2681 this.#matrixProduct(CalRGBCS.#BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
2682 }
2683 #normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
2684 const LMS = result;
2685 this.#matrixProduct(CalRGBCS.#BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
2686 const LMS_D65 = CalRGBCS.#tempNormalizeMatrix;
2687 this.#toD65(sourceWhitePoint, LMS, LMS_D65);
2688 this.#matrixProduct(CalRGBCS.#BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
2689 }
2690 #toRgb(src, srcOffset, dest, destOffset, scale) {
2691 const A = this.#adjustToRange(0, 1, src[srcOffset] * scale);
2692 const B = this.#adjustToRange(0, 1, src[srcOffset + 1] * scale);
2693 const C = this.#adjustToRange(0, 1, src[srcOffset + 2] * scale);
2694 const AGR = A === 1 ? 1 : A ** this.GR;
2695 const BGG = B === 1 ? 1 : B ** this.GG;
2696 const CGB = C === 1 ? 1 : C ** this.GB;
2697 const X = this.MXA * AGR + this.MXB * BGG + this.MXC * CGB;
2698 const Y = this.MYA * AGR + this.MYB * BGG + this.MYC * CGB;
2699 const Z = this.MZA * AGR + this.MZB * BGG + this.MZC * CGB;
2700 const XYZ = CalRGBCS.#tempConvertMatrix1;
2701 XYZ[0] = X;
2702 XYZ[1] = Y;
2703 XYZ[2] = Z;
2704 const XYZ_Flat = CalRGBCS.#tempConvertMatrix2;
2705 this.#normalizeWhitePointToFlat(this.whitePoint, XYZ, XYZ_Flat);
2706 const XYZ_Black = CalRGBCS.#tempConvertMatrix1;
2707 this.#compensateBlackPoint(this.blackPoint, XYZ_Flat, XYZ_Black);
2708 const XYZ_D65 = CalRGBCS.#tempConvertMatrix2;
2709 this.#normalizeWhitePointToD65(CalRGBCS.#FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
2710 const SRGB = CalRGBCS.#tempConvertMatrix1;
2711 this.#matrixProduct(CalRGBCS.#SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
2712 dest[destOffset] = this.#sRGBTransferFunction(SRGB[0]) * 255;
2713 dest[destOffset + 1] = this.#sRGBTransferFunction(SRGB[1]) * 255;
2714 dest[destOffset + 2] = this.#sRGBTransferFunction(SRGB[2]) * 255;
2715 }
2716 getRgbItem(src, srcOffset, dest, destOffset) {
2717 this.#toRgb(src, srcOffset, dest, destOffset, 1);
2718 }
2719 getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
2720 const scale = 1 / ((1 << bits) - 1);
2721 for (let i = 0; i < count; ++i) {
2722 this.#toRgb(src, srcOffset, dest, destOffset, scale);
2723 srcOffset += 3;
2724 destOffset += 3 + alpha01;
2725 }
2726 }
2727 getOutputLength(inputLength, alpha01) {
2728 return inputLength * (3 + alpha01) / 3 | 0;
2729 }
2730}
2731class LabCS extends ColorSpace {
2732 constructor(whitePoint, blackPoint, range) {
2733 super("Lab", 3);
2734 if (!whitePoint) {
2735 throw new FormatError("WhitePoint missing - required for color space Lab");
2736 }
2737 [this.XW, this.YW, this.ZW] = whitePoint;
2738 [this.amin, this.amax, this.bmin, this.bmax] = range || [-100, 100, -100, 100];
2739 [this.XB, this.YB, this.ZB] = blackPoint || [0, 0, 0];
2740 if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
2741 throw new FormatError("Invalid WhitePoint components, no fallback available");
2742 }
2743 if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
2744 info("Invalid BlackPoint, falling back to default");
2745 this.XB = this.YB = this.ZB = 0;
2746 }
2747 if (this.amin > this.amax || this.bmin > this.bmax) {
2748 info("Invalid Range, falling back to defaults");
2749 this.amin = -100;
2750 this.amax = 100;
2751 this.bmin = -100;
2752 this.bmax = 100;
2753 }
2754 }
2755 #fn_g(x) {
2756 return x >= 6 / 29 ? x ** 3 : 108 / 841 * (x - 4 / 29);
2757 }
2758 #decode(value, high1, low2, high2) {
2759 return low2 + value * (high2 - low2) / high1;
2760 }
2761 #toRgb(src, srcOffset, maxVal, dest, destOffset) {
2762 let Ls = src[srcOffset];
2763 let as = src[srcOffset + 1];
2764 let bs = src[srcOffset + 2];
2765 if (maxVal !== false) {
2766 Ls = this.#decode(Ls, maxVal, 0, 100);
2767 as = this.#decode(as, maxVal, this.amin, this.amax);
2768 bs = this.#decode(bs, maxVal, this.bmin, this.bmax);
2769 }
2770 if (as > this.amax) {
2771 as = this.amax;
2772 } else if (as < this.amin) {
2773 as = this.amin;
2774 }
2775 if (bs > this.bmax) {
2776 bs = this.bmax;
2777 } else if (bs < this.bmin) {
2778 bs = this.bmin;
2779 }
2780 const M = (Ls + 16) / 116;
2781 const L = M + as / 500;
2782 const N = M - bs / 200;
2783 const X = this.XW * this.#fn_g(L);
2784 const Y = this.YW * this.#fn_g(M);
2785 const Z = this.ZW * this.#fn_g(N);
2786 let r, g, b;
2787 if (this.ZW < 1) {
2788 r = X * 3.1339 + Y * -1.617 + Z * -0.4906;
2789 g = X * -0.9785 + Y * 1.916 + Z * 0.0333;
2790 b = X * 0.072 + Y * -0.229 + Z * 1.4057;
2791 } else {
2792 r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
2793 g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
2794 b = X * 0.0557 + Y * -0.204 + Z * 1.057;
2795 }
2796 dest[destOffset] = Math.sqrt(r) * 255;
2797 dest[destOffset + 1] = Math.sqrt(g) * 255;
2798 dest[destOffset + 2] = Math.sqrt(b) * 255;
2799 }
2800 getRgbItem(src, srcOffset, dest, destOffset) {
2801 this.#toRgb(src, srcOffset, false, dest, destOffset);
2802 }
2803 getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
2804 const maxVal = (1 << bits) - 1;
2805 for (let i = 0; i < count; i++) {
2806 this.#toRgb(src, srcOffset, maxVal, dest, destOffset);
2807 srcOffset += 3;
2808 destOffset += 3 + alpha01;
2809 }
2810 }
2811 getOutputLength(inputLength, alpha01) {
2812 return inputLength * (3 + alpha01) / 3 | 0;
2813 }
2814 isDefaultDecode(decodeMap, bpc) {
2815 return true;
2816 }
2817 get usesZeroToOneRange() {
2818 return shadow(this, "usesZeroToOneRange", false);
2819 }
2820}
2821
2822;// CONCATENATED MODULE: ./src/core/binary_cmap.js
2823
2824function hexToInt(a, size) {
2825 let n = 0;
2826 for (let i = 0; i <= size; i++) {
2827 n = n << 8 | a[i];
2828 }
2829 return n >>> 0;
2830}
2831function hexToStr(a, size) {
2832 if (size === 1) {
2833 return String.fromCharCode(a[0], a[1]);
2834 }
2835 if (size === 3) {
2836 return String.fromCharCode(a[0], a[1], a[2], a[3]);
2837 }
2838 return String.fromCharCode(...a.subarray(0, size + 1));
2839}
2840function addHex(a, b, size) {
2841 let c = 0;
2842 for (let i = size; i >= 0; i--) {
2843 c += a[i] + b[i];
2844 a[i] = c & 255;
2845 c >>= 8;
2846 }
2847}
2848function incHex(a, size) {
2849 let c = 1;
2850 for (let i = size; i >= 0 && c > 0; i--) {
2851 c += a[i];
2852 a[i] = c & 255;
2853 c >>= 8;
2854 }
2855}
2856const MAX_NUM_SIZE = 16;
2857const MAX_ENCODED_NUM_SIZE = 19;
2858class BinaryCMapStream {
2859 constructor(data) {
2860 this.buffer = data;
2861 this.pos = 0;
2862 this.end = data.length;
2863 this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
2864 }
2865 readByte() {
2866 if (this.pos >= this.end) {
2867 return -1;
2868 }
2869 return this.buffer[this.pos++];
2870 }
2871 readNumber() {
2872 let n = 0;
2873 let last;
2874 do {
2875 const b = this.readByte();
2876 if (b < 0) {
2877 throw new FormatError("unexpected EOF in bcmap");
2878 }
2879 last = !(b & 0x80);
2880 n = n << 7 | b & 0x7f;
2881 } while (!last);
2882 return n;
2883 }
2884 readSigned() {
2885 const n = this.readNumber();
2886 return n & 1 ? ~(n >>> 1) : n >>> 1;
2887 }
2888 readHex(num, size) {
2889 num.set(this.buffer.subarray(this.pos, this.pos + size + 1));
2890 this.pos += size + 1;
2891 }
2892 readHexNumber(num, size) {
2893 let last;
2894 const stack = this.tmpBuf;
2895 let sp = 0;
2896 do {
2897 const b = this.readByte();
2898 if (b < 0) {
2899 throw new FormatError("unexpected EOF in bcmap");
2900 }
2901 last = !(b & 0x80);
2902 stack[sp++] = b & 0x7f;
2903 } while (!last);
2904 let i = size,
2905 buffer = 0,
2906 bufferSize = 0;
2907 while (i >= 0) {
2908 while (bufferSize < 8 && stack.length > 0) {
2909 buffer |= stack[--sp] << bufferSize;
2910 bufferSize += 7;
2911 }
2912 num[i] = buffer & 255;
2913 i--;
2914 buffer >>= 8;
2915 bufferSize -= 8;
2916 }
2917 }
2918 readHexSigned(num, size) {
2919 this.readHexNumber(num, size);
2920 const sign = num[size] & 1 ? 255 : 0;
2921 let c = 0;
2922 for (let i = 0; i <= size; i++) {
2923 c = (c & 1) << 8 | num[i];
2924 num[i] = c >> 1 ^ sign;
2925 }
2926 }
2927 readString() {
2928 const len = this.readNumber(),
2929 buf = new Array(len);
2930 for (let i = 0; i < len; i++) {
2931 buf[i] = this.readNumber();
2932 }
2933 return String.fromCharCode(...buf);
2934 }
2935}
2936class BinaryCMapReader {
2937 async process(data, cMap, extend) {
2938 const stream = new BinaryCMapStream(data);
2939 const header = stream.readByte();
2940 cMap.vertical = !!(header & 1);
2941 let useCMap = null;
2942 const start = new Uint8Array(MAX_NUM_SIZE);
2943 const end = new Uint8Array(MAX_NUM_SIZE);
2944 const char = new Uint8Array(MAX_NUM_SIZE);
2945 const charCode = new Uint8Array(MAX_NUM_SIZE);
2946 const tmp = new Uint8Array(MAX_NUM_SIZE);
2947 let code;
2948 let b;
2949 while ((b = stream.readByte()) >= 0) {
2950 const type = b >> 5;
2951 if (type === 7) {
2952 switch (b & 0x1f) {
2953 case 0:
2954 stream.readString();
2955 break;
2956 case 1:
2957 useCMap = stream.readString();
2958 break;
2959 }
2960 continue;
2961 }
2962 const sequence = !!(b & 0x10);
2963 const dataSize = b & 15;
2964 if (dataSize + 1 > MAX_NUM_SIZE) {
2965 throw new Error("BinaryCMapReader.process: Invalid dataSize.");
2966 }
2967 const ucs2DataSize = 1;
2968 const subitemsCount = stream.readNumber();
2969 switch (type) {
2970 case 0:
2971 stream.readHex(start, dataSize);
2972 stream.readHexNumber(end, dataSize);
2973 addHex(end, start, dataSize);
2974 cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize), hexToInt(end, dataSize));
2975 for (let i = 1; i < subitemsCount; i++) {
2976 incHex(end, dataSize);
2977 stream.readHexNumber(start, dataSize);
2978 addHex(start, end, dataSize);
2979 stream.readHexNumber(end, dataSize);
2980 addHex(end, start, dataSize);
2981 cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize), hexToInt(end, dataSize));
2982 }
2983 break;
2984 case 1:
2985 stream.readHex(start, dataSize);
2986 stream.readHexNumber(end, dataSize);
2987 addHex(end, start, dataSize);
2988 stream.readNumber();
2989 for (let i = 1; i < subitemsCount; i++) {
2990 incHex(end, dataSize);
2991 stream.readHexNumber(start, dataSize);
2992 addHex(start, end, dataSize);
2993 stream.readHexNumber(end, dataSize);
2994 addHex(end, start, dataSize);
2995 stream.readNumber();
2996 }
2997 break;
2998 case 2:
2999 stream.readHex(char, dataSize);
3000 code = stream.readNumber();
3001 cMap.mapOne(hexToInt(char, dataSize), code);
3002 for (let i = 1; i < subitemsCount; i++) {
3003 incHex(char, dataSize);
3004 if (!sequence) {
3005 stream.readHexNumber(tmp, dataSize);
3006 addHex(char, tmp, dataSize);
3007 }
3008 code = stream.readSigned() + (code + 1);
3009 cMap.mapOne(hexToInt(char, dataSize), code);
3010 }
3011 break;
3012 case 3:
3013 stream.readHex(start, dataSize);
3014 stream.readHexNumber(end, dataSize);
3015 addHex(end, start, dataSize);
3016 code = stream.readNumber();
3017 cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize), code);
3018 for (let i = 1; i < subitemsCount; i++) {
3019 incHex(end, dataSize);
3020 if (!sequence) {
3021 stream.readHexNumber(start, dataSize);
3022 addHex(start, end, dataSize);
3023 } else {
3024 start.set(end);
3025 }
3026 stream.readHexNumber(end, dataSize);
3027 addHex(end, start, dataSize);
3028 code = stream.readNumber();
3029 cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize), code);
3030 }
3031 break;
3032 case 4:
3033 stream.readHex(char, ucs2DataSize);
3034 stream.readHex(charCode, dataSize);
3035 cMap.mapOne(hexToInt(char, ucs2DataSize), hexToStr(charCode, dataSize));
3036 for (let i = 1; i < subitemsCount; i++) {
3037 incHex(char, ucs2DataSize);
3038 if (!sequence) {
3039 stream.readHexNumber(tmp, ucs2DataSize);
3040 addHex(char, tmp, ucs2DataSize);
3041 }
3042 incHex(charCode, dataSize);
3043 stream.readHexSigned(tmp, dataSize);
3044 addHex(charCode, tmp, dataSize);
3045 cMap.mapOne(hexToInt(char, ucs2DataSize), hexToStr(charCode, dataSize));
3046 }
3047 break;
3048 case 5:
3049 stream.readHex(start, ucs2DataSize);
3050 stream.readHexNumber(end, ucs2DataSize);
3051 addHex(end, start, ucs2DataSize);
3052 stream.readHex(charCode, dataSize);
3053 cMap.mapBfRange(hexToInt(start, ucs2DataSize), hexToInt(end, ucs2DataSize), hexToStr(charCode, dataSize));
3054 for (let i = 1; i < subitemsCount; i++) {
3055 incHex(end, ucs2DataSize);
3056 if (!sequence) {
3057 stream.readHexNumber(start, ucs2DataSize);
3058 addHex(start, end, ucs2DataSize);
3059 } else {
3060 start.set(end);
3061 }
3062 stream.readHexNumber(end, ucs2DataSize);
3063 addHex(end, start, ucs2DataSize);
3064 stream.readHex(charCode, dataSize);
3065 cMap.mapBfRange(hexToInt(start, ucs2DataSize), hexToInt(end, ucs2DataSize), hexToStr(charCode, dataSize));
3066 }
3067 break;
3068 default:
3069 throw new Error(`BinaryCMapReader.process - unknown type: ${type}`);
3070 }
3071 }
3072 if (useCMap) {
3073 return extend(useCMap);
3074 }
3075 return cMap;
3076 }
3077}
3078
3079;// CONCATENATED MODULE: ./src/core/decode_stream.js
3080
3081
3082const emptyBuffer = new Uint8Array(0);
3083class DecodeStream extends BaseStream {
3084 constructor(maybeMinBufferLength) {
3085 super();
3086 this._rawMinBufferLength = maybeMinBufferLength || 0;
3087 this.pos = 0;
3088 this.bufferLength = 0;
3089 this.eof = false;
3090 this.buffer = emptyBuffer;
3091 this.minBufferLength = 512;
3092 if (maybeMinBufferLength) {
3093 while (this.minBufferLength < maybeMinBufferLength) {
3094 this.minBufferLength *= 2;
3095 }
3096 }
3097 }
3098 get isEmpty() {
3099 while (!this.eof && this.bufferLength === 0) {
3100 this.readBlock();
3101 }
3102 return this.bufferLength === 0;
3103 }
3104 ensureBuffer(requested) {
3105 const buffer = this.buffer;
3106 if (requested <= buffer.byteLength) {
3107 return buffer;
3108 }
3109 let size = this.minBufferLength;
3110 while (size < requested) {
3111 size *= 2;
3112 }
3113 const buffer2 = new Uint8Array(size);
3114 buffer2.set(buffer);
3115 return this.buffer = buffer2;
3116 }
3117 getByte() {
3118 const pos = this.pos;
3119 while (this.bufferLength <= pos) {
3120 if (this.eof) {
3121 return -1;
3122 }
3123 this.readBlock();
3124 }
3125 return this.buffer[this.pos++];
3126 }
3127 getBytes(length) {
3128 const pos = this.pos;
3129 let end;
3130 if (length) {
3131 this.ensureBuffer(pos + length);
3132 end = pos + length;
3133 while (!this.eof && this.bufferLength < end) {
3134 this.readBlock();
3135 }
3136 const bufEnd = this.bufferLength;
3137 if (end > bufEnd) {
3138 end = bufEnd;
3139 }
3140 } else {
3141 while (!this.eof) {
3142 this.readBlock();
3143 }
3144 end = this.bufferLength;
3145 }
3146 this.pos = end;
3147 return this.buffer.subarray(pos, end);
3148 }
3149 reset() {
3150 this.pos = 0;
3151 }
3152 makeSubStream(start, length, dict = null) {
3153 if (length === undefined) {
3154 while (!this.eof) {
3155 this.readBlock();
3156 }
3157 } else {
3158 const end = start + length;
3159 while (this.bufferLength <= end && !this.eof) {
3160 this.readBlock();
3161 }
3162 }
3163 return new Stream(this.buffer, start, length, dict);
3164 }
3165 getBaseStreams() {
3166 return this.str ? this.str.getBaseStreams() : null;
3167 }
3168}
3169class StreamsSequenceStream extends DecodeStream {
3170 constructor(streams, onError = null) {
3171 let maybeLength = 0;
3172 for (const stream of streams) {
3173 maybeLength += stream instanceof DecodeStream ? stream._rawMinBufferLength : stream.length;
3174 }
3175 super(maybeLength);
3176 this.streams = streams;
3177 this._onError = onError;
3178 }
3179 readBlock() {
3180 const streams = this.streams;
3181 if (streams.length === 0) {
3182 this.eof = true;
3183 return;
3184 }
3185 const stream = streams.shift();
3186 let chunk;
3187 try {
3188 chunk = stream.getBytes();
3189 } catch (reason) {
3190 if (this._onError) {
3191 this._onError(reason, stream.dict?.objId);
3192 return;
3193 }
3194 throw reason;
3195 }
3196 const bufferLength = this.bufferLength;
3197 const newLength = bufferLength + chunk.length;
3198 const buffer = this.ensureBuffer(newLength);
3199 buffer.set(chunk, bufferLength);
3200 this.bufferLength = newLength;
3201 }
3202 getBaseStreams() {
3203 const baseStreamsBuf = [];
3204 for (const stream of this.streams) {
3205 const baseStreams = stream.getBaseStreams();
3206 if (baseStreams) {
3207 baseStreamsBuf.push(...baseStreams);
3208 }
3209 }
3210 return baseStreamsBuf.length > 0 ? baseStreamsBuf : null;
3211 }
3212}
3213
3214;// CONCATENATED MODULE: ./src/core/ascii_85_stream.js
3215
3216
3217class Ascii85Stream extends DecodeStream {
3218 constructor(str, maybeLength) {
3219 if (maybeLength) {
3220 maybeLength *= 0.8;
3221 }
3222 super(maybeLength);
3223 this.str = str;
3224 this.dict = str.dict;
3225 this.input = new Uint8Array(5);
3226 }
3227 readBlock() {
3228 const TILDA_CHAR = 0x7e;
3229 const Z_LOWER_CHAR = 0x7a;
3230 const EOF = -1;
3231 const str = this.str;
3232 let c = str.getByte();
3233 while (isWhiteSpace(c)) {
3234 c = str.getByte();
3235 }
3236 if (c === EOF || c === TILDA_CHAR) {
3237 this.eof = true;
3238 return;
3239 }
3240 const bufferLength = this.bufferLength;
3241 let buffer, i;
3242 if (c === Z_LOWER_CHAR) {
3243 buffer = this.ensureBuffer(bufferLength + 4);
3244 for (i = 0; i < 4; ++i) {
3245 buffer[bufferLength + i] = 0;
3246 }
3247 this.bufferLength += 4;
3248 } else {
3249 const input = this.input;
3250 input[0] = c;
3251 for (i = 1; i < 5; ++i) {
3252 c = str.getByte();
3253 while (isWhiteSpace(c)) {
3254 c = str.getByte();
3255 }
3256 input[i] = c;
3257 if (c === EOF || c === TILDA_CHAR) {
3258 break;
3259 }
3260 }
3261 buffer = this.ensureBuffer(bufferLength + i - 1);
3262 this.bufferLength += i - 1;
3263 if (i < 5) {
3264 for (; i < 5; ++i) {
3265 input[i] = 0x21 + 84;
3266 }
3267 this.eof = true;
3268 }
3269 let t = 0;
3270 for (i = 0; i < 5; ++i) {
3271 t = t * 85 + (input[i] - 0x21);
3272 }
3273 for (i = 3; i >= 0; --i) {
3274 buffer[bufferLength + i] = t & 0xff;
3275 t >>= 8;
3276 }
3277 }
3278 }
3279}
3280
3281;// CONCATENATED MODULE: ./src/core/ascii_hex_stream.js
3282
3283class AsciiHexStream extends DecodeStream {
3284 constructor(str, maybeLength) {
3285 if (maybeLength) {
3286 maybeLength *= 0.5;
3287 }
3288 super(maybeLength);
3289 this.str = str;
3290 this.dict = str.dict;
3291 this.firstDigit = -1;
3292 }
3293 readBlock() {
3294 const UPSTREAM_BLOCK_SIZE = 8000;
3295 const bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
3296 if (!bytes.length) {
3297 this.eof = true;
3298 return;
3299 }
3300 const maxDecodeLength = bytes.length + 1 >> 1;
3301 const buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
3302 let bufferLength = this.bufferLength;
3303 let firstDigit = this.firstDigit;
3304 for (const ch of bytes) {
3305 let digit;
3306 if (ch >= 0x30 && ch <= 0x39) {
3307 digit = ch & 0x0f;
3308 } else if (ch >= 0x41 && ch <= 0x46 || ch >= 0x61 && ch <= 0x66) {
3309 digit = (ch & 0x0f) + 9;
3310 } else if (ch === 0x3e) {
3311 this.eof = true;
3312 break;
3313 } else {
3314 continue;
3315 }
3316 if (firstDigit < 0) {
3317 firstDigit = digit;
3318 } else {
3319 buffer[bufferLength++] = firstDigit << 4 | digit;
3320 firstDigit = -1;
3321 }
3322 }
3323 if (firstDigit >= 0 && this.eof) {
3324 buffer[bufferLength++] = firstDigit << 4;
3325 firstDigit = -1;
3326 }
3327 this.firstDigit = firstDigit;
3328 this.bufferLength = bufferLength;
3329 }
3330}
3331
3332;// CONCATENATED MODULE: ./src/core/ccitt.js
3333
3334const ccittEOL = -2;
3335const ccittEOF = -1;
3336const twoDimPass = 0;
3337const twoDimHoriz = 1;
3338const twoDimVert0 = 2;
3339const twoDimVertR1 = 3;
3340const twoDimVertL1 = 4;
3341const twoDimVertR2 = 5;
3342const twoDimVertL2 = 6;
3343const twoDimVertR3 = 7;
3344const twoDimVertL3 = 8;
3345const 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]];
3346const 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]];
3347const 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]];
3348const 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]];
3349const 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]];
3350const 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]];
3351class CCITTFaxDecoder {
3352 constructor(source, options = {}) {
3353 if (!source || typeof source.next !== "function") {
3354 throw new Error('CCITTFaxDecoder - invalid "source" parameter.');
3355 }
3356 this.source = source;
3357 this.eof = false;
3358 this.encoding = options.K || 0;
3359 this.eoline = options.EndOfLine || false;
3360 this.byteAlign = options.EncodedByteAlign || false;
3361 this.columns = options.Columns || 1728;
3362 this.rows = options.Rows || 0;
3363 this.eoblock = options.EndOfBlock ?? true;
3364 this.black = options.BlackIs1 || false;
3365 this.codingLine = new Uint32Array(this.columns + 1);
3366 this.refLine = new Uint32Array(this.columns + 2);
3367 this.codingLine[0] = this.columns;
3368 this.codingPos = 0;
3369 this.row = 0;
3370 this.nextLine2D = this.encoding < 0;
3371 this.inputBits = 0;
3372 this.inputBuf = 0;
3373 this.outputBits = 0;
3374 this.rowsDone = false;
3375 let code1;
3376 while ((code1 = this._lookBits(12)) === 0) {
3377 this._eatBits(1);
3378 }
3379 if (code1 === 1) {
3380 this._eatBits(12);
3381 }
3382 if (this.encoding > 0) {
3383 this.nextLine2D = !this._lookBits(1);
3384 this._eatBits(1);
3385 }
3386 }
3387 readNextChar() {
3388 if (this.eof) {
3389 return -1;
3390 }
3391 const refLine = this.refLine;
3392 const codingLine = this.codingLine;
3393 const columns = this.columns;
3394 let refPos, blackPixels, bits, i;
3395 if (this.outputBits === 0) {
3396 if (this.rowsDone) {
3397 this.eof = true;
3398 }
3399 if (this.eof) {
3400 return -1;
3401 }
3402 this.err = false;
3403 let code1, code2, code3;
3404 if (this.nextLine2D) {
3405 for (i = 0; codingLine[i] < columns; ++i) {
3406 refLine[i] = codingLine[i];
3407 }
3408 refLine[i++] = columns;
3409 refLine[i] = columns;
3410 codingLine[0] = 0;
3411 this.codingPos = 0;
3412 refPos = 0;
3413 blackPixels = 0;
3414 while (codingLine[this.codingPos] < columns) {
3415 code1 = this._getTwoDimCode();
3416 switch (code1) {
3417 case twoDimPass:
3418 this._addPixels(refLine[refPos + 1], blackPixels);
3419 if (refLine[refPos + 1] < columns) {
3420 refPos += 2;
3421 }
3422 break;
3423 case twoDimHoriz:
3424 code1 = code2 = 0;
3425 if (blackPixels) {
3426 do {
3427 code1 += code3 = this._getBlackCode();
3428 } while (code3 >= 64);
3429 do {
3430 code2 += code3 = this._getWhiteCode();
3431 } while (code3 >= 64);
3432 } else {
3433 do {
3434 code1 += code3 = this._getWhiteCode();
3435 } while (code3 >= 64);
3436 do {
3437 code2 += code3 = this._getBlackCode();
3438 } while (code3 >= 64);
3439 }
3440 this._addPixels(codingLine[this.codingPos] + code1, blackPixels);
3441 if (codingLine[this.codingPos] < columns) {
3442 this._addPixels(codingLine[this.codingPos] + code2, blackPixels ^ 1);
3443 }
3444 while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
3445 refPos += 2;
3446 }
3447 break;
3448 case twoDimVertR3:
3449 this._addPixels(refLine[refPos] + 3, blackPixels);
3450 blackPixels ^= 1;
3451 if (codingLine[this.codingPos] < columns) {
3452 ++refPos;
3453 while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
3454 refPos += 2;
3455 }
3456 }
3457 break;
3458 case twoDimVertR2:
3459 this._addPixels(refLine[refPos] + 2, blackPixels);
3460 blackPixels ^= 1;
3461 if (codingLine[this.codingPos] < columns) {
3462 ++refPos;
3463 while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
3464 refPos += 2;
3465 }
3466 }
3467 break;
3468 case twoDimVertR1:
3469 this._addPixels(refLine[refPos] + 1, blackPixels);
3470 blackPixels ^= 1;
3471 if (codingLine[this.codingPos] < columns) {
3472 ++refPos;
3473 while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
3474 refPos += 2;
3475 }
3476 }
3477 break;
3478 case twoDimVert0:
3479 this._addPixels(refLine[refPos], blackPixels);
3480 blackPixels ^= 1;
3481 if (codingLine[this.codingPos] < columns) {
3482 ++refPos;
3483 while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
3484 refPos += 2;
3485 }
3486 }
3487 break;
3488 case twoDimVertL3:
3489 this._addPixelsNeg(refLine[refPos] - 3, blackPixels);
3490 blackPixels ^= 1;
3491 if (codingLine[this.codingPos] < columns) {
3492 if (refPos > 0) {
3493 --refPos;
3494 } else {
3495 ++refPos;
3496 }
3497 while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
3498 refPos += 2;
3499 }
3500 }
3501 break;
3502 case twoDimVertL2:
3503 this._addPixelsNeg(refLine[refPos] - 2, blackPixels);
3504 blackPixels ^= 1;
3505 if (codingLine[this.codingPos] < columns) {
3506 if (refPos > 0) {
3507 --refPos;
3508 } else {
3509 ++refPos;
3510 }
3511 while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
3512 refPos += 2;
3513 }
3514 }
3515 break;
3516 case twoDimVertL1:
3517 this._addPixelsNeg(refLine[refPos] - 1, blackPixels);
3518 blackPixels ^= 1;
3519 if (codingLine[this.codingPos] < columns) {
3520 if (refPos > 0) {
3521 --refPos;
3522 } else {
3523 ++refPos;
3524 }
3525 while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
3526 refPos += 2;
3527 }
3528 }
3529 break;
3530 case ccittEOF:
3531 this._addPixels(columns, 0);
3532 this.eof = true;
3533 break;
3534 default:
3535 info("bad 2d code");
3536 this._addPixels(columns, 0);
3537 this.err = true;
3538 }
3539 }
3540 } else {
3541 codingLine[0] = 0;
3542 this.codingPos = 0;
3543 blackPixels = 0;
3544 while (codingLine[this.codingPos] < columns) {
3545 code1 = 0;
3546 if (blackPixels) {
3547 do {
3548 code1 += code3 = this._getBlackCode();
3549 } while (code3 >= 64);
3550 } else {
3551 do {
3552 code1 += code3 = this._getWhiteCode();
3553 } while (code3 >= 64);
3554 }
3555 this._addPixels(codingLine[this.codingPos] + code1, blackPixels);
3556 blackPixels ^= 1;
3557 }
3558 }
3559 let gotEOL = false;
3560 if (this.byteAlign) {
3561 this.inputBits &= ~7;
3562 }
3563 if (!this.eoblock && this.row === this.rows - 1) {
3564 this.rowsDone = true;
3565 } else {
3566 code1 = this._lookBits(12);
3567 if (this.eoline) {
3568 while (code1 !== ccittEOF && code1 !== 1) {
3569 this._eatBits(1);
3570 code1 = this._lookBits(12);
3571 }
3572 } else {
3573 while (code1 === 0) {
3574 this._eatBits(1);
3575 code1 = this._lookBits(12);
3576 }
3577 }
3578 if (code1 === 1) {
3579 this._eatBits(12);
3580 gotEOL = true;
3581 } else if (code1 === ccittEOF) {
3582 this.eof = true;
3583 }
3584 }
3585 if (!this.eof && this.encoding > 0 && !this.rowsDone) {
3586 this.nextLine2D = !this._lookBits(1);
3587 this._eatBits(1);
3588 }
3589 if (this.eoblock && gotEOL && this.byteAlign) {
3590 code1 = this._lookBits(12);
3591 if (code1 === 1) {
3592 this._eatBits(12);
3593 if (this.encoding > 0) {
3594 this._lookBits(1);
3595 this._eatBits(1);
3596 }
3597 if (this.encoding >= 0) {
3598 for (i = 0; i < 4; ++i) {
3599 code1 = this._lookBits(12);
3600 if (code1 !== 1) {
3601 info("bad rtc code: " + code1);
3602 }
3603 this._eatBits(12);
3604 if (this.encoding > 0) {
3605 this._lookBits(1);
3606 this._eatBits(1);
3607 }
3608 }
3609 }
3610 this.eof = true;
3611 }
3612 } else if (this.err && this.eoline) {
3613 while (true) {
3614 code1 = this._lookBits(13);
3615 if (code1 === ccittEOF) {
3616 this.eof = true;
3617 return -1;
3618 }
3619 if (code1 >> 1 === 1) {
3620 break;
3621 }
3622 this._eatBits(1);
3623 }
3624 this._eatBits(12);
3625 if (this.encoding > 0) {
3626 this._eatBits(1);
3627 this.nextLine2D = !(code1 & 1);
3628 }
3629 }
3630 this.outputBits = codingLine[0] > 0 ? codingLine[this.codingPos = 0] : codingLine[this.codingPos = 1];
3631 this.row++;
3632 }
3633 let c;
3634 if (this.outputBits >= 8) {
3635 c = this.codingPos & 1 ? 0 : 0xff;
3636 this.outputBits -= 8;
3637 if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
3638 this.codingPos++;
3639 this.outputBits = codingLine[this.codingPos] - codingLine[this.codingPos - 1];
3640 }
3641 } else {
3642 bits = 8;
3643 c = 0;
3644 do {
3645 if (typeof this.outputBits !== "number") {
3646 throw new FormatError('Invalid /CCITTFaxDecode data, "outputBits" must be a number.');
3647 }
3648 if (this.outputBits > bits) {
3649 c <<= bits;
3650 if (!(this.codingPos & 1)) {
3651 c |= 0xff >> 8 - bits;
3652 }
3653 this.outputBits -= bits;
3654 bits = 0;
3655 } else {
3656 c <<= this.outputBits;
3657 if (!(this.codingPos & 1)) {
3658 c |= 0xff >> 8 - this.outputBits;
3659 }
3660 bits -= this.outputBits;
3661 this.outputBits = 0;
3662 if (codingLine[this.codingPos] < columns) {
3663 this.codingPos++;
3664 this.outputBits = codingLine[this.codingPos] - codingLine[this.codingPos - 1];
3665 } else if (bits > 0) {
3666 c <<= bits;
3667 bits = 0;
3668 }
3669 }
3670 } while (bits);
3671 }
3672 if (this.black) {
3673 c ^= 0xff;
3674 }
3675 return c;
3676 }
3677 _addPixels(a1, blackPixels) {
3678 const codingLine = this.codingLine;
3679 let codingPos = this.codingPos;
3680 if (a1 > codingLine[codingPos]) {
3681 if (a1 > this.columns) {
3682 info("row is wrong length");
3683 this.err = true;
3684 a1 = this.columns;
3685 }
3686 if (codingPos & 1 ^ blackPixels) {
3687 ++codingPos;
3688 }
3689 codingLine[codingPos] = a1;
3690 }
3691 this.codingPos = codingPos;
3692 }
3693 _addPixelsNeg(a1, blackPixels) {
3694 const codingLine = this.codingLine;
3695 let codingPos = this.codingPos;
3696 if (a1 > codingLine[codingPos]) {
3697 if (a1 > this.columns) {
3698 info("row is wrong length");
3699 this.err = true;
3700 a1 = this.columns;
3701 }
3702 if (codingPos & 1 ^ blackPixels) {
3703 ++codingPos;
3704 }
3705 codingLine[codingPos] = a1;
3706 } else if (a1 < codingLine[codingPos]) {
3707 if (a1 < 0) {
3708 info("invalid code");
3709 this.err = true;
3710 a1 = 0;
3711 }
3712 while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
3713 --codingPos;
3714 }
3715 codingLine[codingPos] = a1;
3716 }
3717 this.codingPos = codingPos;
3718 }
3719 _findTableCode(start, end, table, limit) {
3720 const limitValue = limit || 0;
3721 for (let i = start; i <= end; ++i) {
3722 let code = this._lookBits(i);
3723 if (code === ccittEOF) {
3724 return [true, 1, false];
3725 }
3726 if (i < end) {
3727 code <<= end - i;
3728 }
3729 if (!limitValue || code >= limitValue) {
3730 const p = table[code - limitValue];
3731 if (p[0] === i) {
3732 this._eatBits(i);
3733 return [true, p[1], true];
3734 }
3735 }
3736 }
3737 return [false, 0, false];
3738 }
3739 _getTwoDimCode() {
3740 let code = 0;
3741 let p;
3742 if (this.eoblock) {
3743 code = this._lookBits(7);
3744 p = twoDimTable[code];
3745 if (p?.[0] > 0) {
3746 this._eatBits(p[0]);
3747 return p[1];
3748 }
3749 } else {
3750 const result = this._findTableCode(1, 7, twoDimTable);
3751 if (result[0] && result[2]) {
3752 return result[1];
3753 }
3754 }
3755 info("Bad two dim code");
3756 return ccittEOF;
3757 }
3758 _getWhiteCode() {
3759 let code = 0;
3760 let p;
3761 if (this.eoblock) {
3762 code = this._lookBits(12);
3763 if (code === ccittEOF) {
3764 return 1;
3765 }
3766 p = code >> 5 === 0 ? whiteTable1[code] : whiteTable2[code >> 3];
3767 if (p[0] > 0) {
3768 this._eatBits(p[0]);
3769 return p[1];
3770 }
3771 } else {
3772 let result = this._findTableCode(1, 9, whiteTable2);
3773 if (result[0]) {
3774 return result[1];
3775 }
3776 result = this._findTableCode(11, 12, whiteTable1);
3777 if (result[0]) {
3778 return result[1];
3779 }
3780 }
3781 info("bad white code");
3782 this._eatBits(1);
3783 return 1;
3784 }
3785 _getBlackCode() {
3786 let code, p;
3787 if (this.eoblock) {
3788 code = this._lookBits(13);
3789 if (code === ccittEOF) {
3790 return 1;
3791 }
3792 if (code >> 7 === 0) {
3793 p = blackTable1[code];
3794 } else if (code >> 9 === 0 && code >> 7 !== 0) {
3795 p = blackTable2[(code >> 1) - 64];
3796 } else {
3797 p = blackTable3[code >> 7];
3798 }
3799 if (p[0] > 0) {
3800 this._eatBits(p[0]);
3801 return p[1];
3802 }
3803 } else {
3804 let result = this._findTableCode(2, 6, blackTable3);
3805 if (result[0]) {
3806 return result[1];
3807 }
3808 result = this._findTableCode(7, 12, blackTable2, 64);
3809 if (result[0]) {
3810 return result[1];
3811 }
3812 result = this._findTableCode(10, 13, blackTable1);
3813 if (result[0]) {
3814 return result[1];
3815 }
3816 }
3817 info("bad black code");
3818 this._eatBits(1);
3819 return 1;
3820 }
3821 _lookBits(n) {
3822 let c;
3823 while (this.inputBits < n) {
3824 if ((c = this.source.next()) === -1) {
3825 if (this.inputBits === 0) {
3826 return ccittEOF;
3827 }
3828 return this.inputBuf << n - this.inputBits & 0xffff >> 16 - n;
3829 }
3830 this.inputBuf = this.inputBuf << 8 | c;
3831 this.inputBits += 8;
3832 }
3833 return this.inputBuf >> this.inputBits - n & 0xffff >> 16 - n;
3834 }
3835 _eatBits(n) {
3836 if ((this.inputBits -= n) < 0) {
3837 this.inputBits = 0;
3838 }
3839 }
3840}
3841
3842;// CONCATENATED MODULE: ./src/core/ccitt_stream.js
3843
3844
3845
3846class CCITTFaxStream extends DecodeStream {
3847 constructor(str, maybeLength, params) {
3848 super(maybeLength);
3849 this.str = str;
3850 this.dict = str.dict;
3851 if (!(params instanceof Dict)) {
3852 params = Dict.empty;
3853 }
3854 const source = {
3855 next() {
3856 return str.getByte();
3857 }
3858 };
3859 this.ccittFaxDecoder = new CCITTFaxDecoder(source, {
3860 K: params.get("K"),
3861 EndOfLine: params.get("EndOfLine"),
3862 EncodedByteAlign: params.get("EncodedByteAlign"),
3863 Columns: params.get("Columns"),
3864 Rows: params.get("Rows"),
3865 EndOfBlock: params.get("EndOfBlock"),
3866 BlackIs1: params.get("BlackIs1")
3867 });
3868 }
3869 readBlock() {
3870 while (!this.eof) {
3871 const c = this.ccittFaxDecoder.readNextChar();
3872 if (c === -1) {
3873 this.eof = true;
3874 return;
3875 }
3876 this.ensureBuffer(this.bufferLength + 1);
3877 this.buffer[this.bufferLength++] = c;
3878 }
3879 }
3880}
3881
3882;// CONCATENATED MODULE: ./src/core/flate_stream.js
3883
3884
3885const codeLenCodeMap = new Int32Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]);
3886const 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]);
3887const 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]);
3888const 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];
3889const 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];
3890class FlateStream extends DecodeStream {
3891 constructor(str, maybeLength) {
3892 super(maybeLength);
3893 this.str = str;
3894 this.dict = str.dict;
3895 const cmf = str.getByte();
3896 const flg = str.getByte();
3897 if (cmf === -1 || flg === -1) {
3898 throw new FormatError(`Invalid header in flate stream: ${cmf}, ${flg}`);
3899 }
3900 if ((cmf & 0x0f) !== 0x08) {
3901 throw new FormatError(`Unknown compression method in flate stream: ${cmf}, ${flg}`);
3902 }
3903 if (((cmf << 8) + flg) % 31 !== 0) {
3904 throw new FormatError(`Bad FCHECK in flate stream: ${cmf}, ${flg}`);
3905 }
3906 if (flg & 0x20) {
3907 throw new FormatError(`FDICT bit set in flate stream: ${cmf}, ${flg}`);
3908 }
3909 this.codeSize = 0;
3910 this.codeBuf = 0;
3911 }
3912 getBits(bits) {
3913 const str = this.str;
3914 let codeSize = this.codeSize;
3915 let codeBuf = this.codeBuf;
3916 let b;
3917 while (codeSize < bits) {
3918 if ((b = str.getByte()) === -1) {
3919 throw new FormatError("Bad encoding in flate stream");
3920 }
3921 codeBuf |= b << codeSize;
3922 codeSize += 8;
3923 }
3924 b = codeBuf & (1 << bits) - 1;
3925 this.codeBuf = codeBuf >> bits;
3926 this.codeSize = codeSize -= bits;
3927 return b;
3928 }
3929 getCode(table) {
3930 const str = this.str;
3931 const codes = table[0];
3932 const maxLen = table[1];
3933 let codeSize = this.codeSize;
3934 let codeBuf = this.codeBuf;
3935 let b;
3936 while (codeSize < maxLen) {
3937 if ((b = str.getByte()) === -1) {
3938 break;
3939 }
3940 codeBuf |= b << codeSize;
3941 codeSize += 8;
3942 }
3943 const code = codes[codeBuf & (1 << maxLen) - 1];
3944 const codeLen = code >> 16;
3945 const codeVal = code & 0xffff;
3946 if (codeLen < 1 || codeSize < codeLen) {
3947 throw new FormatError("Bad encoding in flate stream");
3948 }
3949 this.codeBuf = codeBuf >> codeLen;
3950 this.codeSize = codeSize - codeLen;
3951 return codeVal;
3952 }
3953 generateHuffmanTable(lengths) {
3954 const n = lengths.length;
3955 let maxLen = 0;
3956 let i;
3957 for (i = 0; i < n; ++i) {
3958 if (lengths[i] > maxLen) {
3959 maxLen = lengths[i];
3960 }
3961 }
3962 const size = 1 << maxLen;
3963 const codes = new Int32Array(size);
3964 for (let len = 1, code = 0, skip = 2; len <= maxLen; ++len, code <<= 1, skip <<= 1) {
3965 for (let val = 0; val < n; ++val) {
3966 if (lengths[val] === len) {
3967 let code2 = 0;
3968 let t = code;
3969 for (i = 0; i < len; ++i) {
3970 code2 = code2 << 1 | t & 1;
3971 t >>= 1;
3972 }
3973 for (i = code2; i < size; i += skip) {
3974 codes[i] = len << 16 | val;
3975 }
3976 ++code;
3977 }
3978 }
3979 }
3980 return [codes, maxLen];
3981 }
3982 #endsStreamOnError(err) {
3983 info(err);
3984 this.eof = true;
3985 }
3986 readBlock() {
3987 let buffer, len;
3988 const str = this.str;
3989 let hdr = this.getBits(3);
3990 if (hdr & 1) {
3991 this.eof = true;
3992 }
3993 hdr >>= 1;
3994 if (hdr === 0) {
3995 let b;
3996 if ((b = str.getByte()) === -1) {
3997 this.#endsStreamOnError("Bad block header in flate stream");
3998 return;
3999 }
4000 let blockLen = b;
4001 if ((b = str.getByte()) === -1) {
4002 this.#endsStreamOnError("Bad block header in flate stream");
4003 return;
4004 }
4005 blockLen |= b << 8;
4006 if ((b = str.getByte()) === -1) {
4007 this.#endsStreamOnError("Bad block header in flate stream");
4008 return;
4009 }
4010 let check = b;
4011 if ((b = str.getByte()) === -1) {
4012 this.#endsStreamOnError("Bad block header in flate stream");
4013 return;
4014 }
4015 check |= b << 8;
4016 if (check !== (~blockLen & 0xffff) && (blockLen !== 0 || check !== 0)) {
4017 throw new FormatError("Bad uncompressed block length in flate stream");
4018 }
4019 this.codeBuf = 0;
4020 this.codeSize = 0;
4021 const bufferLength = this.bufferLength,
4022 end = bufferLength + blockLen;
4023 buffer = this.ensureBuffer(end);
4024 this.bufferLength = end;
4025 if (blockLen === 0) {
4026 if (str.peekByte() === -1) {
4027 this.eof = true;
4028 }
4029 } else {
4030 const block = str.getBytes(blockLen);
4031 buffer.set(block, bufferLength);
4032 if (block.length < blockLen) {
4033 this.eof = true;
4034 }
4035 }
4036 return;
4037 }
4038 let litCodeTable;
4039 let distCodeTable;
4040 if (hdr === 1) {
4041 litCodeTable = fixedLitCodeTab;
4042 distCodeTable = fixedDistCodeTab;
4043 } else if (hdr === 2) {
4044 const numLitCodes = this.getBits(5) + 257;
4045 const numDistCodes = this.getBits(5) + 1;
4046 const numCodeLenCodes = this.getBits(4) + 4;
4047 const codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
4048 let i;
4049 for (i = 0; i < numCodeLenCodes; ++i) {
4050 codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
4051 }
4052 const codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
4053 len = 0;
4054 i = 0;
4055 const codes = numLitCodes + numDistCodes;
4056 const codeLengths = new Uint8Array(codes);
4057 let bitsLength, bitsOffset, what;
4058 while (i < codes) {
4059 const code = this.getCode(codeLenCodeTab);
4060 if (code === 16) {
4061 bitsLength = 2;
4062 bitsOffset = 3;
4063 what = len;
4064 } else if (code === 17) {
4065 bitsLength = 3;
4066 bitsOffset = 3;
4067 what = len = 0;
4068 } else if (code === 18) {
4069 bitsLength = 7;
4070 bitsOffset = 11;
4071 what = len = 0;
4072 } else {
4073 codeLengths[i++] = len = code;
4074 continue;
4075 }
4076 let repeatLength = this.getBits(bitsLength) + bitsOffset;
4077 while (repeatLength-- > 0) {
4078 codeLengths[i++] = what;
4079 }
4080 }
4081 litCodeTable = this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
4082 distCodeTable = this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
4083 } else {
4084 throw new FormatError("Unknown block type in flate stream");
4085 }
4086 buffer = this.buffer;
4087 let limit = buffer ? buffer.length : 0;
4088 let pos = this.bufferLength;
4089 while (true) {
4090 let code1 = this.getCode(litCodeTable);
4091 if (code1 < 256) {
4092 if (pos + 1 >= limit) {
4093 buffer = this.ensureBuffer(pos + 1);
4094 limit = buffer.length;
4095 }
4096 buffer[pos++] = code1;
4097 continue;
4098 }
4099 if (code1 === 256) {
4100 this.bufferLength = pos;
4101 return;
4102 }
4103 code1 -= 257;
4104 code1 = lengthDecode[code1];
4105 let code2 = code1 >> 16;
4106 if (code2 > 0) {
4107 code2 = this.getBits(code2);
4108 }
4109 len = (code1 & 0xffff) + code2;
4110 code1 = this.getCode(distCodeTable);
4111 code1 = distDecode[code1];
4112 code2 = code1 >> 16;
4113 if (code2 > 0) {
4114 code2 = this.getBits(code2);
4115 }
4116 const dist = (code1 & 0xffff) + code2;
4117 if (pos + len >= limit) {
4118 buffer = this.ensureBuffer(pos + len);
4119 limit = buffer.length;
4120 }
4121 for (let k = 0; k < len; ++k, ++pos) {
4122 buffer[pos] = buffer[pos - dist];
4123 }
4124 }
4125 }
4126}
4127
4128;// CONCATENATED MODULE: ./src/core/arithmetic_decoder.js
4129const QeTable = [{
4130 qe: 0x5601,
4131 nmps: 1,
4132 nlps: 1,
4133 switchFlag: 1
4134}, {
4135 qe: 0x3401,
4136 nmps: 2,
4137 nlps: 6,
4138 switchFlag: 0
4139}, {
4140 qe: 0x1801,
4141 nmps: 3,
4142 nlps: 9,
4143 switchFlag: 0
4144}, {
4145 qe: 0x0ac1,
4146 nmps: 4,
4147 nlps: 12,
4148 switchFlag: 0
4149}, {
4150 qe: 0x0521,
4151 nmps: 5,
4152 nlps: 29,
4153 switchFlag: 0
4154}, {
4155 qe: 0x0221,
4156 nmps: 38,
4157 nlps: 33,
4158 switchFlag: 0
4159}, {
4160 qe: 0x5601,
4161 nmps: 7,
4162 nlps: 6,
4163 switchFlag: 1
4164}, {
4165 qe: 0x5401,
4166 nmps: 8,
4167 nlps: 14,
4168 switchFlag: 0
4169}, {
4170 qe: 0x4801,
4171 nmps: 9,
4172 nlps: 14,
4173 switchFlag: 0
4174}, {
4175 qe: 0x3801,
4176 nmps: 10,
4177 nlps: 14,
4178 switchFlag: 0
4179}, {
4180 qe: 0x3001,
4181 nmps: 11,
4182 nlps: 17,
4183 switchFlag: 0
4184}, {
4185 qe: 0x2401,
4186 nmps: 12,
4187 nlps: 18,
4188 switchFlag: 0
4189}, {
4190 qe: 0x1c01,
4191 nmps: 13,
4192 nlps: 20,
4193 switchFlag: 0
4194}, {
4195 qe: 0x1601,
4196 nmps: 29,
4197 nlps: 21,
4198 switchFlag: 0
4199}, {
4200 qe: 0x5601,
4201 nmps: 15,
4202 nlps: 14,
4203 switchFlag: 1
4204}, {
4205 qe: 0x5401,
4206 nmps: 16,
4207 nlps: 14,
4208 switchFlag: 0
4209}, {
4210 qe: 0x5101,
4211 nmps: 17,
4212 nlps: 15,
4213 switchFlag: 0
4214}, {
4215 qe: 0x4801,
4216 nmps: 18,
4217 nlps: 16,
4218 switchFlag: 0
4219}, {
4220 qe: 0x3801,
4221 nmps: 19,
4222 nlps: 17,
4223 switchFlag: 0
4224}, {
4225 qe: 0x3401,
4226 nmps: 20,
4227 nlps: 18,
4228 switchFlag: 0
4229}, {
4230 qe: 0x3001,
4231 nmps: 21,
4232 nlps: 19,
4233 switchFlag: 0
4234}, {
4235 qe: 0x2801,
4236 nmps: 22,
4237 nlps: 19,
4238 switchFlag: 0
4239}, {
4240 qe: 0x2401,
4241 nmps: 23,
4242 nlps: 20,
4243 switchFlag: 0
4244}, {
4245 qe: 0x2201,
4246 nmps: 24,
4247 nlps: 21,
4248 switchFlag: 0
4249}, {
4250 qe: 0x1c01,
4251 nmps: 25,
4252 nlps: 22,
4253 switchFlag: 0
4254}, {
4255 qe: 0x1801,
4256 nmps: 26,
4257 nlps: 23,
4258 switchFlag: 0
4259}, {
4260 qe: 0x1601,
4261 nmps: 27,
4262 nlps: 24,
4263 switchFlag: 0
4264}, {
4265 qe: 0x1401,
4266 nmps: 28,
4267 nlps: 25,
4268 switchFlag: 0
4269}, {
4270 qe: 0x1201,
4271 nmps: 29,
4272 nlps: 26,
4273 switchFlag: 0
4274}, {
4275 qe: 0x1101,
4276 nmps: 30,
4277 nlps: 27,
4278 switchFlag: 0
4279}, {
4280 qe: 0x0ac1,
4281 nmps: 31,
4282 nlps: 28,
4283 switchFlag: 0
4284}, {
4285 qe: 0x09c1,
4286 nmps: 32,
4287 nlps: 29,
4288 switchFlag: 0
4289}, {
4290 qe: 0x08a1,
4291 nmps: 33,
4292 nlps: 30,
4293 switchFlag: 0
4294}, {
4295 qe: 0x0521,
4296 nmps: 34,
4297 nlps: 31,
4298 switchFlag: 0
4299}, {
4300 qe: 0x0441,
4301 nmps: 35,
4302 nlps: 32,
4303 switchFlag: 0
4304}, {
4305 qe: 0x02a1,
4306 nmps: 36,
4307 nlps: 33,
4308 switchFlag: 0
4309}, {
4310 qe: 0x0221,
4311 nmps: 37,
4312 nlps: 34,
4313 switchFlag: 0
4314}, {
4315 qe: 0x0141,
4316 nmps: 38,
4317 nlps: 35,
4318 switchFlag: 0
4319}, {
4320 qe: 0x0111,
4321 nmps: 39,
4322 nlps: 36,
4323 switchFlag: 0
4324}, {
4325 qe: 0x0085,
4326 nmps: 40,
4327 nlps: 37,
4328 switchFlag: 0
4329}, {
4330 qe: 0x0049,
4331 nmps: 41,
4332 nlps: 38,
4333 switchFlag: 0
4334}, {
4335 qe: 0x0025,
4336 nmps: 42,
4337 nlps: 39,
4338 switchFlag: 0
4339}, {
4340 qe: 0x0015,
4341 nmps: 43,
4342 nlps: 40,
4343 switchFlag: 0
4344}, {
4345 qe: 0x0009,
4346 nmps: 44,
4347 nlps: 41,
4348 switchFlag: 0
4349}, {
4350 qe: 0x0005,
4351 nmps: 45,
4352 nlps: 42,
4353 switchFlag: 0
4354}, {
4355 qe: 0x0001,
4356 nmps: 45,
4357 nlps: 43,
4358 switchFlag: 0
4359}, {
4360 qe: 0x5601,
4361 nmps: 46,
4362 nlps: 46,
4363 switchFlag: 0
4364}];
4365class ArithmeticDecoder {
4366 constructor(data, start, end) {
4367 this.data = data;
4368 this.bp = start;
4369 this.dataEnd = end;
4370 this.chigh = data[start];
4371 this.clow = 0;
4372 this.byteIn();
4373 this.chigh = this.chigh << 7 & 0xffff | this.clow >> 9 & 0x7f;
4374 this.clow = this.clow << 7 & 0xffff;
4375 this.ct -= 7;
4376 this.a = 0x8000;
4377 }
4378 byteIn() {
4379 const data = this.data;
4380 let bp = this.bp;
4381 if (data[bp] === 0xff) {
4382 if (data[bp + 1] > 0x8f) {
4383 this.clow += 0xff00;
4384 this.ct = 8;
4385 } else {
4386 bp++;
4387 this.clow += data[bp] << 9;
4388 this.ct = 7;
4389 this.bp = bp;
4390 }
4391 } else {
4392 bp++;
4393 this.clow += bp < this.dataEnd ? data[bp] << 8 : 0xff00;
4394 this.ct = 8;
4395 this.bp = bp;
4396 }
4397 if (this.clow > 0xffff) {
4398 this.chigh += this.clow >> 16;
4399 this.clow &= 0xffff;
4400 }
4401 }
4402 readBit(contexts, pos) {
4403 let cx_index = contexts[pos] >> 1,
4404 cx_mps = contexts[pos] & 1;
4405 const qeTableIcx = QeTable[cx_index];
4406 const qeIcx = qeTableIcx.qe;
4407 let d;
4408 let a = this.a - qeIcx;
4409 if (this.chigh < qeIcx) {
4410 if (a < qeIcx) {
4411 a = qeIcx;
4412 d = cx_mps;
4413 cx_index = qeTableIcx.nmps;
4414 } else {
4415 a = qeIcx;
4416 d = 1 ^ cx_mps;
4417 if (qeTableIcx.switchFlag === 1) {
4418 cx_mps = d;
4419 }
4420 cx_index = qeTableIcx.nlps;
4421 }
4422 } else {
4423 this.chigh -= qeIcx;
4424 if ((a & 0x8000) !== 0) {
4425 this.a = a;
4426 return cx_mps;
4427 }
4428 if (a < qeIcx) {
4429 d = 1 ^ cx_mps;
4430 if (qeTableIcx.switchFlag === 1) {
4431 cx_mps = d;
4432 }
4433 cx_index = qeTableIcx.nlps;
4434 } else {
4435 d = cx_mps;
4436 cx_index = qeTableIcx.nmps;
4437 }
4438 }
4439 do {
4440 if (this.ct === 0) {
4441 this.byteIn();
4442 }
4443 a <<= 1;
4444 this.chigh = this.chigh << 1 & 0xffff | this.clow >> 15 & 1;
4445 this.clow = this.clow << 1 & 0xffff;
4446 this.ct--;
4447 } while ((a & 0x8000) === 0);
4448 this.a = a;
4449 contexts[pos] = cx_index << 1 | cx_mps;
4450 return d;
4451 }
4452}
4453
4454;// CONCATENATED MODULE: ./src/core/jbig2.js
4455
4456
4457
4458
4459class Jbig2Error extends BaseException {
4460 constructor(msg) {
4461 super(`JBIG2 error: ${msg}`, "Jbig2Error");
4462 }
4463}
4464class ContextCache {
4465 getContexts(id) {
4466 if (id in this) {
4467 return this[id];
4468 }
4469 return this[id] = new Int8Array(1 << 16);
4470 }
4471}
4472class DecodingContext {
4473 constructor(data, start, end) {
4474 this.data = data;
4475 this.start = start;
4476 this.end = end;
4477 }
4478 get decoder() {
4479 const decoder = new ArithmeticDecoder(this.data, this.start, this.end);
4480 return shadow(this, "decoder", decoder);
4481 }
4482 get contextCache() {
4483 const cache = new ContextCache();
4484 return shadow(this, "contextCache", cache);
4485 }
4486}
4487const MAX_INT_32 = 2 ** 31 - 1;
4488const MIN_INT_32 = -(2 ** 31);
4489function decodeInteger(contextCache, procedure, decoder) {
4490 const contexts = contextCache.getContexts(procedure);
4491 let prev = 1;
4492 function readBits(length) {
4493 let v = 0;
4494 for (let i = 0; i < length; i++) {
4495 const bit = decoder.readBit(contexts, prev);
4496 prev = prev < 256 ? prev << 1 | bit : (prev << 1 | bit) & 511 | 256;
4497 v = v << 1 | bit;
4498 }
4499 return v >>> 0;
4500 }
4501 const sign = readBits(1);
4502 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);
4503 let signedValue;
4504 if (sign === 0) {
4505 signedValue = value;
4506 } else if (value > 0) {
4507 signedValue = -value;
4508 }
4509 if (signedValue >= MIN_INT_32 && signedValue <= MAX_INT_32) {
4510 return signedValue;
4511 }
4512 return null;
4513}
4514function decodeIAID(contextCache, decoder, codeLength) {
4515 const contexts = contextCache.getContexts("IAID");
4516 let prev = 1;
4517 for (let i = 0; i < codeLength; i++) {
4518 const bit = decoder.readBit(contexts, prev);
4519 prev = prev << 1 | bit;
4520 }
4521 if (codeLength < 31) {
4522 return prev & (1 << codeLength) - 1;
4523 }
4524 return prev & 0x7fffffff;
4525}
4526const 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"];
4527const CodingTemplates = [[{
4528 x: -1,
4529 y: -2
4530}, {
4531 x: 0,
4532 y: -2
4533}, {
4534 x: 1,
4535 y: -2
4536}, {
4537 x: -2,
4538 y: -1
4539}, {
4540 x: -1,
4541 y: -1
4542}, {
4543 x: 0,
4544 y: -1
4545}, {
4546 x: 1,
4547 y: -1
4548}, {
4549 x: 2,
4550 y: -1
4551}, {
4552 x: -4,
4553 y: 0
4554}, {
4555 x: -3,
4556 y: 0
4557}, {
4558 x: -2,
4559 y: 0
4560}, {
4561 x: -1,
4562 y: 0
4563}], [{
4564 x: -1,
4565 y: -2
4566}, {
4567 x: 0,
4568 y: -2
4569}, {
4570 x: 1,
4571 y: -2
4572}, {
4573 x: 2,
4574 y: -2
4575}, {
4576 x: -2,
4577 y: -1
4578}, {
4579 x: -1,
4580 y: -1
4581}, {
4582 x: 0,
4583 y: -1
4584}, {
4585 x: 1,
4586 y: -1
4587}, {
4588 x: 2,
4589 y: -1
4590}, {
4591 x: -3,
4592 y: 0
4593}, {
4594 x: -2,
4595 y: 0
4596}, {
4597 x: -1,
4598 y: 0
4599}], [{
4600 x: -1,
4601 y: -2
4602}, {
4603 x: 0,
4604 y: -2
4605}, {
4606 x: 1,
4607 y: -2
4608}, {
4609 x: -2,
4610 y: -1
4611}, {
4612 x: -1,
4613 y: -1
4614}, {
4615 x: 0,
4616 y: -1
4617}, {
4618 x: 1,
4619 y: -1
4620}, {
4621 x: -2,
4622 y: 0
4623}, {
4624 x: -1,
4625 y: 0
4626}], [{
4627 x: -3,
4628 y: -1
4629}, {
4630 x: -2,
4631 y: -1
4632}, {
4633 x: -1,
4634 y: -1
4635}, {
4636 x: 0,
4637 y: -1
4638}, {
4639 x: 1,
4640 y: -1
4641}, {
4642 x: -4,
4643 y: 0
4644}, {
4645 x: -3,
4646 y: 0
4647}, {
4648 x: -2,
4649 y: 0
4650}, {
4651 x: -1,
4652 y: 0
4653}]];
4654const RefinementTemplates = [{
4655 coding: [{
4656 x: 0,
4657 y: -1
4658 }, {
4659 x: 1,
4660 y: -1
4661 }, {
4662 x: -1,
4663 y: 0
4664 }],
4665 reference: [{
4666 x: 0,
4667 y: -1
4668 }, {
4669 x: 1,
4670 y: -1
4671 }, {
4672 x: -1,
4673 y: 0
4674 }, {
4675 x: 0,
4676 y: 0
4677 }, {
4678 x: 1,
4679 y: 0
4680 }, {
4681 x: -1,
4682 y: 1
4683 }, {
4684 x: 0,
4685 y: 1
4686 }, {
4687 x: 1,
4688 y: 1
4689 }]
4690}, {
4691 coding: [{
4692 x: -1,
4693 y: -1
4694 }, {
4695 x: 0,
4696 y: -1
4697 }, {
4698 x: 1,
4699 y: -1
4700 }, {
4701 x: -1,
4702 y: 0
4703 }],
4704 reference: [{
4705 x: 0,
4706 y: -1
4707 }, {
4708 x: -1,
4709 y: 0
4710 }, {
4711 x: 0,
4712 y: 0
4713 }, {
4714 x: 1,
4715 y: 0
4716 }, {
4717 x: 0,
4718 y: 1
4719 }, {
4720 x: 1,
4721 y: 1
4722 }]
4723}];
4724const ReusedContexts = [0x9b25, 0x0795, 0x00e5, 0x0195];
4725const RefinementReusedContexts = [0x0020, 0x0008];
4726function decodeBitmapTemplate0(width, height, decodingContext) {
4727 const decoder = decodingContext.decoder;
4728 const contexts = decodingContext.contextCache.getContexts("GB");
4729 const bitmap = [];
4730 let contextLabel, i, j, pixel, row, row1, row2;
4731 const OLD_PIXEL_MASK = 0x7bf7;
4732 for (i = 0; i < height; i++) {
4733 row = bitmap[i] = new Uint8Array(width);
4734 row1 = i < 1 ? row : bitmap[i - 1];
4735 row2 = i < 2 ? row : bitmap[i - 2];
4736 contextLabel = row2[0] << 13 | row2[1] << 12 | row2[2] << 11 | row1[0] << 7 | row1[1] << 6 | row1[2] << 5 | row1[3] << 4;
4737 for (j = 0; j < width; j++) {
4738 row[j] = pixel = decoder.readBit(contexts, contextLabel);
4739 contextLabel = (contextLabel & OLD_PIXEL_MASK) << 1 | (j + 3 < width ? row2[j + 3] << 11 : 0) | (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
4740 }
4741 }
4742 return bitmap;
4743}
4744function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at, decodingContext) {
4745 if (mmr) {
4746 const input = new Reader(decodingContext.data, decodingContext.start, decodingContext.end);
4747 return decodeMMRBitmap(input, width, height, false);
4748 }
4749 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) {
4750 return decodeBitmapTemplate0(width, height, decodingContext);
4751 }
4752 const useskip = !!skip;
4753 const template = CodingTemplates[templateIndex].concat(at);
4754 template.sort(function (a, b) {
4755 return a.y - b.y || a.x - b.x;
4756 });
4757 const templateLength = template.length;
4758 const templateX = new Int8Array(templateLength);
4759 const templateY = new Int8Array(templateLength);
4760 const changingTemplateEntries = [];
4761 let reuseMask = 0,
4762 minX = 0,
4763 maxX = 0,
4764 minY = 0;
4765 let c, k;
4766 for (k = 0; k < templateLength; k++) {
4767 templateX[k] = template[k].x;
4768 templateY[k] = template[k].y;
4769 minX = Math.min(minX, template[k].x);
4770 maxX = Math.max(maxX, template[k].x);
4771 minY = Math.min(minY, template[k].y);
4772 if (k < templateLength - 1 && template[k].y === template[k + 1].y && template[k].x === template[k + 1].x - 1) {
4773 reuseMask |= 1 << templateLength - 1 - k;
4774 } else {
4775 changingTemplateEntries.push(k);
4776 }
4777 }
4778 const changingEntriesLength = changingTemplateEntries.length;
4779 const changingTemplateX = new Int8Array(changingEntriesLength);
4780 const changingTemplateY = new Int8Array(changingEntriesLength);
4781 const changingTemplateBit = new Uint16Array(changingEntriesLength);
4782 for (c = 0; c < changingEntriesLength; c++) {
4783 k = changingTemplateEntries[c];
4784 changingTemplateX[c] = template[k].x;
4785 changingTemplateY[c] = template[k].y;
4786 changingTemplateBit[c] = 1 << templateLength - 1 - k;
4787 }
4788 const sbb_left = -minX;
4789 const sbb_top = -minY;
4790 const sbb_right = width - maxX;
4791 const pseudoPixelContext = ReusedContexts[templateIndex];
4792 let row = new Uint8Array(width);
4793 const bitmap = [];
4794 const decoder = decodingContext.decoder;
4795 const contexts = decodingContext.contextCache.getContexts("GB");
4796 let ltp = 0,
4797 j,
4798 i0,
4799 j0,
4800 contextLabel = 0,
4801 bit,
4802 shift;
4803 for (let i = 0; i < height; i++) {
4804 if (prediction) {
4805 const sltp = decoder.readBit(contexts, pseudoPixelContext);
4806 ltp ^= sltp;
4807 if (ltp) {
4808 bitmap.push(row);
4809 continue;
4810 }
4811 }
4812 row = new Uint8Array(row);
4813 bitmap.push(row);
4814 for (j = 0; j < width; j++) {
4815 if (useskip && skip[i][j]) {
4816 row[j] = 0;
4817 continue;
4818 }
4819 if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
4820 contextLabel = contextLabel << 1 & reuseMask;
4821 for (k = 0; k < changingEntriesLength; k++) {
4822 i0 = i + changingTemplateY[k];
4823 j0 = j + changingTemplateX[k];
4824 bit = bitmap[i0][j0];
4825 if (bit) {
4826 bit = changingTemplateBit[k];
4827 contextLabel |= bit;
4828 }
4829 }
4830 } else {
4831 contextLabel = 0;
4832 shift = templateLength - 1;
4833 for (k = 0; k < templateLength; k++, shift--) {
4834 j0 = j + templateX[k];
4835 if (j0 >= 0 && j0 < width) {
4836 i0 = i + templateY[k];
4837 if (i0 >= 0) {
4838 bit = bitmap[i0][j0];
4839 if (bit) {
4840 contextLabel |= bit << shift;
4841 }
4842 }
4843 }
4844 }
4845 }
4846 const pixel = decoder.readBit(contexts, contextLabel);
4847 row[j] = pixel;
4848 }
4849 }
4850 return bitmap;
4851}
4852function decodeRefinement(width, height, templateIndex, referenceBitmap, offsetX, offsetY, prediction, at, decodingContext) {
4853 let codingTemplate = RefinementTemplates[templateIndex].coding;
4854 if (templateIndex === 0) {
4855 codingTemplate = codingTemplate.concat([at[0]]);
4856 }
4857 const codingTemplateLength = codingTemplate.length;
4858 const codingTemplateX = new Int32Array(codingTemplateLength);
4859 const codingTemplateY = new Int32Array(codingTemplateLength);
4860 let k;
4861 for (k = 0; k < codingTemplateLength; k++) {
4862 codingTemplateX[k] = codingTemplate[k].x;
4863 codingTemplateY[k] = codingTemplate[k].y;
4864 }
4865 let referenceTemplate = RefinementTemplates[templateIndex].reference;
4866 if (templateIndex === 0) {
4867 referenceTemplate = referenceTemplate.concat([at[1]]);
4868 }
4869 const referenceTemplateLength = referenceTemplate.length;
4870 const referenceTemplateX = new Int32Array(referenceTemplateLength);
4871 const referenceTemplateY = new Int32Array(referenceTemplateLength);
4872 for (k = 0; k < referenceTemplateLength; k++) {
4873 referenceTemplateX[k] = referenceTemplate[k].x;
4874 referenceTemplateY[k] = referenceTemplate[k].y;
4875 }
4876 const referenceWidth = referenceBitmap[0].length;
4877 const referenceHeight = referenceBitmap.length;
4878 const pseudoPixelContext = RefinementReusedContexts[templateIndex];
4879 const bitmap = [];
4880 const decoder = decodingContext.decoder;
4881 const contexts = decodingContext.contextCache.getContexts("GR");
4882 let ltp = 0;
4883 for (let i = 0; i < height; i++) {
4884 if (prediction) {
4885 const sltp = decoder.readBit(contexts, pseudoPixelContext);
4886 ltp ^= sltp;
4887 if (ltp) {
4888 throw new Jbig2Error("prediction is not supported");
4889 }
4890 }
4891 const row = new Uint8Array(width);
4892 bitmap.push(row);
4893 for (let j = 0; j < width; j++) {
4894 let i0, j0;
4895 let contextLabel = 0;
4896 for (k = 0; k < codingTemplateLength; k++) {
4897 i0 = i + codingTemplateY[k];
4898 j0 = j + codingTemplateX[k];
4899 if (i0 < 0 || j0 < 0 || j0 >= width) {
4900 contextLabel <<= 1;
4901 } else {
4902 contextLabel = contextLabel << 1 | bitmap[i0][j0];
4903 }
4904 }
4905 for (k = 0; k < referenceTemplateLength; k++) {
4906 i0 = i + referenceTemplateY[k] - offsetY;
4907 j0 = j + referenceTemplateX[k] - offsetX;
4908 if (i0 < 0 || i0 >= referenceHeight || j0 < 0 || j0 >= referenceWidth) {
4909 contextLabel <<= 1;
4910 } else {
4911 contextLabel = contextLabel << 1 | referenceBitmap[i0][j0];
4912 }
4913 }
4914 const pixel = decoder.readBit(contexts, contextLabel);
4915 row[j] = pixel;
4916 }
4917 }
4918 return bitmap;
4919}
4920function decodeSymbolDictionary(huffman, refinement, symbols, numberOfNewSymbols, numberOfExportedSymbols, huffmanTables, templateIndex, at, refinementTemplateIndex, refinementAt, decodingContext, huffmanInput) {
4921 if (huffman && refinement) {
4922 throw new Jbig2Error("symbol refinement with Huffman is not supported");
4923 }
4924 const newSymbols = [];
4925 let currentHeight = 0;
4926 let symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
4927 const decoder = decodingContext.decoder;
4928 const contextCache = decodingContext.contextCache;
4929 let tableB1, symbolWidths;
4930 if (huffman) {
4931 tableB1 = getStandardTable(1);
4932 symbolWidths = [];
4933 symbolCodeLength = Math.max(symbolCodeLength, 1);
4934 }
4935 while (newSymbols.length < numberOfNewSymbols) {
4936 const deltaHeight = huffman ? huffmanTables.tableDeltaHeight.decode(huffmanInput) : decodeInteger(contextCache, "IADH", decoder);
4937 currentHeight += deltaHeight;
4938 let currentWidth = 0,
4939 totalWidth = 0;
4940 const firstSymbol = huffman ? symbolWidths.length : 0;
4941 while (true) {
4942 const deltaWidth = huffman ? huffmanTables.tableDeltaWidth.decode(huffmanInput) : decodeInteger(contextCache, "IADW", decoder);
4943 if (deltaWidth === null) {
4944 break;
4945 }
4946 currentWidth += deltaWidth;
4947 totalWidth += currentWidth;
4948 let bitmap;
4949 if (refinement) {
4950 const numberOfInstances = decodeInteger(contextCache, "IAAI", decoder);
4951 if (numberOfInstances > 1) {
4952 bitmap = decodeTextRegion(huffman, refinement, currentWidth, currentHeight, 0, numberOfInstances, 1, symbols.concat(newSymbols), symbolCodeLength, 0, 0, 1, 0, huffmanTables, refinementTemplateIndex, refinementAt, decodingContext, 0, huffmanInput);
4953 } else {
4954 const symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
4955 const rdx = decodeInteger(contextCache, "IARDX", decoder);
4956 const rdy = decodeInteger(contextCache, "IARDY", decoder);
4957 const symbol = symbolId < symbols.length ? symbols[symbolId] : newSymbols[symbolId - symbols.length];
4958 bitmap = decodeRefinement(currentWidth, currentHeight, refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt, decodingContext);
4959 }
4960 newSymbols.push(bitmap);
4961 } else if (huffman) {
4962 symbolWidths.push(currentWidth);
4963 } else {
4964 bitmap = decodeBitmap(false, currentWidth, currentHeight, templateIndex, false, null, at, decodingContext);
4965 newSymbols.push(bitmap);
4966 }
4967 }
4968 if (huffman && !refinement) {
4969 const bitmapSize = huffmanTables.tableBitmapSize.decode(huffmanInput);
4970 huffmanInput.byteAlign();
4971 let collectiveBitmap;
4972 if (bitmapSize === 0) {
4973 collectiveBitmap = readUncompressedBitmap(huffmanInput, totalWidth, currentHeight);
4974 } else {
4975 const originalEnd = huffmanInput.end;
4976 const bitmapEnd = huffmanInput.position + bitmapSize;
4977 huffmanInput.end = bitmapEnd;
4978 collectiveBitmap = decodeMMRBitmap(huffmanInput, totalWidth, currentHeight, false);
4979 huffmanInput.end = originalEnd;
4980 huffmanInput.position = bitmapEnd;
4981 }
4982 const numberOfSymbolsDecoded = symbolWidths.length;
4983 if (firstSymbol === numberOfSymbolsDecoded - 1) {
4984 newSymbols.push(collectiveBitmap);
4985 } else {
4986 let i,
4987 y,
4988 xMin = 0,
4989 xMax,
4990 bitmapWidth,
4991 symbolBitmap;
4992 for (i = firstSymbol; i < numberOfSymbolsDecoded; i++) {
4993 bitmapWidth = symbolWidths[i];
4994 xMax = xMin + bitmapWidth;
4995 symbolBitmap = [];
4996 for (y = 0; y < currentHeight; y++) {
4997 symbolBitmap.push(collectiveBitmap[y].subarray(xMin, xMax));
4998 }
4999 newSymbols.push(symbolBitmap);
5000 xMin = xMax;
5001 }
5002 }
5003 }
5004 }
5005 const exportedSymbols = [],
5006 flags = [];
5007 let currentFlag = false,
5008 i,
5009 ii;
5010 const totalSymbolsLength = symbols.length + numberOfNewSymbols;
5011 while (flags.length < totalSymbolsLength) {
5012 let runLength = huffman ? tableB1.decode(huffmanInput) : decodeInteger(contextCache, "IAEX", decoder);
5013 while (runLength--) {
5014 flags.push(currentFlag);
5015 }
5016 currentFlag = !currentFlag;
5017 }
5018 for (i = 0, ii = symbols.length; i < ii; i++) {
5019 if (flags[i]) {
5020 exportedSymbols.push(symbols[i]);
5021 }
5022 }
5023 for (let j = 0; j < numberOfNewSymbols; i++, j++) {
5024 if (flags[i]) {
5025 exportedSymbols.push(newSymbols[j]);
5026 }
5027 }
5028 return exportedSymbols;
5029}
5030function decodeTextRegion(huffman, refinement, width, height, defaultPixelValue, numberOfSymbolInstances, stripSize, inputSymbols, symbolCodeLength, transposed, dsOffset, referenceCorner, combinationOperator, huffmanTables, refinementTemplateIndex, refinementAt, decodingContext, logStripSize, huffmanInput) {
5031 if (huffman && refinement) {
5032 throw new Jbig2Error("refinement with Huffman is not supported");
5033 }
5034 const bitmap = [];
5035 let i, row;
5036 for (i = 0; i < height; i++) {
5037 row = new Uint8Array(width);
5038 if (defaultPixelValue) {
5039 for (let j = 0; j < width; j++) {
5040 row[j] = defaultPixelValue;
5041 }
5042 }
5043 bitmap.push(row);
5044 }
5045 const decoder = decodingContext.decoder;
5046 const contextCache = decodingContext.contextCache;
5047 let stripT = huffman ? -huffmanTables.tableDeltaT.decode(huffmanInput) : -decodeInteger(contextCache, "IADT", decoder);
5048 let firstS = 0;
5049 i = 0;
5050 while (i < numberOfSymbolInstances) {
5051 const deltaT = huffman ? huffmanTables.tableDeltaT.decode(huffmanInput) : decodeInteger(contextCache, "IADT", decoder);
5052 stripT += deltaT;
5053 const deltaFirstS = huffman ? huffmanTables.tableFirstS.decode(huffmanInput) : decodeInteger(contextCache, "IAFS", decoder);
5054 firstS += deltaFirstS;
5055 let currentS = firstS;
5056 do {
5057 let currentT = 0;
5058 if (stripSize > 1) {
5059 currentT = huffman ? huffmanInput.readBits(logStripSize) : decodeInteger(contextCache, "IAIT", decoder);
5060 }
5061 const t = stripSize * stripT + currentT;
5062 const symbolId = huffman ? huffmanTables.symbolIDTable.decode(huffmanInput) : decodeIAID(contextCache, decoder, symbolCodeLength);
5063 const applyRefinement = refinement && (huffman ? huffmanInput.readBit() : decodeInteger(contextCache, "IARI", decoder));
5064 let symbolBitmap = inputSymbols[symbolId];
5065 let symbolWidth = symbolBitmap[0].length;
5066 let symbolHeight = symbolBitmap.length;
5067 if (applyRefinement) {
5068 const rdw = decodeInteger(contextCache, "IARDW", decoder);
5069 const rdh = decodeInteger(contextCache, "IARDH", decoder);
5070 const rdx = decodeInteger(contextCache, "IARDX", decoder);
5071 const rdy = decodeInteger(contextCache, "IARDY", decoder);
5072 symbolWidth += rdw;
5073 symbolHeight += rdh;
5074 symbolBitmap = decodeRefinement(symbolWidth, symbolHeight, refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx, (rdh >> 1) + rdy, false, refinementAt, decodingContext);
5075 }
5076 let increment = 0;
5077 if (!transposed) {
5078 if (referenceCorner > 1) {
5079 currentS += symbolWidth - 1;
5080 } else {
5081 increment = symbolWidth - 1;
5082 }
5083 } else if (!(referenceCorner & 1)) {
5084 currentS += symbolHeight - 1;
5085 } else {
5086 increment = symbolHeight - 1;
5087 }
5088 const offsetT = t - (referenceCorner & 1 ? 0 : symbolHeight - 1);
5089 const offsetS = currentS - (referenceCorner & 2 ? symbolWidth - 1 : 0);
5090 let s2, t2, symbolRow;
5091 if (transposed) {
5092 for (s2 = 0; s2 < symbolHeight; s2++) {
5093 row = bitmap[offsetS + s2];
5094 if (!row) {
5095 continue;
5096 }
5097 symbolRow = symbolBitmap[s2];
5098 const maxWidth = Math.min(width - offsetT, symbolWidth);
5099 switch (combinationOperator) {
5100 case 0:
5101 for (t2 = 0; t2 < maxWidth; t2++) {
5102 row[offsetT + t2] |= symbolRow[t2];
5103 }
5104 break;
5105 case 2:
5106 for (t2 = 0; t2 < maxWidth; t2++) {
5107 row[offsetT + t2] ^= symbolRow[t2];
5108 }
5109 break;
5110 default:
5111 throw new Jbig2Error(`operator ${combinationOperator} is not supported`);
5112 }
5113 }
5114 } else {
5115 for (t2 = 0; t2 < symbolHeight; t2++) {
5116 row = bitmap[offsetT + t2];
5117 if (!row) {
5118 continue;
5119 }
5120 symbolRow = symbolBitmap[t2];
5121 switch (combinationOperator) {
5122 case 0:
5123 for (s2 = 0; s2 < symbolWidth; s2++) {
5124 row[offsetS + s2] |= symbolRow[s2];
5125 }
5126 break;
5127 case 2:
5128 for (s2 = 0; s2 < symbolWidth; s2++) {
5129 row[offsetS + s2] ^= symbolRow[s2];
5130 }
5131 break;
5132 default:
5133 throw new Jbig2Error(`operator ${combinationOperator} is not supported`);
5134 }
5135 }
5136 }
5137 i++;
5138 const deltaS = huffman ? huffmanTables.tableDeltaS.decode(huffmanInput) : decodeInteger(contextCache, "IADS", decoder);
5139 if (deltaS === null) {
5140 break;
5141 }
5142 currentS += increment + deltaS + dsOffset;
5143 } while (true);
5144 }
5145 return bitmap;
5146}
5147function decodePatternDictionary(mmr, patternWidth, patternHeight, maxPatternIndex, template, decodingContext) {
5148 const at = [];
5149 if (!mmr) {
5150 at.push({
5151 x: -patternWidth,
5152 y: 0
5153 });
5154 if (template === 0) {
5155 at.push({
5156 x: -3,
5157 y: -1
5158 }, {
5159 x: 2,
5160 y: -2
5161 }, {
5162 x: -2,
5163 y: -2
5164 });
5165 }
5166 }
5167 const collectiveWidth = (maxPatternIndex + 1) * patternWidth;
5168 const collectiveBitmap = decodeBitmap(mmr, collectiveWidth, patternHeight, template, false, null, at, decodingContext);
5169 const patterns = [];
5170 for (let i = 0; i <= maxPatternIndex; i++) {
5171 const patternBitmap = [];
5172 const xMin = patternWidth * i;
5173 const xMax = xMin + patternWidth;
5174 for (let y = 0; y < patternHeight; y++) {
5175 patternBitmap.push(collectiveBitmap[y].subarray(xMin, xMax));
5176 }
5177 patterns.push(patternBitmap);
5178 }
5179 return patterns;
5180}
5181function decodeHalftoneRegion(mmr, patterns, template, regionWidth, regionHeight, defaultPixelValue, enableSkip, combinationOperator, gridWidth, gridHeight, gridOffsetX, gridOffsetY, gridVectorX, gridVectorY, decodingContext) {
5182 const skip = null;
5183 if (enableSkip) {
5184 throw new Jbig2Error("skip is not supported");
5185 }
5186 if (combinationOperator !== 0) {
5187 throw new Jbig2Error(`operator "${combinationOperator}" is not supported in halftone region`);
5188 }
5189 const regionBitmap = [];
5190 let i, j, row;
5191 for (i = 0; i < regionHeight; i++) {
5192 row = new Uint8Array(regionWidth);
5193 if (defaultPixelValue) {
5194 for (j = 0; j < regionWidth; j++) {
5195 row[j] = defaultPixelValue;
5196 }
5197 }
5198 regionBitmap.push(row);
5199 }
5200 const numberOfPatterns = patterns.length;
5201 const pattern0 = patterns[0];
5202 const patternWidth = pattern0[0].length,
5203 patternHeight = pattern0.length;
5204 const bitsPerValue = log2(numberOfPatterns);
5205 const at = [];
5206 if (!mmr) {
5207 at.push({
5208 x: template <= 1 ? 3 : 2,
5209 y: -1
5210 });
5211 if (template === 0) {
5212 at.push({
5213 x: -3,
5214 y: -1
5215 }, {
5216 x: 2,
5217 y: -2
5218 }, {
5219 x: -2,
5220 y: -2
5221 });
5222 }
5223 }
5224 const grayScaleBitPlanes = [];
5225 let mmrInput, bitmap;
5226 if (mmr) {
5227 mmrInput = new Reader(decodingContext.data, decodingContext.start, decodingContext.end);
5228 }
5229 for (i = bitsPerValue - 1; i >= 0; i--) {
5230 if (mmr) {
5231 bitmap = decodeMMRBitmap(mmrInput, gridWidth, gridHeight, true);
5232 } else {
5233 bitmap = decodeBitmap(false, gridWidth, gridHeight, template, false, skip, at, decodingContext);
5234 }
5235 grayScaleBitPlanes[i] = bitmap;
5236 }
5237 let mg, ng, bit, patternIndex, patternBitmap, x, y, patternRow, regionRow;
5238 for (mg = 0; mg < gridHeight; mg++) {
5239 for (ng = 0; ng < gridWidth; ng++) {
5240 bit = 0;
5241 patternIndex = 0;
5242 for (j = bitsPerValue - 1; j >= 0; j--) {
5243 bit ^= grayScaleBitPlanes[j][mg][ng];
5244 patternIndex |= bit << j;
5245 }
5246 patternBitmap = patterns[patternIndex];
5247 x = gridOffsetX + mg * gridVectorY + ng * gridVectorX >> 8;
5248 y = gridOffsetY + mg * gridVectorX - ng * gridVectorY >> 8;
5249 if (x >= 0 && x + patternWidth <= regionWidth && y >= 0 && y + patternHeight <= regionHeight) {
5250 for (i = 0; i < patternHeight; i++) {
5251 regionRow = regionBitmap[y + i];
5252 patternRow = patternBitmap[i];
5253 for (j = 0; j < patternWidth; j++) {
5254 regionRow[x + j] |= patternRow[j];
5255 }
5256 }
5257 } else {
5258 let regionX, regionY;
5259 for (i = 0; i < patternHeight; i++) {
5260 regionY = y + i;
5261 if (regionY < 0 || regionY >= regionHeight) {
5262 continue;
5263 }
5264 regionRow = regionBitmap[regionY];
5265 patternRow = patternBitmap[i];
5266 for (j = 0; j < patternWidth; j++) {
5267 regionX = x + j;
5268 if (regionX >= 0 && regionX < regionWidth) {
5269 regionRow[regionX] |= patternRow[j];
5270 }
5271 }
5272 }
5273 }
5274 }
5275 }
5276 return regionBitmap;
5277}
5278function readSegmentHeader(data, start) {
5279 const segmentHeader = {};
5280 segmentHeader.number = readUint32(data, start);
5281 const flags = data[start + 4];
5282 const segmentType = flags & 0x3f;
5283 if (!SegmentTypes[segmentType]) {
5284 throw new Jbig2Error("invalid segment type: " + segmentType);
5285 }
5286 segmentHeader.type = segmentType;
5287 segmentHeader.typeName = SegmentTypes[segmentType];
5288 segmentHeader.deferredNonRetain = !!(flags & 0x80);
5289 const pageAssociationFieldSize = !!(flags & 0x40);
5290 const referredFlags = data[start + 5];
5291 let referredToCount = referredFlags >> 5 & 7;
5292 const retainBits = [referredFlags & 31];
5293 let position = start + 6;
5294 if (referredFlags === 7) {
5295 referredToCount = readUint32(data, position - 1) & 0x1fffffff;
5296 position += 3;
5297 let bytes = referredToCount + 7 >> 3;
5298 retainBits[0] = data[position++];
5299 while (--bytes > 0) {
5300 retainBits.push(data[position++]);
5301 }
5302 } else if (referredFlags === 5 || referredFlags === 6) {
5303 throw new Jbig2Error("invalid referred-to flags");
5304 }
5305 segmentHeader.retainBits = retainBits;
5306 let referredToSegmentNumberSize = 4;
5307 if (segmentHeader.number <= 256) {
5308 referredToSegmentNumberSize = 1;
5309 } else if (segmentHeader.number <= 65536) {
5310 referredToSegmentNumberSize = 2;
5311 }
5312 const referredTo = [];
5313 let i, ii;
5314 for (i = 0; i < referredToCount; i++) {
5315 let number;
5316 if (referredToSegmentNumberSize === 1) {
5317 number = data[position];
5318 } else if (referredToSegmentNumberSize === 2) {
5319 number = readUint16(data, position);
5320 } else {
5321 number = readUint32(data, position);
5322 }
5323 referredTo.push(number);
5324 position += referredToSegmentNumberSize;
5325 }
5326 segmentHeader.referredTo = referredTo;
5327 if (!pageAssociationFieldSize) {
5328 segmentHeader.pageAssociation = data[position++];
5329 } else {
5330 segmentHeader.pageAssociation = readUint32(data, position);
5331 position += 4;
5332 }
5333 segmentHeader.length = readUint32(data, position);
5334 position += 4;
5335 if (segmentHeader.length === 0xffffffff) {
5336 if (segmentType === 38) {
5337 const genericRegionInfo = readRegionSegmentInformation(data, position);
5338 const genericRegionSegmentFlags = data[position + RegionSegmentInformationFieldLength];
5339 const genericRegionMmr = !!(genericRegionSegmentFlags & 1);
5340 const searchPatternLength = 6;
5341 const searchPattern = new Uint8Array(searchPatternLength);
5342 if (!genericRegionMmr) {
5343 searchPattern[0] = 0xff;
5344 searchPattern[1] = 0xac;
5345 }
5346 searchPattern[2] = genericRegionInfo.height >>> 24 & 0xff;
5347 searchPattern[3] = genericRegionInfo.height >> 16 & 0xff;
5348 searchPattern[4] = genericRegionInfo.height >> 8 & 0xff;
5349 searchPattern[5] = genericRegionInfo.height & 0xff;
5350 for (i = position, ii = data.length; i < ii; i++) {
5351 let j = 0;
5352 while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
5353 j++;
5354 }
5355 if (j === searchPatternLength) {
5356 segmentHeader.length = i + searchPatternLength;
5357 break;
5358 }
5359 }
5360 if (segmentHeader.length === 0xffffffff) {
5361 throw new Jbig2Error("segment end was not found");
5362 }
5363 } else {
5364 throw new Jbig2Error("invalid unknown segment length");
5365 }
5366 }
5367 segmentHeader.headerEnd = position;
5368 return segmentHeader;
5369}
5370function readSegments(header, data, start, end) {
5371 const segments = [];
5372 let position = start;
5373 while (position < end) {
5374 const segmentHeader = readSegmentHeader(data, position);
5375 position = segmentHeader.headerEnd;
5376 const segment = {
5377 header: segmentHeader,
5378 data
5379 };
5380 if (!header.randomAccess) {
5381 segment.start = position;
5382 position += segmentHeader.length;
5383 segment.end = position;
5384 }
5385 segments.push(segment);
5386 if (segmentHeader.type === 51) {
5387 break;
5388 }
5389 }
5390 if (header.randomAccess) {
5391 for (let i = 0, ii = segments.length; i < ii; i++) {
5392 segments[i].start = position;
5393 position += segments[i].header.length;
5394 segments[i].end = position;
5395 }
5396 }
5397 return segments;
5398}
5399function readRegionSegmentInformation(data, start) {
5400 return {
5401 width: readUint32(data, start),
5402 height: readUint32(data, start + 4),
5403 x: readUint32(data, start + 8),
5404 y: readUint32(data, start + 12),
5405 combinationOperator: data[start + 16] & 7
5406 };
5407}
5408const RegionSegmentInformationFieldLength = 17;
5409function processSegment(segment, visitor) {
5410 const header = segment.header;
5411 const data = segment.data,
5412 end = segment.end;
5413 let position = segment.start;
5414 let args, at, i, atLength;
5415 switch (header.type) {
5416 case 0:
5417 const dictionary = {};
5418 const dictionaryFlags = readUint16(data, position);
5419 dictionary.huffman = !!(dictionaryFlags & 1);
5420 dictionary.refinement = !!(dictionaryFlags & 2);
5421 dictionary.huffmanDHSelector = dictionaryFlags >> 2 & 3;
5422 dictionary.huffmanDWSelector = dictionaryFlags >> 4 & 3;
5423 dictionary.bitmapSizeSelector = dictionaryFlags >> 6 & 1;
5424 dictionary.aggregationInstancesSelector = dictionaryFlags >> 7 & 1;
5425 dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
5426 dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
5427 dictionary.template = dictionaryFlags >> 10 & 3;
5428 dictionary.refinementTemplate = dictionaryFlags >> 12 & 1;
5429 position += 2;
5430 if (!dictionary.huffman) {
5431 atLength = dictionary.template === 0 ? 4 : 1;
5432 at = [];
5433 for (i = 0; i < atLength; i++) {
5434 at.push({
5435 x: readInt8(data, position),
5436 y: readInt8(data, position + 1)
5437 });
5438 position += 2;
5439 }
5440 dictionary.at = at;
5441 }
5442 if (dictionary.refinement && !dictionary.refinementTemplate) {
5443 at = [];
5444 for (i = 0; i < 2; i++) {
5445 at.push({
5446 x: readInt8(data, position),
5447 y: readInt8(data, position + 1)
5448 });
5449 position += 2;
5450 }
5451 dictionary.refinementAt = at;
5452 }
5453 dictionary.numberOfExportedSymbols = readUint32(data, position);
5454 position += 4;
5455 dictionary.numberOfNewSymbols = readUint32(data, position);
5456 position += 4;
5457 args = [dictionary, header.number, header.referredTo, data, position, end];
5458 break;
5459 case 6:
5460 case 7:
5461 const textRegion = {};
5462 textRegion.info = readRegionSegmentInformation(data, position);
5463 position += RegionSegmentInformationFieldLength;
5464 const textRegionSegmentFlags = readUint16(data, position);
5465 position += 2;
5466 textRegion.huffman = !!(textRegionSegmentFlags & 1);
5467 textRegion.refinement = !!(textRegionSegmentFlags & 2);
5468 textRegion.logStripSize = textRegionSegmentFlags >> 2 & 3;
5469 textRegion.stripSize = 1 << textRegion.logStripSize;
5470 textRegion.referenceCorner = textRegionSegmentFlags >> 4 & 3;
5471 textRegion.transposed = !!(textRegionSegmentFlags & 64);
5472 textRegion.combinationOperator = textRegionSegmentFlags >> 7 & 3;
5473 textRegion.defaultPixelValue = textRegionSegmentFlags >> 9 & 1;
5474 textRegion.dsOffset = textRegionSegmentFlags << 17 >> 27;
5475 textRegion.refinementTemplate = textRegionSegmentFlags >> 15 & 1;
5476 if (textRegion.huffman) {
5477 const textRegionHuffmanFlags = readUint16(data, position);
5478 position += 2;
5479 textRegion.huffmanFS = textRegionHuffmanFlags & 3;
5480 textRegion.huffmanDS = textRegionHuffmanFlags >> 2 & 3;
5481 textRegion.huffmanDT = textRegionHuffmanFlags >> 4 & 3;
5482 textRegion.huffmanRefinementDW = textRegionHuffmanFlags >> 6 & 3;
5483 textRegion.huffmanRefinementDH = textRegionHuffmanFlags >> 8 & 3;
5484 textRegion.huffmanRefinementDX = textRegionHuffmanFlags >> 10 & 3;
5485 textRegion.huffmanRefinementDY = textRegionHuffmanFlags >> 12 & 3;
5486 textRegion.huffmanRefinementSizeSelector = !!(textRegionHuffmanFlags & 0x4000);
5487 }
5488 if (textRegion.refinement && !textRegion.refinementTemplate) {
5489 at = [];
5490 for (i = 0; i < 2; i++) {
5491 at.push({
5492 x: readInt8(data, position),
5493 y: readInt8(data, position + 1)
5494 });
5495 position += 2;
5496 }
5497 textRegion.refinementAt = at;
5498 }
5499 textRegion.numberOfSymbolInstances = readUint32(data, position);
5500 position += 4;
5501 args = [textRegion, header.referredTo, data, position, end];
5502 break;
5503 case 16:
5504 const patternDictionary = {};
5505 const patternDictionaryFlags = data[position++];
5506 patternDictionary.mmr = !!(patternDictionaryFlags & 1);
5507 patternDictionary.template = patternDictionaryFlags >> 1 & 3;
5508 patternDictionary.patternWidth = data[position++];
5509 patternDictionary.patternHeight = data[position++];
5510 patternDictionary.maxPatternIndex = readUint32(data, position);
5511 position += 4;
5512 args = [patternDictionary, header.number, data, position, end];
5513 break;
5514 case 22:
5515 case 23:
5516 const halftoneRegion = {};
5517 halftoneRegion.info = readRegionSegmentInformation(data, position);
5518 position += RegionSegmentInformationFieldLength;
5519 const halftoneRegionFlags = data[position++];
5520 halftoneRegion.mmr = !!(halftoneRegionFlags & 1);
5521 halftoneRegion.template = halftoneRegionFlags >> 1 & 3;
5522 halftoneRegion.enableSkip = !!(halftoneRegionFlags & 8);
5523 halftoneRegion.combinationOperator = halftoneRegionFlags >> 4 & 7;
5524 halftoneRegion.defaultPixelValue = halftoneRegionFlags >> 7 & 1;
5525 halftoneRegion.gridWidth = readUint32(data, position);
5526 position += 4;
5527 halftoneRegion.gridHeight = readUint32(data, position);
5528 position += 4;
5529 halftoneRegion.gridOffsetX = readUint32(data, position) & 0xffffffff;
5530 position += 4;
5531 halftoneRegion.gridOffsetY = readUint32(data, position) & 0xffffffff;
5532 position += 4;
5533 halftoneRegion.gridVectorX = readUint16(data, position);
5534 position += 2;
5535 halftoneRegion.gridVectorY = readUint16(data, position);
5536 position += 2;
5537 args = [halftoneRegion, header.referredTo, data, position, end];
5538 break;
5539 case 38:
5540 case 39:
5541 const genericRegion = {};
5542 genericRegion.info = readRegionSegmentInformation(data, position);
5543 position += RegionSegmentInformationFieldLength;
5544 const genericRegionSegmentFlags = data[position++];
5545 genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
5546 genericRegion.template = genericRegionSegmentFlags >> 1 & 3;
5547 genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
5548 if (!genericRegion.mmr) {
5549 atLength = genericRegion.template === 0 ? 4 : 1;
5550 at = [];
5551 for (i = 0; i < atLength; i++) {
5552 at.push({
5553 x: readInt8(data, position),
5554 y: readInt8(data, position + 1)
5555 });
5556 position += 2;
5557 }
5558 genericRegion.at = at;
5559 }
5560 args = [genericRegion, data, position, end];
5561 break;
5562 case 48:
5563 const pageInfo = {
5564 width: readUint32(data, position),
5565 height: readUint32(data, position + 4),
5566 resolutionX: readUint32(data, position + 8),
5567 resolutionY: readUint32(data, position + 12)
5568 };
5569 if (pageInfo.height === 0xffffffff) {
5570 delete pageInfo.height;
5571 }
5572 const pageSegmentFlags = data[position + 16];
5573 readUint16(data, position + 17);
5574 pageInfo.lossless = !!(pageSegmentFlags & 1);
5575 pageInfo.refinement = !!(pageSegmentFlags & 2);
5576 pageInfo.defaultPixelValue = pageSegmentFlags >> 2 & 1;
5577 pageInfo.combinationOperator = pageSegmentFlags >> 3 & 3;
5578 pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
5579 pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
5580 args = [pageInfo];
5581 break;
5582 case 49:
5583 break;
5584 case 50:
5585 break;
5586 case 51:
5587 break;
5588 case 53:
5589 args = [header.number, data, position, end];
5590 break;
5591 case 62:
5592 break;
5593 default:
5594 throw new Jbig2Error(`segment type ${header.typeName}(${header.type}) is not implemented`);
5595 }
5596 const callbackName = "on" + header.typeName;
5597 if (callbackName in visitor) {
5598 visitor[callbackName].apply(visitor, args);
5599 }
5600}
5601function processSegments(segments, visitor) {
5602 for (let i = 0, ii = segments.length; i < ii; i++) {
5603 processSegment(segments[i], visitor);
5604 }
5605}
5606function parseJbig2Chunks(chunks) {
5607 const visitor = new SimpleSegmentVisitor();
5608 for (let i = 0, ii = chunks.length; i < ii; i++) {
5609 const chunk = chunks[i];
5610 const segments = readSegments({}, chunk.data, chunk.start, chunk.end);
5611 processSegments(segments, visitor);
5612 }
5613 return visitor.buffer;
5614}
5615function parseJbig2(data) {
5616 throw new Error("Not implemented: parseJbig2");
5617}
5618class SimpleSegmentVisitor {
5619 onPageInformation(info) {
5620 this.currentPageInfo = info;
5621 const rowSize = info.width + 7 >> 3;
5622 const buffer = new Uint8ClampedArray(rowSize * info.height);
5623 if (info.defaultPixelValue) {
5624 buffer.fill(0xff);
5625 }
5626 this.buffer = buffer;
5627 }
5628 drawBitmap(regionInfo, bitmap) {
5629 const pageInfo = this.currentPageInfo;
5630 const width = regionInfo.width,
5631 height = regionInfo.height;
5632 const rowSize = pageInfo.width + 7 >> 3;
5633 const combinationOperator = pageInfo.combinationOperatorOverride ? regionInfo.combinationOperator : pageInfo.combinationOperator;
5634 const buffer = this.buffer;
5635 const mask0 = 128 >> (regionInfo.x & 7);
5636 let offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
5637 let i, j, mask, offset;
5638 switch (combinationOperator) {
5639 case 0:
5640 for (i = 0; i < height; i++) {
5641 mask = mask0;
5642 offset = offset0;
5643 for (j = 0; j < width; j++) {
5644 if (bitmap[i][j]) {
5645 buffer[offset] |= mask;
5646 }
5647 mask >>= 1;
5648 if (!mask) {
5649 mask = 128;
5650 offset++;
5651 }
5652 }
5653 offset0 += rowSize;
5654 }
5655 break;
5656 case 2:
5657 for (i = 0; i < height; i++) {
5658 mask = mask0;
5659 offset = offset0;
5660 for (j = 0; j < width; j++) {
5661 if (bitmap[i][j]) {
5662 buffer[offset] ^= mask;
5663 }
5664 mask >>= 1;
5665 if (!mask) {
5666 mask = 128;
5667 offset++;
5668 }
5669 }
5670 offset0 += rowSize;
5671 }
5672 break;
5673 default:
5674 throw new Jbig2Error(`operator ${combinationOperator} is not supported`);
5675 }
5676 }
5677 onImmediateGenericRegion(region, data, start, end) {
5678 const regionInfo = region.info;
5679 const decodingContext = new DecodingContext(data, start, end);
5680 const bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height, region.template, region.prediction, null, region.at, decodingContext);
5681 this.drawBitmap(regionInfo, bitmap);
5682 }
5683 onImmediateLosslessGenericRegion() {
5684 this.onImmediateGenericRegion(...arguments);
5685 }
5686 onSymbolDictionary(dictionary, currentSegment, referredSegments, data, start, end) {
5687 let huffmanTables, huffmanInput;
5688 if (dictionary.huffman) {
5689 huffmanTables = getSymbolDictionaryHuffmanTables(dictionary, referredSegments, this.customTables);
5690 huffmanInput = new Reader(data, start, end);
5691 }
5692 let symbols = this.symbols;
5693 if (!symbols) {
5694 this.symbols = symbols = {};
5695 }
5696 const inputSymbols = [];
5697 for (const referredSegment of referredSegments) {
5698 const referredSymbols = symbols[referredSegment];
5699 if (referredSymbols) {
5700 inputSymbols.push(...referredSymbols);
5701 }
5702 }
5703 const decodingContext = new DecodingContext(data, start, end);
5704 symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman, dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols, dictionary.numberOfExportedSymbols, huffmanTables, dictionary.template, dictionary.at, dictionary.refinementTemplate, dictionary.refinementAt, decodingContext, huffmanInput);
5705 }
5706 onImmediateTextRegion(region, referredSegments, data, start, end) {
5707 const regionInfo = region.info;
5708 let huffmanTables, huffmanInput;
5709 const symbols = this.symbols;
5710 const inputSymbols = [];
5711 for (const referredSegment of referredSegments) {
5712 const referredSymbols = symbols[referredSegment];
5713 if (referredSymbols) {
5714 inputSymbols.push(...referredSymbols);
5715 }
5716 }
5717 const symbolCodeLength = log2(inputSymbols.length);
5718 if (region.huffman) {
5719 huffmanInput = new Reader(data, start, end);
5720 huffmanTables = getTextRegionHuffmanTables(region, referredSegments, this.customTables, inputSymbols.length, huffmanInput);
5721 }
5722 const decodingContext = new DecodingContext(data, start, end);
5723 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);
5724 this.drawBitmap(regionInfo, bitmap);
5725 }
5726 onImmediateLosslessTextRegion() {
5727 this.onImmediateTextRegion(...arguments);
5728 }
5729 onPatternDictionary(dictionary, currentSegment, data, start, end) {
5730 let patterns = this.patterns;
5731 if (!patterns) {
5732 this.patterns = patterns = {};
5733 }
5734 const decodingContext = new DecodingContext(data, start, end);
5735 patterns[currentSegment] = decodePatternDictionary(dictionary.mmr, dictionary.patternWidth, dictionary.patternHeight, dictionary.maxPatternIndex, dictionary.template, decodingContext);
5736 }
5737 onImmediateHalftoneRegion(region, referredSegments, data, start, end) {
5738 const patterns = this.patterns[referredSegments[0]];
5739 const regionInfo = region.info;
5740 const decodingContext = new DecodingContext(data, start, end);
5741 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);
5742 this.drawBitmap(regionInfo, bitmap);
5743 }
5744 onImmediateLosslessHalftoneRegion() {
5745 this.onImmediateHalftoneRegion(...arguments);
5746 }
5747 onTables(currentSegment, data, start, end) {
5748 let customTables = this.customTables;
5749 if (!customTables) {
5750 this.customTables = customTables = {};
5751 }
5752 customTables[currentSegment] = decodeTablesSegment(data, start, end);
5753 }
5754}
5755class HuffmanLine {
5756 constructor(lineData) {
5757 if (lineData.length === 2) {
5758 this.isOOB = true;
5759 this.rangeLow = 0;
5760 this.prefixLength = lineData[0];
5761 this.rangeLength = 0;
5762 this.prefixCode = lineData[1];
5763 this.isLowerRange = false;
5764 } else {
5765 this.isOOB = false;
5766 this.rangeLow = lineData[0];
5767 this.prefixLength = lineData[1];
5768 this.rangeLength = lineData[2];
5769 this.prefixCode = lineData[3];
5770 this.isLowerRange = lineData[4] === "lower";
5771 }
5772 }
5773}
5774class HuffmanTreeNode {
5775 constructor(line) {
5776 this.children = [];
5777 if (line) {
5778 this.isLeaf = true;
5779 this.rangeLength = line.rangeLength;
5780 this.rangeLow = line.rangeLow;
5781 this.isLowerRange = line.isLowerRange;
5782 this.isOOB = line.isOOB;
5783 } else {
5784 this.isLeaf = false;
5785 }
5786 }
5787 buildTree(line, shift) {
5788 const bit = line.prefixCode >> shift & 1;
5789 if (shift <= 0) {
5790 this.children[bit] = new HuffmanTreeNode(line);
5791 } else {
5792 let node = this.children[bit];
5793 if (!node) {
5794 this.children[bit] = node = new HuffmanTreeNode(null);
5795 }
5796 node.buildTree(line, shift - 1);
5797 }
5798 }
5799 decodeNode(reader) {
5800 if (this.isLeaf) {
5801 if (this.isOOB) {
5802 return null;
5803 }
5804 const htOffset = reader.readBits(this.rangeLength);
5805 return this.rangeLow + (this.isLowerRange ? -htOffset : htOffset);
5806 }
5807 const node = this.children[reader.readBit()];
5808 if (!node) {
5809 throw new Jbig2Error("invalid Huffman data");
5810 }
5811 return node.decodeNode(reader);
5812 }
5813}
5814class HuffmanTable {
5815 constructor(lines, prefixCodesDone) {
5816 if (!prefixCodesDone) {
5817 this.assignPrefixCodes(lines);
5818 }
5819 this.rootNode = new HuffmanTreeNode(null);
5820 for (let i = 0, ii = lines.length; i < ii; i++) {
5821 const line = lines[i];
5822 if (line.prefixLength > 0) {
5823 this.rootNode.buildTree(line, line.prefixLength - 1);
5824 }
5825 }
5826 }
5827 decode(reader) {
5828 return this.rootNode.decodeNode(reader);
5829 }
5830 assignPrefixCodes(lines) {
5831 const linesLength = lines.length;
5832 let prefixLengthMax = 0;
5833 for (let i = 0; i < linesLength; i++) {
5834 prefixLengthMax = Math.max(prefixLengthMax, lines[i].prefixLength);
5835 }
5836 const histogram = new Uint32Array(prefixLengthMax + 1);
5837 for (let i = 0; i < linesLength; i++) {
5838 histogram[lines[i].prefixLength]++;
5839 }
5840 let currentLength = 1,
5841 firstCode = 0,
5842 currentCode,
5843 currentTemp,
5844 line;
5845 histogram[0] = 0;
5846 while (currentLength <= prefixLengthMax) {
5847 firstCode = firstCode + histogram[currentLength - 1] << 1;
5848 currentCode = firstCode;
5849 currentTemp = 0;
5850 while (currentTemp < linesLength) {
5851 line = lines[currentTemp];
5852 if (line.prefixLength === currentLength) {
5853 line.prefixCode = currentCode;
5854 currentCode++;
5855 }
5856 currentTemp++;
5857 }
5858 currentLength++;
5859 }
5860 }
5861}
5862function decodeTablesSegment(data, start, end) {
5863 const flags = data[start];
5864 const lowestValue = readUint32(data, start + 1) & 0xffffffff;
5865 const highestValue = readUint32(data, start + 5) & 0xffffffff;
5866 const reader = new Reader(data, start + 9, end);
5867 const prefixSizeBits = (flags >> 1 & 7) + 1;
5868 const rangeSizeBits = (flags >> 4 & 7) + 1;
5869 const lines = [];
5870 let prefixLength,
5871 rangeLength,
5872 currentRangeLow = lowestValue;
5873 do {
5874 prefixLength = reader.readBits(prefixSizeBits);
5875 rangeLength = reader.readBits(rangeSizeBits);
5876 lines.push(new HuffmanLine([currentRangeLow, prefixLength, rangeLength, 0]));
5877 currentRangeLow += 1 << rangeLength;
5878 } while (currentRangeLow < highestValue);
5879 prefixLength = reader.readBits(prefixSizeBits);
5880 lines.push(new HuffmanLine([lowestValue - 1, prefixLength, 32, 0, "lower"]));
5881 prefixLength = reader.readBits(prefixSizeBits);
5882 lines.push(new HuffmanLine([highestValue, prefixLength, 32, 0]));
5883 if (flags & 1) {
5884 prefixLength = reader.readBits(prefixSizeBits);
5885 lines.push(new HuffmanLine([prefixLength, 0]));
5886 }
5887 return new HuffmanTable(lines, false);
5888}
5889const standardTablesCache = {};
5890function getStandardTable(number) {
5891 let table = standardTablesCache[number];
5892 if (table) {
5893 return table;
5894 }
5895 let lines;
5896 switch (number) {
5897 case 1:
5898 lines = [[0, 1, 4, 0x0], [16, 2, 8, 0x2], [272, 3, 16, 0x6], [65808, 3, 32, 0x7]];
5899 break;
5900 case 2:
5901 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]];
5902 break;
5903 case 3:
5904 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]];
5905 break;
5906 case 4:
5907 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]];
5908 break;
5909 case 5:
5910 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]];
5911 break;
5912 case 6:
5913 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]];
5914 break;
5915 case 7:
5916 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]];
5917 break;
5918 case 8:
5919 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]];
5920 break;
5921 case 9:
5922 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]];
5923 break;
5924 case 10:
5925 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]];
5926 break;
5927 case 11:
5928 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]];
5929 break;
5930 case 12:
5931 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]];
5932 break;
5933 case 13:
5934 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]];
5935 break;
5936 case 14:
5937 lines = [[-2, 3, 0, 0x4], [-1, 3, 0, 0x5], [0, 1, 0, 0x0], [1, 3, 0, 0x6], [2, 3, 0, 0x7]];
5938 break;
5939 case 15:
5940 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]];
5941 break;
5942 default:
5943 throw new Jbig2Error(`standard table B.${number} does not exist`);
5944 }
5945 for (let i = 0, ii = lines.length; i < ii; i++) {
5946 lines[i] = new HuffmanLine(lines[i]);
5947 }
5948 table = new HuffmanTable(lines, true);
5949 standardTablesCache[number] = table;
5950 return table;
5951}
5952class Reader {
5953 constructor(data, start, end) {
5954 this.data = data;
5955 this.start = start;
5956 this.end = end;
5957 this.position = start;
5958 this.shift = -1;
5959 this.currentByte = 0;
5960 }
5961 readBit() {
5962 if (this.shift < 0) {
5963 if (this.position >= this.end) {
5964 throw new Jbig2Error("end of data while reading bit");
5965 }
5966 this.currentByte = this.data[this.position++];
5967 this.shift = 7;
5968 }
5969 const bit = this.currentByte >> this.shift & 1;
5970 this.shift--;
5971 return bit;
5972 }
5973 readBits(numBits) {
5974 let result = 0,
5975 i;
5976 for (i = numBits - 1; i >= 0; i--) {
5977 result |= this.readBit() << i;
5978 }
5979 return result;
5980 }
5981 byteAlign() {
5982 this.shift = -1;
5983 }
5984 next() {
5985 if (this.position >= this.end) {
5986 return -1;
5987 }
5988 return this.data[this.position++];
5989 }
5990}
5991function getCustomHuffmanTable(index, referredTo, customTables) {
5992 let currentIndex = 0;
5993 for (let i = 0, ii = referredTo.length; i < ii; i++) {
5994 const table = customTables[referredTo[i]];
5995 if (table) {
5996 if (index === currentIndex) {
5997 return table;
5998 }
5999 currentIndex++;
6000 }
6001 }
6002 throw new Jbig2Error("can't find custom Huffman table");
6003}
6004function getTextRegionHuffmanTables(textRegion, referredTo, customTables, numberOfSymbols, reader) {
6005 const codes = [];
6006 for (let i = 0; i <= 34; i++) {
6007 const codeLength = reader.readBits(4);
6008 codes.push(new HuffmanLine([i, codeLength, 0, 0]));
6009 }
6010 const runCodesTable = new HuffmanTable(codes, false);
6011 codes.length = 0;
6012 for (let i = 0; i < numberOfSymbols;) {
6013 const codeLength = runCodesTable.decode(reader);
6014 if (codeLength >= 32) {
6015 let repeatedLength, numberOfRepeats, j;
6016 switch (codeLength) {
6017 case 32:
6018 if (i === 0) {
6019 throw new Jbig2Error("no previous value in symbol ID table");
6020 }
6021 numberOfRepeats = reader.readBits(2) + 3;
6022 repeatedLength = codes[i - 1].prefixLength;
6023 break;
6024 case 33:
6025 numberOfRepeats = reader.readBits(3) + 3;
6026 repeatedLength = 0;
6027 break;
6028 case 34:
6029 numberOfRepeats = reader.readBits(7) + 11;
6030 repeatedLength = 0;
6031 break;
6032 default:
6033 throw new Jbig2Error("invalid code length in symbol ID table");
6034 }
6035 for (j = 0; j < numberOfRepeats; j++) {
6036 codes.push(new HuffmanLine([i, repeatedLength, 0, 0]));
6037 i++;
6038 }
6039 } else {
6040 codes.push(new HuffmanLine([i, codeLength, 0, 0]));
6041 i++;
6042 }
6043 }
6044 reader.byteAlign();
6045 const symbolIDTable = new HuffmanTable(codes, false);
6046 let customIndex = 0,
6047 tableFirstS,
6048 tableDeltaS,
6049 tableDeltaT;
6050 switch (textRegion.huffmanFS) {
6051 case 0:
6052 case 1:
6053 tableFirstS = getStandardTable(textRegion.huffmanFS + 6);
6054 break;
6055 case 3:
6056 tableFirstS = getCustomHuffmanTable(customIndex, referredTo, customTables);
6057 customIndex++;
6058 break;
6059 default:
6060 throw new Jbig2Error("invalid Huffman FS selector");
6061 }
6062 switch (textRegion.huffmanDS) {
6063 case 0:
6064 case 1:
6065 case 2:
6066 tableDeltaS = getStandardTable(textRegion.huffmanDS + 8);
6067 break;
6068 case 3:
6069 tableDeltaS = getCustomHuffmanTable(customIndex, referredTo, customTables);
6070 customIndex++;
6071 break;
6072 default:
6073 throw new Jbig2Error("invalid Huffman DS selector");
6074 }
6075 switch (textRegion.huffmanDT) {
6076 case 0:
6077 case 1:
6078 case 2:
6079 tableDeltaT = getStandardTable(textRegion.huffmanDT + 11);
6080 break;
6081 case 3:
6082 tableDeltaT = getCustomHuffmanTable(customIndex, referredTo, customTables);
6083 customIndex++;
6084 break;
6085 default:
6086 throw new Jbig2Error("invalid Huffman DT selector");
6087 }
6088 if (textRegion.refinement) {
6089 throw new Jbig2Error("refinement with Huffman is not supported");
6090 }
6091 return {
6092 symbolIDTable,
6093 tableFirstS,
6094 tableDeltaS,
6095 tableDeltaT
6096 };
6097}
6098function getSymbolDictionaryHuffmanTables(dictionary, referredTo, customTables) {
6099 let customIndex = 0,
6100 tableDeltaHeight,
6101 tableDeltaWidth;
6102 switch (dictionary.huffmanDHSelector) {
6103 case 0:
6104 case 1:
6105 tableDeltaHeight = getStandardTable(dictionary.huffmanDHSelector + 4);
6106 break;
6107 case 3:
6108 tableDeltaHeight = getCustomHuffmanTable(customIndex, referredTo, customTables);
6109 customIndex++;
6110 break;
6111 default:
6112 throw new Jbig2Error("invalid Huffman DH selector");
6113 }
6114 switch (dictionary.huffmanDWSelector) {
6115 case 0:
6116 case 1:
6117 tableDeltaWidth = getStandardTable(dictionary.huffmanDWSelector + 2);
6118 break;
6119 case 3:
6120 tableDeltaWidth = getCustomHuffmanTable(customIndex, referredTo, customTables);
6121 customIndex++;
6122 break;
6123 default:
6124 throw new Jbig2Error("invalid Huffman DW selector");
6125 }
6126 let tableBitmapSize, tableAggregateInstances;
6127 if (dictionary.bitmapSizeSelector) {
6128 tableBitmapSize = getCustomHuffmanTable(customIndex, referredTo, customTables);
6129 customIndex++;
6130 } else {
6131 tableBitmapSize = getStandardTable(1);
6132 }
6133 if (dictionary.aggregationInstancesSelector) {
6134 tableAggregateInstances = getCustomHuffmanTable(customIndex, referredTo, customTables);
6135 } else {
6136 tableAggregateInstances = getStandardTable(1);
6137 }
6138 return {
6139 tableDeltaHeight,
6140 tableDeltaWidth,
6141 tableBitmapSize,
6142 tableAggregateInstances
6143 };
6144}
6145function readUncompressedBitmap(reader, width, height) {
6146 const bitmap = [];
6147 for (let y = 0; y < height; y++) {
6148 const row = new Uint8Array(width);
6149 bitmap.push(row);
6150 for (let x = 0; x < width; x++) {
6151 row[x] = reader.readBit();
6152 }
6153 reader.byteAlign();
6154 }
6155 return bitmap;
6156}
6157function decodeMMRBitmap(input, width, height, endOfBlock) {
6158 const params = {
6159 K: -1,
6160 Columns: width,
6161 Rows: height,
6162 BlackIs1: true,
6163 EndOfBlock: endOfBlock
6164 };
6165 const decoder = new CCITTFaxDecoder(input, params);
6166 const bitmap = [];
6167 let currentByte,
6168 eof = false;
6169 for (let y = 0; y < height; y++) {
6170 const row = new Uint8Array(width);
6171 bitmap.push(row);
6172 let shift = -1;
6173 for (let x = 0; x < width; x++) {
6174 if (shift < 0) {
6175 currentByte = decoder.readNextChar();
6176 if (currentByte === -1) {
6177 currentByte = 0;
6178 eof = true;
6179 }
6180 shift = 7;
6181 }
6182 row[x] = currentByte >> shift & 1;
6183 shift--;
6184 }
6185 }
6186 if (endOfBlock && !eof) {
6187 const lookForEOFLimit = 5;
6188 for (let i = 0; i < lookForEOFLimit; i++) {
6189 if (decoder.readNextChar() === -1) {
6190 break;
6191 }
6192 }
6193 }
6194 return bitmap;
6195}
6196class Jbig2Image {
6197 parseChunks(chunks) {
6198 return parseJbig2Chunks(chunks);
6199 }
6200 parse(data) {
6201 throw new Error("Not implemented: Jbig2Image.parse");
6202 }
6203}
6204
6205;// CONCATENATED MODULE: ./src/core/jbig2_stream.js
6206
6207
6208
6209
6210
6211class Jbig2Stream extends DecodeStream {
6212 constructor(stream, maybeLength, params) {
6213 super(maybeLength);
6214 this.stream = stream;
6215 this.dict = stream.dict;
6216 this.maybeLength = maybeLength;
6217 this.params = params;
6218 }
6219 get bytes() {
6220 return shadow(this, "bytes", this.stream.getBytes(this.maybeLength));
6221 }
6222 ensureBuffer(requested) {}
6223 readBlock() {
6224 if (this.eof) {
6225 return;
6226 }
6227 const jbig2Image = new Jbig2Image();
6228 const chunks = [];
6229 if (this.params instanceof Dict) {
6230 const globalsStream = this.params.get("JBIG2Globals");
6231 if (globalsStream instanceof BaseStream) {
6232 const globals = globalsStream.getBytes();
6233 chunks.push({
6234 data: globals,
6235 start: 0,
6236 end: globals.length
6237 });
6238 }
6239 }
6240 chunks.push({
6241 data: this.bytes,
6242 start: 0,
6243 end: this.bytes.length
6244 });
6245 const data = jbig2Image.parseChunks(chunks);
6246 const dataLength = data.length;
6247 for (let i = 0; i < dataLength; i++) {
6248 data[i] ^= 0xff;
6249 }
6250 this.buffer = data;
6251 this.bufferLength = dataLength;
6252 this.eof = true;
6253 }
6254}
6255
6256;// CONCATENATED MODULE: ./src/shared/image_utils.js
6257
6258function convertToRGBA(params) {
6259 switch (params.kind) {
6260 case ImageKind.GRAYSCALE_1BPP:
6261 return convertBlackAndWhiteToRGBA(params);
6262 case ImageKind.RGB_24BPP:
6263 return convertRGBToRGBA(params);
6264 }
6265 return null;
6266}
6267function convertBlackAndWhiteToRGBA({
6268 src,
6269 srcPos = 0,
6270 dest,
6271 width,
6272 height,
6273 nonBlackColor = 0xffffffff,
6274 inverseDecode = false
6275}) {
6276 const black = FeatureTest.isLittleEndian ? 0xff000000 : 0x000000ff;
6277 const [zeroMapping, oneMapping] = inverseDecode ? [nonBlackColor, black] : [black, nonBlackColor];
6278 const widthInSource = width >> 3;
6279 const widthRemainder = width & 7;
6280 const srcLength = src.length;
6281 dest = new Uint32Array(dest.buffer);
6282 let destPos = 0;
6283 for (let i = 0; i < height; i++) {
6284 for (const max = srcPos + widthInSource; srcPos < max; srcPos++) {
6285 const elem = srcPos < srcLength ? src[srcPos] : 255;
6286 dest[destPos++] = elem & 0b10000000 ? oneMapping : zeroMapping;
6287 dest[destPos++] = elem & 0b1000000 ? oneMapping : zeroMapping;
6288 dest[destPos++] = elem & 0b100000 ? oneMapping : zeroMapping;
6289 dest[destPos++] = elem & 0b10000 ? oneMapping : zeroMapping;
6290 dest[destPos++] = elem & 0b1000 ? oneMapping : zeroMapping;
6291 dest[destPos++] = elem & 0b100 ? oneMapping : zeroMapping;
6292 dest[destPos++] = elem & 0b10 ? oneMapping : zeroMapping;
6293 dest[destPos++] = elem & 0b1 ? oneMapping : zeroMapping;
6294 }
6295 if (widthRemainder === 0) {
6296 continue;
6297 }
6298 const elem = srcPos < srcLength ? src[srcPos++] : 255;
6299 for (let j = 0; j < widthRemainder; j++) {
6300 dest[destPos++] = elem & 1 << 7 - j ? oneMapping : zeroMapping;
6301 }
6302 }
6303 return {
6304 srcPos,
6305 destPos
6306 };
6307}
6308function convertRGBToRGBA({
6309 src,
6310 srcPos = 0,
6311 dest,
6312 destPos = 0,
6313 width,
6314 height
6315}) {
6316 let i = 0;
6317 const len32 = src.length >> 2;
6318 const src32 = new Uint32Array(src.buffer, srcPos, len32);
6319 if (FeatureTest.isLittleEndian) {
6320 for (; i < len32 - 2; i += 3, destPos += 4) {
6321 const s1 = src32[i];
6322 const s2 = src32[i + 1];
6323 const s3 = src32[i + 2];
6324 dest[destPos] = s1 | 0xff000000;
6325 dest[destPos + 1] = s1 >>> 24 | s2 << 8 | 0xff000000;
6326 dest[destPos + 2] = s2 >>> 16 | s3 << 16 | 0xff000000;
6327 dest[destPos + 3] = s3 >>> 8 | 0xff000000;
6328 }
6329 for (let j = i * 4, jj = src.length; j < jj; j += 3) {
6330 dest[destPos++] = src[j] | src[j + 1] << 8 | src[j + 2] << 16 | 0xff000000;
6331 }
6332 } else {
6333 for (; i < len32 - 2; i += 3, destPos += 4) {
6334 const s1 = src32[i];
6335 const s2 = src32[i + 1];
6336 const s3 = src32[i + 2];
6337 dest[destPos] = s1 | 0xff;
6338 dest[destPos + 1] = s1 << 24 | s2 >>> 8 | 0xff;
6339 dest[destPos + 2] = s2 << 16 | s3 >>> 16 | 0xff;
6340 dest[destPos + 3] = s3 << 8 | 0xff;
6341 }
6342 for (let j = i * 4, jj = src.length; j < jj; j += 3) {
6343 dest[destPos++] = src[j] << 24 | src[j + 1] << 16 | src[j + 2] << 8 | 0xff;
6344 }
6345 }
6346 return {
6347 srcPos,
6348 destPos
6349 };
6350}
6351function grayToRGBA(src, dest) {
6352 if (FeatureTest.isLittleEndian) {
6353 for (let i = 0, ii = src.length; i < ii; i++) {
6354 dest[i] = src[i] * 0x10101 | 0xff000000;
6355 }
6356 } else {
6357 for (let i = 0, ii = src.length; i < ii; i++) {
6358 dest[i] = src[i] * 0x1010100 | 0x000000ff;
6359 }
6360 }
6361}
6362
6363;// CONCATENATED MODULE: ./src/core/jpg.js
6364
6365
6366
6367class JpegError extends BaseException {
6368 constructor(msg) {
6369 super(`JPEG error: ${msg}`, "JpegError");
6370 }
6371}
6372class DNLMarkerError extends BaseException {
6373 constructor(message, scanLines) {
6374 super(message, "DNLMarkerError");
6375 this.scanLines = scanLines;
6376 }
6377}
6378class EOIMarkerError extends BaseException {
6379 constructor(msg) {
6380 super(msg, "EOIMarkerError");
6381 }
6382}
6383const 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]);
6384const dctCos1 = 4017;
6385const dctSin1 = 799;
6386const dctCos3 = 3406;
6387const dctSin3 = 2276;
6388const dctCos6 = 1567;
6389const dctSin6 = 3784;
6390const dctSqrt2 = 5793;
6391const dctSqrt1d2 = 2896;
6392function buildHuffmanTable(codeLengths, values) {
6393 let k = 0,
6394 i,
6395 j,
6396 length = 16;
6397 while (length > 0 && !codeLengths[length - 1]) {
6398 length--;
6399 }
6400 const code = [{
6401 children: [],
6402 index: 0
6403 }];
6404 let p = code[0],
6405 q;
6406 for (i = 0; i < length; i++) {
6407 for (j = 0; j < codeLengths[i]; j++) {
6408 p = code.pop();
6409 p.children[p.index] = values[k];
6410 while (p.index > 0) {
6411 p = code.pop();
6412 }
6413 p.index++;
6414 code.push(p);
6415 while (code.length <= i) {
6416 code.push(q = {
6417 children: [],
6418 index: 0
6419 });
6420 p.children[p.index] = q.children;
6421 p = q;
6422 }
6423 k++;
6424 }
6425 if (i + 1 < length) {
6426 code.push(q = {
6427 children: [],
6428 index: 0
6429 });
6430 p.children[p.index] = q.children;
6431 p = q;
6432 }
6433 }
6434 return code[0].children;
6435}
6436function getBlockBufferOffset(component, row, col) {
6437 return 64 * ((component.blocksPerLine + 1) * row + col);
6438}
6439function decodeScan(data, offset, frame, components, resetInterval, spectralStart, spectralEnd, successivePrev, successive, parseDNLMarker = false) {
6440 const mcusPerLine = frame.mcusPerLine;
6441 const progressive = frame.progressive;
6442 const startOffset = offset;
6443 let bitsData = 0,
6444 bitsCount = 0;
6445 function readBit() {
6446 if (bitsCount > 0) {
6447 bitsCount--;
6448 return bitsData >> bitsCount & 1;
6449 }
6450 bitsData = data[offset++];
6451 if (bitsData === 0xff) {
6452 const nextByte = data[offset++];
6453 if (nextByte) {
6454 if (nextByte === 0xdc && parseDNLMarker) {
6455 offset += 2;
6456 const scanLines = readUint16(data, offset);
6457 offset += 2;
6458 if (scanLines > 0 && scanLines !== frame.scanLines) {
6459 throw new DNLMarkerError("Found DNL marker (0xFFDC) while parsing scan data", scanLines);
6460 }
6461 } else if (nextByte === 0xd9) {
6462 if (parseDNLMarker) {
6463 const maybeScanLines = blockRow * (frame.precision === 8 ? 8 : 0);
6464 if (maybeScanLines > 0 && Math.round(frame.scanLines / maybeScanLines) >= 5) {
6465 throw new DNLMarkerError("Found EOI marker (0xFFD9) while parsing scan data, " + "possibly caused by incorrect `scanLines` parameter", maybeScanLines);
6466 }
6467 }
6468 throw new EOIMarkerError("Found EOI marker (0xFFD9) while parsing scan data");
6469 }
6470 throw new JpegError(`unexpected marker ${(bitsData << 8 | nextByte).toString(16)}`);
6471 }
6472 }
6473 bitsCount = 7;
6474 return bitsData >>> 7;
6475 }
6476 function decodeHuffman(tree) {
6477 let node = tree;
6478 while (true) {
6479 node = node[readBit()];
6480 switch (typeof node) {
6481 case "number":
6482 return node;
6483 case "object":
6484 continue;
6485 }
6486 throw new JpegError("invalid huffman sequence");
6487 }
6488 }
6489 function receive(length) {
6490 let n = 0;
6491 while (length > 0) {
6492 n = n << 1 | readBit();
6493 length--;
6494 }
6495 return n;
6496 }
6497 function receiveAndExtend(length) {
6498 if (length === 1) {
6499 return readBit() === 1 ? 1 : -1;
6500 }
6501 const n = receive(length);
6502 if (n >= 1 << length - 1) {
6503 return n;
6504 }
6505 return n + (-1 << length) + 1;
6506 }
6507 function decodeBaseline(component, blockOffset) {
6508 const t = decodeHuffman(component.huffmanTableDC);
6509 const diff = t === 0 ? 0 : receiveAndExtend(t);
6510 component.blockData[blockOffset] = component.pred += diff;
6511 let k = 1;
6512 while (k < 64) {
6513 const rs = decodeHuffman(component.huffmanTableAC);
6514 const s = rs & 15,
6515 r = rs >> 4;
6516 if (s === 0) {
6517 if (r < 15) {
6518 break;
6519 }
6520 k += 16;
6521 continue;
6522 }
6523 k += r;
6524 const z = dctZigZag[k];
6525 component.blockData[blockOffset + z] = receiveAndExtend(s);
6526 k++;
6527 }
6528 }
6529 function decodeDCFirst(component, blockOffset) {
6530 const t = decodeHuffman(component.huffmanTableDC);
6531 const diff = t === 0 ? 0 : receiveAndExtend(t) << successive;
6532 component.blockData[blockOffset] = component.pred += diff;
6533 }
6534 function decodeDCSuccessive(component, blockOffset) {
6535 component.blockData[blockOffset] |= readBit() << successive;
6536 }
6537 let eobrun = 0;
6538 function decodeACFirst(component, blockOffset) {
6539 if (eobrun > 0) {
6540 eobrun--;
6541 return;
6542 }
6543 let k = spectralStart;
6544 const e = spectralEnd;
6545 while (k <= e) {
6546 const rs = decodeHuffman(component.huffmanTableAC);
6547 const s = rs & 15,
6548 r = rs >> 4;
6549 if (s === 0) {
6550 if (r < 15) {
6551 eobrun = receive(r) + (1 << r) - 1;
6552 break;
6553 }
6554 k += 16;
6555 continue;
6556 }
6557 k += r;
6558 const z = dctZigZag[k];
6559 component.blockData[blockOffset + z] = receiveAndExtend(s) * (1 << successive);
6560 k++;
6561 }
6562 }
6563 let successiveACState = 0,
6564 successiveACNextValue;
6565 function decodeACSuccessive(component, blockOffset) {
6566 let k = spectralStart;
6567 const e = spectralEnd;
6568 let r = 0;
6569 let s;
6570 let rs;
6571 while (k <= e) {
6572 const offsetZ = blockOffset + dctZigZag[k];
6573 const sign = component.blockData[offsetZ] < 0 ? -1 : 1;
6574 switch (successiveACState) {
6575 case 0:
6576 rs = decodeHuffman(component.huffmanTableAC);
6577 s = rs & 15;
6578 r = rs >> 4;
6579 if (s === 0) {
6580 if (r < 15) {
6581 eobrun = receive(r) + (1 << r);
6582 successiveACState = 4;
6583 } else {
6584 r = 16;
6585 successiveACState = 1;
6586 }
6587 } else {
6588 if (s !== 1) {
6589 throw new JpegError("invalid ACn encoding");
6590 }
6591 successiveACNextValue = receiveAndExtend(s);
6592 successiveACState = r ? 2 : 3;
6593 }
6594 continue;
6595 case 1:
6596 case 2:
6597 if (component.blockData[offsetZ]) {
6598 component.blockData[offsetZ] += sign * (readBit() << successive);
6599 } else {
6600 r--;
6601 if (r === 0) {
6602 successiveACState = successiveACState === 2 ? 3 : 0;
6603 }
6604 }
6605 break;
6606 case 3:
6607 if (component.blockData[offsetZ]) {
6608 component.blockData[offsetZ] += sign * (readBit() << successive);
6609 } else {
6610 component.blockData[offsetZ] = successiveACNextValue << successive;
6611 successiveACState = 0;
6612 }
6613 break;
6614 case 4:
6615 if (component.blockData[offsetZ]) {
6616 component.blockData[offsetZ] += sign * (readBit() << successive);
6617 }
6618 break;
6619 }
6620 k++;
6621 }
6622 if (successiveACState === 4) {
6623 eobrun--;
6624 if (eobrun === 0) {
6625 successiveACState = 0;
6626 }
6627 }
6628 }
6629 let blockRow = 0;
6630 function decodeMcu(component, decode, mcu, row, col) {
6631 const mcuRow = mcu / mcusPerLine | 0;
6632 const mcuCol = mcu % mcusPerLine;
6633 blockRow = mcuRow * component.v + row;
6634 const blockCol = mcuCol * component.h + col;
6635 const blockOffset = getBlockBufferOffset(component, blockRow, blockCol);
6636 decode(component, blockOffset);
6637 }
6638 function decodeBlock(component, decode, mcu) {
6639 blockRow = mcu / component.blocksPerLine | 0;
6640 const blockCol = mcu % component.blocksPerLine;
6641 const blockOffset = getBlockBufferOffset(component, blockRow, blockCol);
6642 decode(component, blockOffset);
6643 }
6644 const componentsLength = components.length;
6645 let component, i, j, k, n;
6646 let decodeFn;
6647 if (progressive) {
6648 if (spectralStart === 0) {
6649 decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
6650 } else {
6651 decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
6652 }
6653 } else {
6654 decodeFn = decodeBaseline;
6655 }
6656 let mcu = 0,
6657 fileMarker;
6658 const mcuExpected = componentsLength === 1 ? components[0].blocksPerLine * components[0].blocksPerColumn : mcusPerLine * frame.mcusPerColumn;
6659 let h, v;
6660 while (mcu <= mcuExpected) {
6661 const mcuToRead = resetInterval ? Math.min(mcuExpected - mcu, resetInterval) : mcuExpected;
6662 if (mcuToRead > 0) {
6663 for (i = 0; i < componentsLength; i++) {
6664 components[i].pred = 0;
6665 }
6666 eobrun = 0;
6667 if (componentsLength === 1) {
6668 component = components[0];
6669 for (n = 0; n < mcuToRead; n++) {
6670 decodeBlock(component, decodeFn, mcu);
6671 mcu++;
6672 }
6673 } else {
6674 for (n = 0; n < mcuToRead; n++) {
6675 for (i = 0; i < componentsLength; i++) {
6676 component = components[i];
6677 h = component.h;
6678 v = component.v;
6679 for (j = 0; j < v; j++) {
6680 for (k = 0; k < h; k++) {
6681 decodeMcu(component, decodeFn, mcu, j, k);
6682 }
6683 }
6684 }
6685 mcu++;
6686 }
6687 }
6688 }
6689 bitsCount = 0;
6690 fileMarker = findNextFileMarker(data, offset);
6691 if (!fileMarker) {
6692 break;
6693 }
6694 if (fileMarker.invalid) {
6695 const partialMsg = mcuToRead > 0 ? "unexpected" : "excessive";
6696 warn(`decodeScan - ${partialMsg} MCU data, current marker is: ${fileMarker.invalid}`);
6697 offset = fileMarker.offset;
6698 }
6699 if (fileMarker.marker >= 0xffd0 && fileMarker.marker <= 0xffd7) {
6700 offset += 2;
6701 } else {
6702 break;
6703 }
6704 }
6705 return offset - startOffset;
6706}
6707function quantizeAndInverse(component, blockBufferOffset, p) {
6708 const qt = component.quantizationTable,
6709 blockData = component.blockData;
6710 let v0, v1, v2, v3, v4, v5, v6, v7;
6711 let p0, p1, p2, p3, p4, p5, p6, p7;
6712 let t;
6713 if (!qt) {
6714 throw new JpegError("missing required Quantization Table.");
6715 }
6716 for (let row = 0; row < 64; row += 8) {
6717 p0 = blockData[blockBufferOffset + row];
6718 p1 = blockData[blockBufferOffset + row + 1];
6719 p2 = blockData[blockBufferOffset + row + 2];
6720 p3 = blockData[blockBufferOffset + row + 3];
6721 p4 = blockData[blockBufferOffset + row + 4];
6722 p5 = blockData[blockBufferOffset + row + 5];
6723 p6 = blockData[blockBufferOffset + row + 6];
6724 p7 = blockData[blockBufferOffset + row + 7];
6725 p0 *= qt[row];
6726 if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
6727 t = dctSqrt2 * p0 + 512 >> 10;
6728 p[row] = t;
6729 p[row + 1] = t;
6730 p[row + 2] = t;
6731 p[row + 3] = t;
6732 p[row + 4] = t;
6733 p[row + 5] = t;
6734 p[row + 6] = t;
6735 p[row + 7] = t;
6736 continue;
6737 }
6738 p1 *= qt[row + 1];
6739 p2 *= qt[row + 2];
6740 p3 *= qt[row + 3];
6741 p4 *= qt[row + 4];
6742 p5 *= qt[row + 5];
6743 p6 *= qt[row + 6];
6744 p7 *= qt[row + 7];
6745 v0 = dctSqrt2 * p0 + 128 >> 8;
6746 v1 = dctSqrt2 * p4 + 128 >> 8;
6747 v2 = p2;
6748 v3 = p6;
6749 v4 = dctSqrt1d2 * (p1 - p7) + 128 >> 8;
6750 v7 = dctSqrt1d2 * (p1 + p7) + 128 >> 8;
6751 v5 = p3 << 4;
6752 v6 = p5 << 4;
6753 v0 = v0 + v1 + 1 >> 1;
6754 v1 = v0 - v1;
6755 t = v2 * dctSin6 + v3 * dctCos6 + 128 >> 8;
6756 v2 = v2 * dctCos6 - v3 * dctSin6 + 128 >> 8;
6757 v3 = t;
6758 v4 = v4 + v6 + 1 >> 1;
6759 v6 = v4 - v6;
6760 v7 = v7 + v5 + 1 >> 1;
6761 v5 = v7 - v5;
6762 v0 = v0 + v3 + 1 >> 1;
6763 v3 = v0 - v3;
6764 v1 = v1 + v2 + 1 >> 1;
6765 v2 = v1 - v2;
6766 t = v4 * dctSin3 + v7 * dctCos3 + 2048 >> 12;
6767 v4 = v4 * dctCos3 - v7 * dctSin3 + 2048 >> 12;
6768 v7 = t;
6769 t = v5 * dctSin1 + v6 * dctCos1 + 2048 >> 12;
6770 v5 = v5 * dctCos1 - v6 * dctSin1 + 2048 >> 12;
6771 v6 = t;
6772 p[row] = v0 + v7;
6773 p[row + 7] = v0 - v7;
6774 p[row + 1] = v1 + v6;
6775 p[row + 6] = v1 - v6;
6776 p[row + 2] = v2 + v5;
6777 p[row + 5] = v2 - v5;
6778 p[row + 3] = v3 + v4;
6779 p[row + 4] = v3 - v4;
6780 }
6781 for (let col = 0; col < 8; ++col) {
6782 p0 = p[col];
6783 p1 = p[col + 8];
6784 p2 = p[col + 16];
6785 p3 = p[col + 24];
6786 p4 = p[col + 32];
6787 p5 = p[col + 40];
6788 p6 = p[col + 48];
6789 p7 = p[col + 56];
6790 if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
6791 t = dctSqrt2 * p0 + 8192 >> 14;
6792 if (t < -2040) {
6793 t = 0;
6794 } else if (t >= 2024) {
6795 t = 255;
6796 } else {
6797 t = t + 2056 >> 4;
6798 }
6799 blockData[blockBufferOffset + col] = t;
6800 blockData[blockBufferOffset + col + 8] = t;
6801 blockData[blockBufferOffset + col + 16] = t;
6802 blockData[blockBufferOffset + col + 24] = t;
6803 blockData[blockBufferOffset + col + 32] = t;
6804 blockData[blockBufferOffset + col + 40] = t;
6805 blockData[blockBufferOffset + col + 48] = t;
6806 blockData[blockBufferOffset + col + 56] = t;
6807 continue;
6808 }
6809 v0 = dctSqrt2 * p0 + 2048 >> 12;
6810 v1 = dctSqrt2 * p4 + 2048 >> 12;
6811 v2 = p2;
6812 v3 = p6;
6813 v4 = dctSqrt1d2 * (p1 - p7) + 2048 >> 12;
6814 v7 = dctSqrt1d2 * (p1 + p7) + 2048 >> 12;
6815 v5 = p3;
6816 v6 = p5;
6817 v0 = (v0 + v1 + 1 >> 1) + 4112;
6818 v1 = v0 - v1;
6819 t = v2 * dctSin6 + v3 * dctCos6 + 2048 >> 12;
6820 v2 = v2 * dctCos6 - v3 * dctSin6 + 2048 >> 12;
6821 v3 = t;
6822 v4 = v4 + v6 + 1 >> 1;
6823 v6 = v4 - v6;
6824 v7 = v7 + v5 + 1 >> 1;
6825 v5 = v7 - v5;
6826 v0 = v0 + v3 + 1 >> 1;
6827 v3 = v0 - v3;
6828 v1 = v1 + v2 + 1 >> 1;
6829 v2 = v1 - v2;
6830 t = v4 * dctSin3 + v7 * dctCos3 + 2048 >> 12;
6831 v4 = v4 * dctCos3 - v7 * dctSin3 + 2048 >> 12;
6832 v7 = t;
6833 t = v5 * dctSin1 + v6 * dctCos1 + 2048 >> 12;
6834 v5 = v5 * dctCos1 - v6 * dctSin1 + 2048 >> 12;
6835 v6 = t;
6836 p0 = v0 + v7;
6837 p7 = v0 - v7;
6838 p1 = v1 + v6;
6839 p6 = v1 - v6;
6840 p2 = v2 + v5;
6841 p5 = v2 - v5;
6842 p3 = v3 + v4;
6843 p4 = v3 - v4;
6844 if (p0 < 16) {
6845 p0 = 0;
6846 } else if (p0 >= 4080) {
6847 p0 = 255;
6848 } else {
6849 p0 >>= 4;
6850 }
6851 if (p1 < 16) {
6852 p1 = 0;
6853 } else if (p1 >= 4080) {
6854 p1 = 255;
6855 } else {
6856 p1 >>= 4;
6857 }
6858 if (p2 < 16) {
6859 p2 = 0;
6860 } else if (p2 >= 4080) {
6861 p2 = 255;
6862 } else {
6863 p2 >>= 4;
6864 }
6865 if (p3 < 16) {
6866 p3 = 0;
6867 } else if (p3 >= 4080) {
6868 p3 = 255;
6869 } else {
6870 p3 >>= 4;
6871 }
6872 if (p4 < 16) {
6873 p4 = 0;
6874 } else if (p4 >= 4080) {
6875 p4 = 255;
6876 } else {
6877 p4 >>= 4;
6878 }
6879 if (p5 < 16) {
6880 p5 = 0;
6881 } else if (p5 >= 4080) {
6882 p5 = 255;
6883 } else {
6884 p5 >>= 4;
6885 }
6886 if (p6 < 16) {
6887 p6 = 0;
6888 } else if (p6 >= 4080) {
6889 p6 = 255;
6890 } else {
6891 p6 >>= 4;
6892 }
6893 if (p7 < 16) {
6894 p7 = 0;
6895 } else if (p7 >= 4080) {
6896 p7 = 255;
6897 } else {
6898 p7 >>= 4;
6899 }
6900 blockData[blockBufferOffset + col] = p0;
6901 blockData[blockBufferOffset + col + 8] = p1;
6902 blockData[blockBufferOffset + col + 16] = p2;
6903 blockData[blockBufferOffset + col + 24] = p3;
6904 blockData[blockBufferOffset + col + 32] = p4;
6905 blockData[blockBufferOffset + col + 40] = p5;
6906 blockData[blockBufferOffset + col + 48] = p6;
6907 blockData[blockBufferOffset + col + 56] = p7;
6908 }
6909}
6910function buildComponentData(frame, component) {
6911 const blocksPerLine = component.blocksPerLine;
6912 const blocksPerColumn = component.blocksPerColumn;
6913 const computationBuffer = new Int16Array(64);
6914 for (let blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
6915 for (let blockCol = 0; blockCol < blocksPerLine; blockCol++) {
6916 const offset = getBlockBufferOffset(component, blockRow, blockCol);
6917 quantizeAndInverse(component, offset, computationBuffer);
6918 }
6919 }
6920 return component.blockData;
6921}
6922function findNextFileMarker(data, currentPos, startPos = currentPos) {
6923 const maxPos = data.length - 1;
6924 let newPos = startPos < currentPos ? startPos : currentPos;
6925 if (currentPos >= maxPos) {
6926 return null;
6927 }
6928 const currentMarker = readUint16(data, currentPos);
6929 if (currentMarker >= 0xffc0 && currentMarker <= 0xfffe) {
6930 return {
6931 invalid: null,
6932 marker: currentMarker,
6933 offset: currentPos
6934 };
6935 }
6936 let newMarker = readUint16(data, newPos);
6937 while (!(newMarker >= 0xffc0 && newMarker <= 0xfffe)) {
6938 if (++newPos >= maxPos) {
6939 return null;
6940 }
6941 newMarker = readUint16(data, newPos);
6942 }
6943 return {
6944 invalid: currentMarker.toString(16),
6945 marker: newMarker,
6946 offset: newPos
6947 };
6948}
6949class JpegImage {
6950 constructor({
6951 decodeTransform = null,
6952 colorTransform = -1
6953 } = {}) {
6954 this._decodeTransform = decodeTransform;
6955 this._colorTransform = colorTransform;
6956 }
6957 parse(data, {
6958 dnlScanLines = null
6959 } = {}) {
6960 function readDataBlock() {
6961 const length = readUint16(data, offset);
6962 offset += 2;
6963 let endOffset = offset + length - 2;
6964 const fileMarker = findNextFileMarker(data, endOffset, offset);
6965 if (fileMarker?.invalid) {
6966 warn("readDataBlock - incorrect length, current marker is: " + fileMarker.invalid);
6967 endOffset = fileMarker.offset;
6968 }
6969 const array = data.subarray(offset, endOffset);
6970 offset += array.length;
6971 return array;
6972 }
6973 function prepareComponents(frame) {
6974 const mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
6975 const mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
6976 for (const component of frame.components) {
6977 const blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) * component.h / frame.maxH);
6978 const blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) * component.v / frame.maxV);
6979 const blocksPerLineForMcu = mcusPerLine * component.h;
6980 const blocksPerColumnForMcu = mcusPerColumn * component.v;
6981 const blocksBufferSize = 64 * blocksPerColumnForMcu * (blocksPerLineForMcu + 1);
6982 component.blockData = new Int16Array(blocksBufferSize);
6983 component.blocksPerLine = blocksPerLine;
6984 component.blocksPerColumn = blocksPerColumn;
6985 }
6986 frame.mcusPerLine = mcusPerLine;
6987 frame.mcusPerColumn = mcusPerColumn;
6988 }
6989 let offset = 0;
6990 let jfif = null;
6991 let adobe = null;
6992 let frame, resetInterval;
6993 let numSOSMarkers = 0;
6994 const quantizationTables = [];
6995 const huffmanTablesAC = [],
6996 huffmanTablesDC = [];
6997 let fileMarker = readUint16(data, offset);
6998 offset += 2;
6999 if (fileMarker !== 0xffd8) {
7000 throw new JpegError("SOI not found");
7001 }
7002 fileMarker = readUint16(data, offset);
7003 offset += 2;
7004 markerLoop: while (fileMarker !== 0xffd9) {
7005 let i, j, l;
7006 switch (fileMarker) {
7007 case 0xffe0:
7008 case 0xffe1:
7009 case 0xffe2:
7010 case 0xffe3:
7011 case 0xffe4:
7012 case 0xffe5:
7013 case 0xffe6:
7014 case 0xffe7:
7015 case 0xffe8:
7016 case 0xffe9:
7017 case 0xffea:
7018 case 0xffeb:
7019 case 0xffec:
7020 case 0xffed:
7021 case 0xffee:
7022 case 0xffef:
7023 case 0xfffe:
7024 const appData = readDataBlock();
7025 if (fileMarker === 0xffe0) {
7026 if (appData[0] === 0x4a && appData[1] === 0x46 && appData[2] === 0x49 && appData[3] === 0x46 && appData[4] === 0) {
7027 jfif = {
7028 version: {
7029 major: appData[5],
7030 minor: appData[6]
7031 },
7032 densityUnits: appData[7],
7033 xDensity: appData[8] << 8 | appData[9],
7034 yDensity: appData[10] << 8 | appData[11],
7035 thumbWidth: appData[12],
7036 thumbHeight: appData[13],
7037 thumbData: appData.subarray(14, 14 + 3 * appData[12] * appData[13])
7038 };
7039 }
7040 }
7041 if (fileMarker === 0xffee) {
7042 if (appData[0] === 0x41 && appData[1] === 0x64 && appData[2] === 0x6f && appData[3] === 0x62 && appData[4] === 0x65) {
7043 adobe = {
7044 version: appData[5] << 8 | appData[6],
7045 flags0: appData[7] << 8 | appData[8],
7046 flags1: appData[9] << 8 | appData[10],
7047 transformCode: appData[11]
7048 };
7049 }
7050 }
7051 break;
7052 case 0xffdb:
7053 const quantizationTablesLength = readUint16(data, offset);
7054 offset += 2;
7055 const quantizationTablesEnd = quantizationTablesLength + offset - 2;
7056 let z;
7057 while (offset < quantizationTablesEnd) {
7058 const quantizationTableSpec = data[offset++];
7059 const tableData = new Uint16Array(64);
7060 if (quantizationTableSpec >> 4 === 0) {
7061 for (j = 0; j < 64; j++) {
7062 z = dctZigZag[j];
7063 tableData[z] = data[offset++];
7064 }
7065 } else if (quantizationTableSpec >> 4 === 1) {
7066 for (j = 0; j < 64; j++) {
7067 z = dctZigZag[j];
7068 tableData[z] = readUint16(data, offset);
7069 offset += 2;
7070 }
7071 } else {
7072 throw new JpegError("DQT - invalid table spec");
7073 }
7074 quantizationTables[quantizationTableSpec & 15] = tableData;
7075 }
7076 break;
7077 case 0xffc0:
7078 case 0xffc1:
7079 case 0xffc2:
7080 if (frame) {
7081 throw new JpegError("Only single frame JPEGs supported");
7082 }
7083 offset += 2;
7084 frame = {};
7085 frame.extended = fileMarker === 0xffc1;
7086 frame.progressive = fileMarker === 0xffc2;
7087 frame.precision = data[offset++];
7088 const sofScanLines = readUint16(data, offset);
7089 offset += 2;
7090 frame.scanLines = dnlScanLines || sofScanLines;
7091 frame.samplesPerLine = readUint16(data, offset);
7092 offset += 2;
7093 frame.components = [];
7094 frame.componentIds = {};
7095 const componentsCount = data[offset++];
7096 let maxH = 0,
7097 maxV = 0;
7098 for (i = 0; i < componentsCount; i++) {
7099 const componentId = data[offset];
7100 const h = data[offset + 1] >> 4;
7101 const v = data[offset + 1] & 15;
7102 if (maxH < h) {
7103 maxH = h;
7104 }
7105 if (maxV < v) {
7106 maxV = v;
7107 }
7108 const qId = data[offset + 2];
7109 l = frame.components.push({
7110 h,
7111 v,
7112 quantizationId: qId,
7113 quantizationTable: null
7114 });
7115 frame.componentIds[componentId] = l - 1;
7116 offset += 3;
7117 }
7118 frame.maxH = maxH;
7119 frame.maxV = maxV;
7120 prepareComponents(frame);
7121 break;
7122 case 0xffc4:
7123 const huffmanLength = readUint16(data, offset);
7124 offset += 2;
7125 for (i = 2; i < huffmanLength;) {
7126 const huffmanTableSpec = data[offset++];
7127 const codeLengths = new Uint8Array(16);
7128 let codeLengthSum = 0;
7129 for (j = 0; j < 16; j++, offset++) {
7130 codeLengthSum += codeLengths[j] = data[offset];
7131 }
7132 const huffmanValues = new Uint8Array(codeLengthSum);
7133 for (j = 0; j < codeLengthSum; j++, offset++) {
7134 huffmanValues[j] = data[offset];
7135 }
7136 i += 17 + codeLengthSum;
7137 (huffmanTableSpec >> 4 === 0 ? huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] = buildHuffmanTable(codeLengths, huffmanValues);
7138 }
7139 break;
7140 case 0xffdd:
7141 offset += 2;
7142 resetInterval = readUint16(data, offset);
7143 offset += 2;
7144 break;
7145 case 0xffda:
7146 const parseDNLMarker = ++numSOSMarkers === 1 && !dnlScanLines;
7147 offset += 2;
7148 const selectorsCount = data[offset++],
7149 components = [];
7150 for (i = 0; i < selectorsCount; i++) {
7151 const index = data[offset++];
7152 const componentIndex = frame.componentIds[index];
7153 const component = frame.components[componentIndex];
7154 component.index = index;
7155 const tableSpec = data[offset++];
7156 component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
7157 component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
7158 components.push(component);
7159 }
7160 const spectralStart = data[offset++],
7161 spectralEnd = data[offset++],
7162 successiveApproximation = data[offset++];
7163 try {
7164 const processed = decodeScan(data, offset, frame, components, resetInterval, spectralStart, spectralEnd, successiveApproximation >> 4, successiveApproximation & 15, parseDNLMarker);
7165 offset += processed;
7166 } catch (ex) {
7167 if (ex instanceof DNLMarkerError) {
7168 warn(`${ex.message} -- attempting to re-parse the JPEG image.`);
7169 return this.parse(data, {
7170 dnlScanLines: ex.scanLines
7171 });
7172 } else if (ex instanceof EOIMarkerError) {
7173 warn(`${ex.message} -- ignoring the rest of the image data.`);
7174 break markerLoop;
7175 }
7176 throw ex;
7177 }
7178 break;
7179 case 0xffdc:
7180 offset += 4;
7181 break;
7182 case 0xffff:
7183 if (data[offset] !== 0xff) {
7184 offset--;
7185 }
7186 break;
7187 default:
7188 const nextFileMarker = findNextFileMarker(data, offset - 2, offset - 3);
7189 if (nextFileMarker?.invalid) {
7190 warn("JpegImage.parse - unexpected data, current marker is: " + nextFileMarker.invalid);
7191 offset = nextFileMarker.offset;
7192 break;
7193 }
7194 if (!nextFileMarker || offset >= data.length - 1) {
7195 warn("JpegImage.parse - reached the end of the image data " + "without finding an EOI marker (0xFFD9).");
7196 break markerLoop;
7197 }
7198 throw new JpegError("JpegImage.parse - unknown marker: " + fileMarker.toString(16));
7199 }
7200 fileMarker = readUint16(data, offset);
7201 offset += 2;
7202 }
7203 if (!frame) {
7204 throw new JpegError("JpegImage.parse - no frame data found.");
7205 }
7206 this.width = frame.samplesPerLine;
7207 this.height = frame.scanLines;
7208 this.jfif = jfif;
7209 this.adobe = adobe;
7210 this.components = [];
7211 for (const component of frame.components) {
7212 const quantizationTable = quantizationTables[component.quantizationId];
7213 if (quantizationTable) {
7214 component.quantizationTable = quantizationTable;
7215 }
7216 this.components.push({
7217 index: component.index,
7218 output: buildComponentData(frame, component),
7219 scaleX: component.h / frame.maxH,
7220 scaleY: component.v / frame.maxV,
7221 blocksPerLine: component.blocksPerLine,
7222 blocksPerColumn: component.blocksPerColumn
7223 });
7224 }
7225 this.numComponents = this.components.length;
7226 return undefined;
7227 }
7228 _getLinearizedBlockData(width, height, isSourcePDF = false) {
7229 const scaleX = this.width / width,
7230 scaleY = this.height / height;
7231 let component, componentScaleX, componentScaleY, blocksPerScanline;
7232 let x, y, i, j, k;
7233 let index;
7234 let offset = 0;
7235 let output;
7236 const numComponents = this.components.length;
7237 const dataLength = width * height * numComponents;
7238 const data = new Uint8ClampedArray(dataLength);
7239 const xScaleBlockOffset = new Uint32Array(width);
7240 const mask3LSB = 0xfffffff8;
7241 let lastComponentScaleX;
7242 for (i = 0; i < numComponents; i++) {
7243 component = this.components[i];
7244 componentScaleX = component.scaleX * scaleX;
7245 componentScaleY = component.scaleY * scaleY;
7246 offset = i;
7247 output = component.output;
7248 blocksPerScanline = component.blocksPerLine + 1 << 3;
7249 if (componentScaleX !== lastComponentScaleX) {
7250 for (x = 0; x < width; x++) {
7251 j = 0 | x * componentScaleX;
7252 xScaleBlockOffset[x] = (j & mask3LSB) << 3 | j & 7;
7253 }
7254 lastComponentScaleX = componentScaleX;
7255 }
7256 for (y = 0; y < height; y++) {
7257 j = 0 | y * componentScaleY;
7258 index = blocksPerScanline * (j & mask3LSB) | (j & 7) << 3;
7259 for (x = 0; x < width; x++) {
7260 data[offset] = output[index + xScaleBlockOffset[x]];
7261 offset += numComponents;
7262 }
7263 }
7264 }
7265 let transform = this._decodeTransform;
7266 if (!isSourcePDF && numComponents === 4 && !transform) {
7267 transform = new Int32Array([-256, 255, -256, 255, -256, 255, -256, 255]);
7268 }
7269 if (transform) {
7270 for (i = 0; i < dataLength;) {
7271 for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
7272 data[i] = (data[i] * transform[k] >> 8) + transform[k + 1];
7273 }
7274 }
7275 }
7276 return data;
7277 }
7278 get _isColorConversionNeeded() {
7279 if (this.adobe) {
7280 return !!this.adobe.transformCode;
7281 }
7282 if (this.numComponents === 3) {
7283 if (this._colorTransform === 0) {
7284 return false;
7285 } else if (this.components[0].index === 0x52 && this.components[1].index === 0x47 && this.components[2].index === 0x42) {
7286 return false;
7287 }
7288 return true;
7289 }
7290 if (this._colorTransform === 1) {
7291 return true;
7292 }
7293 return false;
7294 }
7295 _convertYccToRgb(data) {
7296 let Y, Cb, Cr;
7297 for (let i = 0, length = data.length; i < length; i += 3) {
7298 Y = data[i];
7299 Cb = data[i + 1];
7300 Cr = data[i + 2];
7301 data[i] = Y - 179.456 + 1.402 * Cr;
7302 data[i + 1] = Y + 135.459 - 0.344 * Cb - 0.714 * Cr;
7303 data[i + 2] = Y - 226.816 + 1.772 * Cb;
7304 }
7305 return data;
7306 }
7307 _convertYccToRgba(data, out) {
7308 for (let i = 0, j = 0, length = data.length; i < length; i += 3, j += 4) {
7309 const Y = data[i];
7310 const Cb = data[i + 1];
7311 const Cr = data[i + 2];
7312 out[j] = Y - 179.456 + 1.402 * Cr;
7313 out[j + 1] = Y + 135.459 - 0.344 * Cb - 0.714 * Cr;
7314 out[j + 2] = Y - 226.816 + 1.772 * Cb;
7315 out[j + 3] = 255;
7316 }
7317 return out;
7318 }
7319 _convertYcckToRgb(data) {
7320 let Y, Cb, Cr, k;
7321 let offset = 0;
7322 for (let i = 0, length = data.length; i < length; i += 4) {
7323 Y = data[i];
7324 Cb = data[i + 1];
7325 Cr = data[i + 2];
7326 k = data[i + 3];
7327 data[offset++] = -122.67195406894 + Cb * (-6.60635669420364e-5 * Cb + 0.000437130475926232 * Cr - 5.4080610064599e-5 * Y + 0.00048449797120281 * k - 0.154362151871126) + Cr * (-0.000957964378445773 * Cr + 0.000817076911346625 * Y - 0.00477271405408747 * k + 1.53380253221734) + Y * (0.000961250184130688 * Y - 0.00266257332283933 * k + 0.48357088451265) + k * (-0.000336197177618394 * k + 0.484791561490776);
7328 data[offset++] = 107.268039397724 + Cb * (2.19927104525741e-5 * Cb - 0.000640992018297945 * Cr + 0.000659397001245577 * Y + 0.000426105652938837 * k - 0.176491792462875) + Cr * (-0.000778269941513683 * Cr + 0.00130872261408275 * Y + 0.000770482631801132 * k - 0.151051492775562) + Y * (0.00126935368114843 * Y - 0.00265090189010898 * k + 0.25802910206845) + k * (-0.000318913117588328 * k - 0.213742400323665);
7329 data[offset++] = -20.810012546947 + Cb * (-0.000570115196973677 * Cb - 2.63409051004589e-5 * Cr + 0.0020741088115012 * Y - 0.00288260236853442 * k + 0.814272968359295) + Cr * (-1.53496057440975e-5 * Cr - 0.000132689043961446 * Y + 0.000560833691242812 * k - 0.195152027534049) + Y * (0.00174418132927582 * Y - 0.00255243321439347 * k + 0.116935020465145) + k * (-0.000343531996510555 * k + 0.24165260232407);
7330 }
7331 return data.subarray(0, offset);
7332 }
7333 _convertYcckToRgba(data) {
7334 for (let i = 0, length = data.length; i < length; i += 4) {
7335 const Y = data[i];
7336 const Cb = data[i + 1];
7337 const Cr = data[i + 2];
7338 const k = data[i + 3];
7339 data[i] = -122.67195406894 + Cb * (-6.60635669420364e-5 * Cb + 0.000437130475926232 * Cr - 5.4080610064599e-5 * Y + 0.00048449797120281 * k - 0.154362151871126) + Cr * (-0.000957964378445773 * Cr + 0.000817076911346625 * Y - 0.00477271405408747 * k + 1.53380253221734) + Y * (0.000961250184130688 * Y - 0.00266257332283933 * k + 0.48357088451265) + k * (-0.000336197177618394 * k + 0.484791561490776);
7340 data[i + 1] = 107.268039397724 + Cb * (2.19927104525741e-5 * Cb - 0.000640992018297945 * Cr + 0.000659397001245577 * Y + 0.000426105652938837 * k - 0.176491792462875) + Cr * (-0.000778269941513683 * Cr + 0.00130872261408275 * Y + 0.000770482631801132 * k - 0.151051492775562) + Y * (0.00126935368114843 * Y - 0.00265090189010898 * k + 0.25802910206845) + k * (-0.000318913117588328 * k - 0.213742400323665);
7341 data[i + 2] = -20.810012546947 + Cb * (-0.000570115196973677 * Cb - 2.63409051004589e-5 * Cr + 0.0020741088115012 * Y - 0.00288260236853442 * k + 0.814272968359295) + Cr * (-1.53496057440975e-5 * Cr - 0.000132689043961446 * Y + 0.000560833691242812 * k - 0.195152027534049) + Y * (0.00174418132927582 * Y - 0.00255243321439347 * k + 0.116935020465145) + k * (-0.000343531996510555 * k + 0.24165260232407);
7342 data[i + 3] = 255;
7343 }
7344 return data;
7345 }
7346 _convertYcckToCmyk(data) {
7347 let Y, Cb, Cr;
7348 for (let i = 0, length = data.length; i < length; i += 4) {
7349 Y = data[i];
7350 Cb = data[i + 1];
7351 Cr = data[i + 2];
7352 data[i] = 434.456 - Y - 1.402 * Cr;
7353 data[i + 1] = 119.541 - Y + 0.344 * Cb + 0.714 * Cr;
7354 data[i + 2] = 481.816 - Y - 1.772 * Cb;
7355 }
7356 return data;
7357 }
7358 _convertCmykToRgb(data) {
7359 let c, m, y, k;
7360 let offset = 0;
7361 for (let i = 0, length = data.length; i < length; i += 4) {
7362 c = data[i];
7363 m = data[i + 1];
7364 y = data[i + 2];
7365 k = data[i + 3];
7366 data[offset++] = 255 + c * (-0.00006747147073602441 * c + 0.0008379262121013727 * m + 0.0002894718188643294 * y + 0.003264231057537806 * k - 1.1185611867203937) + m * (0.000026374107616089405 * m - 0.00008626949158638572 * y - 0.0002748769067499491 * k - 0.02155688794978967) + y * (-0.00003878099212869363 * y - 0.0003267808279485286 * k + 0.0686742238595345) - k * (0.0003361971776183937 * k + 0.7430659151342254);
7367 data[offset++] = 255 + c * (0.00013596372813588848 * c + 0.000924537132573585 * m + 0.00010567359618683593 * y + 0.0004791864687436512 * k - 0.3109689587515875) + m * (-0.00023545346108370344 * m + 0.0002702845253534714 * y + 0.0020200308977307156 * k - 0.7488052167015494) + y * (0.00006834815998235662 * y + 0.00015168452363460973 * k - 0.09751927774728933) - k * (0.0003189131175883281 * k + 0.7364883807733168);
7368 data[offset++] = 255 + c * (0.000013598650411385307 * c + 0.00012423956175490851 * m + 0.0004751985097583589 * y - 0.0000036729317476630422 * k - 0.05562186980264034) + m * (0.00016141380598724676 * m + 0.0009692239130725186 * y + 0.0007782692450036253 * k - 0.44015232367526463) + y * (5.068882914068769e-7 * y + 0.0017778369011375071 * k - 0.7591454649749609) - k * (0.0003435319965105553 * k + 0.7063770186160144);
7369 }
7370 return data.subarray(0, offset);
7371 }
7372 _convertCmykToRgba(data) {
7373 for (let i = 0, length = data.length; i < length; i += 4) {
7374 const c = data[i];
7375 const m = data[i + 1];
7376 const y = data[i + 2];
7377 const k = data[i + 3];
7378 data[i] = 255 + c * (-0.00006747147073602441 * c + 0.0008379262121013727 * m + 0.0002894718188643294 * y + 0.003264231057537806 * k - 1.1185611867203937) + m * (0.000026374107616089405 * m - 0.00008626949158638572 * y - 0.0002748769067499491 * k - 0.02155688794978967) + y * (-0.00003878099212869363 * y - 0.0003267808279485286 * k + 0.0686742238595345) - k * (0.0003361971776183937 * k + 0.7430659151342254);
7379 data[i + 1] = 255 + c * (0.00013596372813588848 * c + 0.000924537132573585 * m + 0.00010567359618683593 * y + 0.0004791864687436512 * k - 0.3109689587515875) + m * (-0.00023545346108370344 * m + 0.0002702845253534714 * y + 0.0020200308977307156 * k - 0.7488052167015494) + y * (0.00006834815998235662 * y + 0.00015168452363460973 * k - 0.09751927774728933) - k * (0.0003189131175883281 * k + 0.7364883807733168);
7380 data[i + 2] = 255 + c * (0.000013598650411385307 * c + 0.00012423956175490851 * m + 0.0004751985097583589 * y - 0.0000036729317476630422 * k - 0.05562186980264034) + m * (0.00016141380598724676 * m + 0.0009692239130725186 * y + 0.0007782692450036253 * k - 0.44015232367526463) + y * (5.068882914068769e-7 * y + 0.0017778369011375071 * k - 0.7591454649749609) - k * (0.0003435319965105553 * k + 0.7063770186160144);
7381 data[i + 3] = 255;
7382 }
7383 return data;
7384 }
7385 getData({
7386 width,
7387 height,
7388 forceRGBA = false,
7389 forceRGB = false,
7390 isSourcePDF = false
7391 }) {
7392 if (this.numComponents > 4) {
7393 throw new JpegError("Unsupported color mode");
7394 }
7395 const data = this._getLinearizedBlockData(width, height, isSourcePDF);
7396 if (this.numComponents === 1 && (forceRGBA || forceRGB)) {
7397 const len = data.length * (forceRGBA ? 4 : 3);
7398 const rgbaData = new Uint8ClampedArray(len);
7399 let offset = 0;
7400 if (forceRGBA) {
7401 grayToRGBA(data, new Uint32Array(rgbaData.buffer));
7402 } else {
7403 for (const grayColor of data) {
7404 rgbaData[offset++] = grayColor;
7405 rgbaData[offset++] = grayColor;
7406 rgbaData[offset++] = grayColor;
7407 }
7408 }
7409 return rgbaData;
7410 } else if (this.numComponents === 3 && this._isColorConversionNeeded) {
7411 if (forceRGBA) {
7412 const rgbaData = new Uint8ClampedArray(data.length / 3 * 4);
7413 return this._convertYccToRgba(data, rgbaData);
7414 }
7415 return this._convertYccToRgb(data);
7416 } else if (this.numComponents === 4) {
7417 if (this._isColorConversionNeeded) {
7418 if (forceRGBA) {
7419 return this._convertYcckToRgba(data);
7420 }
7421 if (forceRGB) {
7422 return this._convertYcckToRgb(data);
7423 }
7424 return this._convertYcckToCmyk(data);
7425 } else if (forceRGBA) {
7426 return this._convertCmykToRgba(data);
7427 } else if (forceRGB) {
7428 return this._convertCmykToRgb(data);
7429 }
7430 }
7431 return data;
7432 }
7433}
7434
7435;// CONCATENATED MODULE: ./src/core/jpeg_stream.js
7436
7437
7438
7439
7440class JpegStream extends DecodeStream {
7441 constructor(stream, maybeLength, params) {
7442 let ch;
7443 while ((ch = stream.getByte()) !== -1) {
7444 if (ch === 0xff) {
7445 stream.skip(-1);
7446 break;
7447 }
7448 }
7449 super(maybeLength);
7450 this.stream = stream;
7451 this.dict = stream.dict;
7452 this.maybeLength = maybeLength;
7453 this.params = params;
7454 }
7455 get bytes() {
7456 return shadow(this, "bytes", this.stream.getBytes(this.maybeLength));
7457 }
7458 ensureBuffer(requested) {}
7459 readBlock() {
7460 if (this.eof) {
7461 return;
7462 }
7463 const jpegOptions = {
7464 decodeTransform: undefined,
7465 colorTransform: undefined
7466 };
7467 const decodeArr = this.dict.getArray("D", "Decode");
7468 if ((this.forceRGBA || this.forceRGB) && Array.isArray(decodeArr)) {
7469 const bitsPerComponent = this.dict.get("BPC", "BitsPerComponent") || 8;
7470 const decodeArrLength = decodeArr.length;
7471 const transform = new Int32Array(decodeArrLength);
7472 let transformNeeded = false;
7473 const maxValue = (1 << bitsPerComponent) - 1;
7474 for (let i = 0; i < decodeArrLength; i += 2) {
7475 transform[i] = (decodeArr[i + 1] - decodeArr[i]) * 256 | 0;
7476 transform[i + 1] = decodeArr[i] * maxValue | 0;
7477 if (transform[i] !== 256 || transform[i + 1] !== 0) {
7478 transformNeeded = true;
7479 }
7480 }
7481 if (transformNeeded) {
7482 jpegOptions.decodeTransform = transform;
7483 }
7484 }
7485 if (this.params instanceof Dict) {
7486 const colorTransform = this.params.get("ColorTransform");
7487 if (Number.isInteger(colorTransform)) {
7488 jpegOptions.colorTransform = colorTransform;
7489 }
7490 }
7491 const jpegImage = new JpegImage(jpegOptions);
7492 jpegImage.parse(this.bytes);
7493 const data = jpegImage.getData({
7494 width: this.drawWidth,
7495 height: this.drawHeight,
7496 forceRGBA: this.forceRGBA,
7497 forceRGB: this.forceRGB,
7498 isSourcePDF: true
7499 });
7500 this.buffer = data;
7501 this.bufferLength = data.length;
7502 this.eof = true;
7503 }
7504}
7505
7506;// CONCATENATED MODULE: ./src/core/jpx.js
7507
7508
7509
7510class JpxError extends BaseException {
7511 constructor(msg) {
7512 super(`JPX error: ${msg}`, "JpxError");
7513 }
7514}
7515const SubbandsGainLog2 = {
7516 LL: 0,
7517 LH: 1,
7518 HL: 1,
7519 HH: 2
7520};
7521class JpxImage {
7522 constructor() {
7523 this.failOnCorruptedImage = false;
7524 }
7525 parse(data) {
7526 const head = readUint16(data, 0);
7527 if (head === 0xff4f) {
7528 this.parseCodestream(data, 0, data.length);
7529 return;
7530 }
7531 const length = data.length;
7532 let position = 0;
7533 while (position < length) {
7534 let headerSize = 8;
7535 let lbox = readUint32(data, position);
7536 const tbox = readUint32(data, position + 4);
7537 position += headerSize;
7538 if (lbox === 1) {
7539 lbox = readUint32(data, position) * 4294967296 + readUint32(data, position + 4);
7540 position += 8;
7541 headerSize += 8;
7542 }
7543 if (lbox === 0) {
7544 lbox = length - position + headerSize;
7545 }
7546 if (lbox < headerSize) {
7547 throw new JpxError("Invalid box field size");
7548 }
7549 const dataLength = lbox - headerSize;
7550 let jumpDataLength = true;
7551 switch (tbox) {
7552 case 0x6a703268:
7553 jumpDataLength = false;
7554 break;
7555 case 0x636f6c72:
7556 const method = data[position];
7557 if (method === 1) {
7558 const colorspace = readUint32(data, position + 3);
7559 switch (colorspace) {
7560 case 16:
7561 case 17:
7562 case 18:
7563 break;
7564 default:
7565 warn("Unknown colorspace " + colorspace);
7566 break;
7567 }
7568 } else if (method === 2) {
7569 info("ICC profile not supported");
7570 }
7571 break;
7572 case 0x6a703263:
7573 this.parseCodestream(data, position, position + dataLength);
7574 break;
7575 case 0x6a502020:
7576 if (readUint32(data, position) !== 0x0d0a870a) {
7577 warn("Invalid JP2 signature");
7578 }
7579 break;
7580 case 0x6a501a1a:
7581 case 0x66747970:
7582 case 0x72726571:
7583 case 0x72657320:
7584 case 0x69686472:
7585 break;
7586 default:
7587 const headerType = String.fromCharCode(tbox >> 24 & 0xff, tbox >> 16 & 0xff, tbox >> 8 & 0xff, tbox & 0xff);
7588 warn(`Unsupported header type ${tbox} (${headerType}).`);
7589 break;
7590 }
7591 if (jumpDataLength) {
7592 position += dataLength;
7593 }
7594 }
7595 }
7596 parseImageProperties(stream) {
7597 let newByte = stream.getByte();
7598 while (newByte >= 0) {
7599 const oldByte = newByte;
7600 newByte = stream.getByte();
7601 const code = oldByte << 8 | newByte;
7602 if (code === 0xff51) {
7603 stream.skip(4);
7604 const Xsiz = stream.getInt32() >>> 0;
7605 const Ysiz = stream.getInt32() >>> 0;
7606 const XOsiz = stream.getInt32() >>> 0;
7607 const YOsiz = stream.getInt32() >>> 0;
7608 stream.skip(16);
7609 const Csiz = stream.getUint16();
7610 this.width = Xsiz - XOsiz;
7611 this.height = Ysiz - YOsiz;
7612 this.componentsCount = Csiz;
7613 this.bitsPerComponent = 8;
7614 return;
7615 }
7616 }
7617 throw new JpxError("No size marker found in JPX stream");
7618 }
7619 parseCodestream(data, start, end) {
7620 const context = {};
7621 let doNotRecover = false;
7622 try {
7623 let position = start;
7624 while (position + 1 < end) {
7625 const code = readUint16(data, position);
7626 position += 2;
7627 let length = 0,
7628 j,
7629 sqcd,
7630 spqcds,
7631 spqcdSize,
7632 scalarExpounded,
7633 tile;
7634 switch (code) {
7635 case 0xff4f:
7636 context.mainHeader = true;
7637 break;
7638 case 0xffd9:
7639 break;
7640 case 0xff51:
7641 length = readUint16(data, position);
7642 const siz = {};
7643 siz.Xsiz = readUint32(data, position + 4);
7644 siz.Ysiz = readUint32(data, position + 8);
7645 siz.XOsiz = readUint32(data, position + 12);
7646 siz.YOsiz = readUint32(data, position + 16);
7647 siz.XTsiz = readUint32(data, position + 20);
7648 siz.YTsiz = readUint32(data, position + 24);
7649 siz.XTOsiz = readUint32(data, position + 28);
7650 siz.YTOsiz = readUint32(data, position + 32);
7651 const componentsCount = readUint16(data, position + 36);
7652 siz.Csiz = componentsCount;
7653 const components = [];
7654 j = position + 38;
7655 for (let i = 0; i < componentsCount; i++) {
7656 const component = {
7657 precision: (data[j] & 0x7f) + 1,
7658 isSigned: !!(data[j] & 0x80),
7659 XRsiz: data[j + 1],
7660 YRsiz: data[j + 2]
7661 };
7662 j += 3;
7663 calculateComponentDimensions(component, siz);
7664 components.push(component);
7665 }
7666 context.SIZ = siz;
7667 context.components = components;
7668 calculateTileGrids(context, components);
7669 context.QCC = [];
7670 context.COC = [];
7671 break;
7672 case 0xff5c:
7673 length = readUint16(data, position);
7674 const qcd = {};
7675 j = position + 2;
7676 sqcd = data[j++];
7677 switch (sqcd & 0x1f) {
7678 case 0:
7679 spqcdSize = 8;
7680 scalarExpounded = true;
7681 break;
7682 case 1:
7683 spqcdSize = 16;
7684 scalarExpounded = false;
7685 break;
7686 case 2:
7687 spqcdSize = 16;
7688 scalarExpounded = true;
7689 break;
7690 default:
7691 throw new Error("Invalid SQcd value " + sqcd);
7692 }
7693 qcd.noQuantization = spqcdSize === 8;
7694 qcd.scalarExpounded = scalarExpounded;
7695 qcd.guardBits = sqcd >> 5;
7696 spqcds = [];
7697 while (j < length + position) {
7698 const spqcd = {};
7699 if (spqcdSize === 8) {
7700 spqcd.epsilon = data[j++] >> 3;
7701 spqcd.mu = 0;
7702 } else {
7703 spqcd.epsilon = data[j] >> 3;
7704 spqcd.mu = (data[j] & 0x7) << 8 | data[j + 1];
7705 j += 2;
7706 }
7707 spqcds.push(spqcd);
7708 }
7709 qcd.SPqcds = spqcds;
7710 if (context.mainHeader) {
7711 context.QCD = qcd;
7712 } else {
7713 context.currentTile.QCD = qcd;
7714 context.currentTile.QCC = [];
7715 }
7716 break;
7717 case 0xff5d:
7718 length = readUint16(data, position);
7719 const qcc = {};
7720 j = position + 2;
7721 let cqcc;
7722 if (context.SIZ.Csiz < 257) {
7723 cqcc = data[j++];
7724 } else {
7725 cqcc = readUint16(data, j);
7726 j += 2;
7727 }
7728 sqcd = data[j++];
7729 switch (sqcd & 0x1f) {
7730 case 0:
7731 spqcdSize = 8;
7732 scalarExpounded = true;
7733 break;
7734 case 1:
7735 spqcdSize = 16;
7736 scalarExpounded = false;
7737 break;
7738 case 2:
7739 spqcdSize = 16;
7740 scalarExpounded = true;
7741 break;
7742 default:
7743 throw new Error("Invalid SQcd value " + sqcd);
7744 }
7745 qcc.noQuantization = spqcdSize === 8;
7746 qcc.scalarExpounded = scalarExpounded;
7747 qcc.guardBits = sqcd >> 5;
7748 spqcds = [];
7749 while (j < length + position) {
7750 const spqcd = {};
7751 if (spqcdSize === 8) {
7752 spqcd.epsilon = data[j++] >> 3;
7753 spqcd.mu = 0;
7754 } else {
7755 spqcd.epsilon = data[j] >> 3;
7756 spqcd.mu = (data[j] & 0x7) << 8 | data[j + 1];
7757 j += 2;
7758 }
7759 spqcds.push(spqcd);
7760 }
7761 qcc.SPqcds = spqcds;
7762 if (context.mainHeader) {
7763 context.QCC[cqcc] = qcc;
7764 } else {
7765 context.currentTile.QCC[cqcc] = qcc;
7766 }
7767 break;
7768 case 0xff52:
7769 length = readUint16(data, position);
7770 const cod = {};
7771 j = position + 2;
7772 const scod = data[j++];
7773 cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
7774 cod.sopMarkerUsed = !!(scod & 2);
7775 cod.ephMarkerUsed = !!(scod & 4);
7776 cod.progressionOrder = data[j++];
7777 cod.layersCount = readUint16(data, j);
7778 j += 2;
7779 cod.multipleComponentTransform = data[j++];
7780 cod.decompositionLevelsCount = data[j++];
7781 cod.xcb = (data[j++] & 0xf) + 2;
7782 cod.ycb = (data[j++] & 0xf) + 2;
7783 const blockStyle = data[j++];
7784 cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
7785 cod.resetContextProbabilities = !!(blockStyle & 2);
7786 cod.terminationOnEachCodingPass = !!(blockStyle & 4);
7787 cod.verticallyStripe = !!(blockStyle & 8);
7788 cod.predictableTermination = !!(blockStyle & 16);
7789 cod.segmentationSymbolUsed = !!(blockStyle & 32);
7790 cod.reversibleTransformation = data[j++];
7791 if (cod.entropyCoderWithCustomPrecincts) {
7792 const precinctsSizes = [];
7793 while (j < length + position) {
7794 const precinctsSize = data[j++];
7795 precinctsSizes.push({
7796 PPx: precinctsSize & 0xf,
7797 PPy: precinctsSize >> 4
7798 });
7799 }
7800 cod.precinctsSizes = precinctsSizes;
7801 }
7802 const unsupported = [];
7803 if (cod.selectiveArithmeticCodingBypass) {
7804 unsupported.push("selectiveArithmeticCodingBypass");
7805 }
7806 if (cod.terminationOnEachCodingPass) {
7807 unsupported.push("terminationOnEachCodingPass");
7808 }
7809 if (cod.verticallyStripe) {
7810 unsupported.push("verticallyStripe");
7811 }
7812 if (cod.predictableTermination) {
7813 unsupported.push("predictableTermination");
7814 }
7815 if (unsupported.length > 0) {
7816 doNotRecover = true;
7817 warn(`JPX: Unsupported COD options (${unsupported.join(", ")}).`);
7818 }
7819 if (context.mainHeader) {
7820 context.COD = cod;
7821 } else {
7822 context.currentTile.COD = cod;
7823 context.currentTile.COC = [];
7824 }
7825 break;
7826 case 0xff90:
7827 length = readUint16(data, position);
7828 tile = {};
7829 tile.index = readUint16(data, position + 2);
7830 tile.length = readUint32(data, position + 4);
7831 tile.dataEnd = tile.length + position - 2;
7832 tile.partIndex = data[position + 8];
7833 tile.partsCount = data[position + 9];
7834 context.mainHeader = false;
7835 if (tile.partIndex === 0) {
7836 tile.COD = context.COD;
7837 tile.COC = context.COC.slice(0);
7838 tile.QCD = context.QCD;
7839 tile.QCC = context.QCC.slice(0);
7840 }
7841 context.currentTile = tile;
7842 break;
7843 case 0xff93:
7844 tile = context.currentTile;
7845 if (tile.partIndex === 0) {
7846 initializeTile(context, tile.index);
7847 buildPackets(context);
7848 }
7849 length = tile.dataEnd - position;
7850 parseTilePackets(context, data, position, length);
7851 break;
7852 case 0xff53:
7853 warn("JPX: Codestream code 0xFF53 (COC) is not implemented.");
7854 case 0xff55:
7855 case 0xff57:
7856 case 0xff58:
7857 case 0xff64:
7858 length = readUint16(data, position);
7859 break;
7860 default:
7861 throw new Error("Unknown codestream code: " + code.toString(16));
7862 }
7863 position += length;
7864 }
7865 } catch (e) {
7866 if (doNotRecover || this.failOnCorruptedImage) {
7867 throw new JpxError(e.message);
7868 } else {
7869 warn(`JPX: Trying to recover from: "${e.message}".`);
7870 }
7871 }
7872 this.tiles = transformComponents(context);
7873 this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
7874 this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
7875 this.componentsCount = context.SIZ.Csiz;
7876 }
7877}
7878function calculateComponentDimensions(component, siz) {
7879 component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
7880 component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
7881 component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
7882 component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
7883 component.width = component.x1 - component.x0;
7884 component.height = component.y1 - component.y0;
7885}
7886function calculateTileGrids(context, components) {
7887 const siz = context.SIZ;
7888 const tiles = [];
7889 let tile;
7890 const numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
7891 const numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
7892 for (let q = 0; q < numYtiles; q++) {
7893 for (let p = 0; p < numXtiles; p++) {
7894 tile = {};
7895 tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
7896 tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
7897 tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
7898 tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
7899 tile.width = tile.tx1 - tile.tx0;
7900 tile.height = tile.ty1 - tile.ty0;
7901 tile.components = [];
7902 tiles.push(tile);
7903 }
7904 }
7905 context.tiles = tiles;
7906 const componentsCount = siz.Csiz;
7907 for (let i = 0, ii = componentsCount; i < ii; i++) {
7908 const component = components[i];
7909 for (let j = 0, jj = tiles.length; j < jj; j++) {
7910 const tileComponent = {};
7911 tile = tiles[j];
7912 tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
7913 tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
7914 tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
7915 tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
7916 tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
7917 tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
7918 tile.components[i] = tileComponent;
7919 }
7920 }
7921}
7922function getBlocksDimensions(context, component, r) {
7923 const codOrCoc = component.codingStyleParameters;
7924 const result = {};
7925 if (!codOrCoc.entropyCoderWithCustomPrecincts) {
7926 result.PPx = 15;
7927 result.PPy = 15;
7928 } else {
7929 result.PPx = codOrCoc.precinctsSizes[r].PPx;
7930 result.PPy = codOrCoc.precinctsSizes[r].PPy;
7931 }
7932 result.xcb_ = r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) : Math.min(codOrCoc.xcb, result.PPx);
7933 result.ycb_ = r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) : Math.min(codOrCoc.ycb, result.PPy);
7934 return result;
7935}
7936function buildPrecincts(context, resolution, dimensions) {
7937 const precinctWidth = 1 << dimensions.PPx;
7938 const precinctHeight = 1 << dimensions.PPy;
7939 const isZeroRes = resolution.resLevel === 0;
7940 const precinctWidthInSubband = 1 << dimensions.PPx + (isZeroRes ? 0 : -1);
7941 const precinctHeightInSubband = 1 << dimensions.PPy + (isZeroRes ? 0 : -1);
7942 const numprecinctswide = resolution.trx1 > resolution.trx0 ? Math.ceil(resolution.trx1 / precinctWidth) - Math.floor(resolution.trx0 / precinctWidth) : 0;
7943 const numprecinctshigh = resolution.try1 > resolution.try0 ? Math.ceil(resolution.try1 / precinctHeight) - Math.floor(resolution.try0 / precinctHeight) : 0;
7944 const numprecincts = numprecinctswide * numprecinctshigh;
7945 resolution.precinctParameters = {
7946 precinctWidth,
7947 precinctHeight,
7948 numprecinctswide,
7949 numprecinctshigh,
7950 numprecincts,
7951 precinctWidthInSubband,
7952 precinctHeightInSubband
7953 };
7954}
7955function buildCodeblocks(context, subband, dimensions) {
7956 const xcb_ = dimensions.xcb_;
7957 const ycb_ = dimensions.ycb_;
7958 const codeblockWidth = 1 << xcb_;
7959 const codeblockHeight = 1 << ycb_;
7960 const cbx0 = subband.tbx0 >> xcb_;
7961 const cby0 = subband.tby0 >> ycb_;
7962 const cbx1 = subband.tbx1 + codeblockWidth - 1 >> xcb_;
7963 const cby1 = subband.tby1 + codeblockHeight - 1 >> ycb_;
7964 const precinctParameters = subband.resolution.precinctParameters;
7965 const codeblocks = [];
7966 const precincts = [];
7967 let i, j, codeblock, precinctNumber;
7968 for (j = cby0; j < cby1; j++) {
7969 for (i = cbx0; i < cbx1; i++) {
7970 codeblock = {
7971 cbx: i,
7972 cby: j,
7973 tbx0: codeblockWidth * i,
7974 tby0: codeblockHeight * j,
7975 tbx1: codeblockWidth * (i + 1),
7976 tby1: codeblockHeight * (j + 1)
7977 };
7978 codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
7979 codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
7980 codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
7981 codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
7982 const pi = Math.floor((codeblock.tbx0_ - subband.tbx0) / precinctParameters.precinctWidthInSubband);
7983 const pj = Math.floor((codeblock.tby0_ - subband.tby0) / precinctParameters.precinctHeightInSubband);
7984 precinctNumber = pi + pj * precinctParameters.numprecinctswide;
7985 codeblock.precinctNumber = precinctNumber;
7986 codeblock.subbandType = subband.type;
7987 codeblock.Lblock = 3;
7988 if (codeblock.tbx1_ <= codeblock.tbx0_ || codeblock.tby1_ <= codeblock.tby0_) {
7989 continue;
7990 }
7991 codeblocks.push(codeblock);
7992 let precinct = precincts[precinctNumber];
7993 if (precinct !== undefined) {
7994 if (i < precinct.cbxMin) {
7995 precinct.cbxMin = i;
7996 } else if (i > precinct.cbxMax) {
7997 precinct.cbxMax = i;
7998 }
7999 if (j < precinct.cbyMin) {
8000 precinct.cbxMin = j;
8001 } else if (j > precinct.cbyMax) {
8002 precinct.cbyMax = j;
8003 }
8004 } else {
8005 precincts[precinctNumber] = precinct = {
8006 cbxMin: i,
8007 cbyMin: j,
8008 cbxMax: i,
8009 cbyMax: j
8010 };
8011 }
8012 codeblock.precinct = precinct;
8013 }
8014 }
8015 subband.codeblockParameters = {
8016 codeblockWidth: xcb_,
8017 codeblockHeight: ycb_,
8018 numcodeblockwide: cbx1 - cbx0 + 1,
8019 numcodeblockhigh: cby1 - cby0 + 1
8020 };
8021 subband.codeblocks = codeblocks;
8022 subband.precincts = precincts;
8023}
8024function createPacket(resolution, precinctNumber, layerNumber) {
8025 const precinctCodeblocks = [];
8026 const subbands = resolution.subbands;
8027 for (let i = 0, ii = subbands.length; i < ii; i++) {
8028 const subband = subbands[i];
8029 const codeblocks = subband.codeblocks;
8030 for (let j = 0, jj = codeblocks.length; j < jj; j++) {
8031 const codeblock = codeblocks[j];
8032 if (codeblock.precinctNumber !== precinctNumber) {
8033 continue;
8034 }
8035 precinctCodeblocks.push(codeblock);
8036 }
8037 }
8038 return {
8039 layerNumber,
8040 codeblocks: precinctCodeblocks
8041 };
8042}
8043function LayerResolutionComponentPositionIterator(context) {
8044 const siz = context.SIZ;
8045 const tileIndex = context.currentTile.index;
8046 const tile = context.tiles[tileIndex];
8047 const layersCount = tile.codingStyleDefaultParameters.layersCount;
8048 const componentsCount = siz.Csiz;
8049 let maxDecompositionLevelsCount = 0;
8050 for (let q = 0; q < componentsCount; q++) {
8051 maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount, tile.components[q].codingStyleParameters.decompositionLevelsCount);
8052 }
8053 let l = 0,
8054 r = 0,
8055 i = 0,
8056 k = 0;
8057 this.nextPacket = function JpxImage_nextPacket() {
8058 for (; l < layersCount; l++) {
8059 for (; r <= maxDecompositionLevelsCount; r++) {
8060 for (; i < componentsCount; i++) {
8061 const component = tile.components[i];
8062 if (r > component.codingStyleParameters.decompositionLevelsCount) {
8063 continue;
8064 }
8065 const resolution = component.resolutions[r];
8066 const numprecincts = resolution.precinctParameters.numprecincts;
8067 for (; k < numprecincts;) {
8068 const packet = createPacket(resolution, k, l);
8069 k++;
8070 return packet;
8071 }
8072 k = 0;
8073 }
8074 i = 0;
8075 }
8076 r = 0;
8077 }
8078 throw new JpxError("Out of packets");
8079 };
8080}
8081function ResolutionLayerComponentPositionIterator(context) {
8082 const siz = context.SIZ;
8083 const tileIndex = context.currentTile.index;
8084 const tile = context.tiles[tileIndex];
8085 const layersCount = tile.codingStyleDefaultParameters.layersCount;
8086 const componentsCount = siz.Csiz;
8087 let maxDecompositionLevelsCount = 0;
8088 for (let q = 0; q < componentsCount; q++) {
8089 maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount, tile.components[q].codingStyleParameters.decompositionLevelsCount);
8090 }
8091 let r = 0,
8092 l = 0,
8093 i = 0,
8094 k = 0;
8095 this.nextPacket = function JpxImage_nextPacket() {
8096 for (; r <= maxDecompositionLevelsCount; r++) {
8097 for (; l < layersCount; l++) {
8098 for (; i < componentsCount; i++) {
8099 const component = tile.components[i];
8100 if (r > component.codingStyleParameters.decompositionLevelsCount) {
8101 continue;
8102 }
8103 const resolution = component.resolutions[r];
8104 const numprecincts = resolution.precinctParameters.numprecincts;
8105 for (; k < numprecincts;) {
8106 const packet = createPacket(resolution, k, l);
8107 k++;
8108 return packet;
8109 }
8110 k = 0;
8111 }
8112 i = 0;
8113 }
8114 l = 0;
8115 }
8116 throw new JpxError("Out of packets");
8117 };
8118}
8119function ResolutionPositionComponentLayerIterator(context) {
8120 const siz = context.SIZ;
8121 const tileIndex = context.currentTile.index;
8122 const tile = context.tiles[tileIndex];
8123 const layersCount = tile.codingStyleDefaultParameters.layersCount;
8124 const componentsCount = siz.Csiz;
8125 let l, r, c, p;
8126 let maxDecompositionLevelsCount = 0;
8127 for (c = 0; c < componentsCount; c++) {
8128 const component = tile.components[c];
8129 maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount, component.codingStyleParameters.decompositionLevelsCount);
8130 }
8131 const maxNumPrecinctsInLevel = new Int32Array(maxDecompositionLevelsCount + 1);
8132 for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
8133 let maxNumPrecincts = 0;
8134 for (c = 0; c < componentsCount; ++c) {
8135 const resolutions = tile.components[c].resolutions;
8136 if (r < resolutions.length) {
8137 maxNumPrecincts = Math.max(maxNumPrecincts, resolutions[r].precinctParameters.numprecincts);
8138 }
8139 }
8140 maxNumPrecinctsInLevel[r] = maxNumPrecincts;
8141 }
8142 l = 0;
8143 r = 0;
8144 c = 0;
8145 p = 0;
8146 this.nextPacket = function JpxImage_nextPacket() {
8147 for (; r <= maxDecompositionLevelsCount; r++) {
8148 for (; p < maxNumPrecinctsInLevel[r]; p++) {
8149 for (; c < componentsCount; c++) {
8150 const component = tile.components[c];
8151 if (r > component.codingStyleParameters.decompositionLevelsCount) {
8152 continue;
8153 }
8154 const resolution = component.resolutions[r];
8155 const numprecincts = resolution.precinctParameters.numprecincts;
8156 if (p >= numprecincts) {
8157 continue;
8158 }
8159 for (; l < layersCount;) {
8160 const packet = createPacket(resolution, p, l);
8161 l++;
8162 return packet;
8163 }
8164 l = 0;
8165 }
8166 c = 0;
8167 }
8168 p = 0;
8169 }
8170 throw new JpxError("Out of packets");
8171 };
8172}
8173function PositionComponentResolutionLayerIterator(context) {
8174 const siz = context.SIZ;
8175 const tileIndex = context.currentTile.index;
8176 const tile = context.tiles[tileIndex];
8177 const layersCount = tile.codingStyleDefaultParameters.layersCount;
8178 const componentsCount = siz.Csiz;
8179 const precinctsSizes = getPrecinctSizesInImageScale(tile);
8180 const precinctsIterationSizes = precinctsSizes;
8181 let l = 0,
8182 r = 0,
8183 c = 0,
8184 px = 0,
8185 py = 0;
8186 this.nextPacket = function JpxImage_nextPacket() {
8187 for (; py < precinctsIterationSizes.maxNumHigh; py++) {
8188 for (; px < precinctsIterationSizes.maxNumWide; px++) {
8189 for (; c < componentsCount; c++) {
8190 const component = tile.components[c];
8191 const decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount;
8192 for (; r <= decompositionLevelsCount; r++) {
8193 const resolution = component.resolutions[r];
8194 const sizeInImageScale = precinctsSizes.components[c].resolutions[r];
8195 const k = getPrecinctIndexIfExist(px, py, sizeInImageScale, precinctsIterationSizes, resolution);
8196 if (k === null) {
8197 continue;
8198 }
8199 for (; l < layersCount;) {
8200 const packet = createPacket(resolution, k, l);
8201 l++;
8202 return packet;
8203 }
8204 l = 0;
8205 }
8206 r = 0;
8207 }
8208 c = 0;
8209 }
8210 px = 0;
8211 }
8212 throw new JpxError("Out of packets");
8213 };
8214}
8215function ComponentPositionResolutionLayerIterator(context) {
8216 const siz = context.SIZ;
8217 const tileIndex = context.currentTile.index;
8218 const tile = context.tiles[tileIndex];
8219 const layersCount = tile.codingStyleDefaultParameters.layersCount;
8220 const componentsCount = siz.Csiz;
8221 const precinctsSizes = getPrecinctSizesInImageScale(tile);
8222 let l = 0,
8223 r = 0,
8224 c = 0,
8225 px = 0,
8226 py = 0;
8227 this.nextPacket = function JpxImage_nextPacket() {
8228 for (; c < componentsCount; ++c) {
8229 const component = tile.components[c];
8230 const precinctsIterationSizes = precinctsSizes.components[c];
8231 const decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount;
8232 for (; py < precinctsIterationSizes.maxNumHigh; py++) {
8233 for (; px < precinctsIterationSizes.maxNumWide; px++) {
8234 for (; r <= decompositionLevelsCount; r++) {
8235 const resolution = component.resolutions[r];
8236 const sizeInImageScale = precinctsIterationSizes.resolutions[r];
8237 const k = getPrecinctIndexIfExist(px, py, sizeInImageScale, precinctsIterationSizes, resolution);
8238 if (k === null) {
8239 continue;
8240 }
8241 for (; l < layersCount;) {
8242 const packet = createPacket(resolution, k, l);
8243 l++;
8244 return packet;
8245 }
8246 l = 0;
8247 }
8248 r = 0;
8249 }
8250 px = 0;
8251 }
8252 py = 0;
8253 }
8254 throw new JpxError("Out of packets");
8255 };
8256}
8257function getPrecinctIndexIfExist(pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
8258 const posX = pxIndex * precinctIterationSizes.minWidth;
8259 const posY = pyIndex * precinctIterationSizes.minHeight;
8260 if (posX % sizeInImageScale.width !== 0 || posY % sizeInImageScale.height !== 0) {
8261 return null;
8262 }
8263 const startPrecinctRowIndex = posY / sizeInImageScale.width * resolution.precinctParameters.numprecinctswide;
8264 return posX / sizeInImageScale.height + startPrecinctRowIndex;
8265}
8266function getPrecinctSizesInImageScale(tile) {
8267 const componentsCount = tile.components.length;
8268 let minWidth = Number.MAX_VALUE;
8269 let minHeight = Number.MAX_VALUE;
8270 let maxNumWide = 0;
8271 let maxNumHigh = 0;
8272 const sizePerComponent = new Array(componentsCount);
8273 for (let c = 0; c < componentsCount; c++) {
8274 const component = tile.components[c];
8275 const decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount;
8276 const sizePerResolution = new Array(decompositionLevelsCount + 1);
8277 let minWidthCurrentComponent = Number.MAX_VALUE;
8278 let minHeightCurrentComponent = Number.MAX_VALUE;
8279 let maxNumWideCurrentComponent = 0;
8280 let maxNumHighCurrentComponent = 0;
8281 let scale = 1;
8282 for (let r = decompositionLevelsCount; r >= 0; --r) {
8283 const resolution = component.resolutions[r];
8284 const widthCurrentResolution = scale * resolution.precinctParameters.precinctWidth;
8285 const heightCurrentResolution = scale * resolution.precinctParameters.precinctHeight;
8286 minWidthCurrentComponent = Math.min(minWidthCurrentComponent, widthCurrentResolution);
8287 minHeightCurrentComponent = Math.min(minHeightCurrentComponent, heightCurrentResolution);
8288 maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent, resolution.precinctParameters.numprecinctswide);
8289 maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent, resolution.precinctParameters.numprecinctshigh);
8290 sizePerResolution[r] = {
8291 width: widthCurrentResolution,
8292 height: heightCurrentResolution
8293 };
8294 scale <<= 1;
8295 }
8296 minWidth = Math.min(minWidth, minWidthCurrentComponent);
8297 minHeight = Math.min(minHeight, minHeightCurrentComponent);
8298 maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
8299 maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
8300 sizePerComponent[c] = {
8301 resolutions: sizePerResolution,
8302 minWidth: minWidthCurrentComponent,
8303 minHeight: minHeightCurrentComponent,
8304 maxNumWide: maxNumWideCurrentComponent,
8305 maxNumHigh: maxNumHighCurrentComponent
8306 };
8307 }
8308 return {
8309 components: sizePerComponent,
8310 minWidth,
8311 minHeight,
8312 maxNumWide,
8313 maxNumHigh
8314 };
8315}
8316function buildPackets(context) {
8317 const siz = context.SIZ;
8318 const tileIndex = context.currentTile.index;
8319 const tile = context.tiles[tileIndex];
8320 const componentsCount = siz.Csiz;
8321 for (let c = 0; c < componentsCount; c++) {
8322 const component = tile.components[c];
8323 const decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount;
8324 const resolutions = [];
8325 const subbands = [];
8326 for (let r = 0; r <= decompositionLevelsCount; r++) {
8327 const blocksDimensions = getBlocksDimensions(context, component, r);
8328 const resolution = {};
8329 const scale = 1 << decompositionLevelsCount - r;
8330 resolution.trx0 = Math.ceil(component.tcx0 / scale);
8331 resolution.try0 = Math.ceil(component.tcy0 / scale);
8332 resolution.trx1 = Math.ceil(component.tcx1 / scale);
8333 resolution.try1 = Math.ceil(component.tcy1 / scale);
8334 resolution.resLevel = r;
8335 buildPrecincts(context, resolution, blocksDimensions);
8336 resolutions.push(resolution);
8337 let subband;
8338 if (r === 0) {
8339 subband = {};
8340 subband.type = "LL";
8341 subband.tbx0 = Math.ceil(component.tcx0 / scale);
8342 subband.tby0 = Math.ceil(component.tcy0 / scale);
8343 subband.tbx1 = Math.ceil(component.tcx1 / scale);
8344 subband.tby1 = Math.ceil(component.tcy1 / scale);
8345 subband.resolution = resolution;
8346 buildCodeblocks(context, subband, blocksDimensions);
8347 subbands.push(subband);
8348 resolution.subbands = [subband];
8349 } else {
8350 const bscale = 1 << decompositionLevelsCount - r + 1;
8351 const resolutionSubbands = [];
8352 subband = {};
8353 subband.type = "HL";
8354 subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
8355 subband.tby0 = Math.ceil(component.tcy0 / bscale);
8356 subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
8357 subband.tby1 = Math.ceil(component.tcy1 / bscale);
8358 subband.resolution = resolution;
8359 buildCodeblocks(context, subband, blocksDimensions);
8360 subbands.push(subband);
8361 resolutionSubbands.push(subband);
8362 subband = {};
8363 subband.type = "LH";
8364 subband.tbx0 = Math.ceil(component.tcx0 / bscale);
8365 subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
8366 subband.tbx1 = Math.ceil(component.tcx1 / bscale);
8367 subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
8368 subband.resolution = resolution;
8369 buildCodeblocks(context, subband, blocksDimensions);
8370 subbands.push(subband);
8371 resolutionSubbands.push(subband);
8372 subband = {};
8373 subband.type = "HH";
8374 subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
8375 subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
8376 subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
8377 subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
8378 subband.resolution = resolution;
8379 buildCodeblocks(context, subband, blocksDimensions);
8380 subbands.push(subband);
8381 resolutionSubbands.push(subband);
8382 resolution.subbands = resolutionSubbands;
8383 }
8384 }
8385 component.resolutions = resolutions;
8386 component.subbands = subbands;
8387 }
8388 const progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
8389 switch (progressionOrder) {
8390 case 0:
8391 tile.packetsIterator = new LayerResolutionComponentPositionIterator(context);
8392 break;
8393 case 1:
8394 tile.packetsIterator = new ResolutionLayerComponentPositionIterator(context);
8395 break;
8396 case 2:
8397 tile.packetsIterator = new ResolutionPositionComponentLayerIterator(context);
8398 break;
8399 case 3:
8400 tile.packetsIterator = new PositionComponentResolutionLayerIterator(context);
8401 break;
8402 case 4:
8403 tile.packetsIterator = new ComponentPositionResolutionLayerIterator(context);
8404 break;
8405 default:
8406 throw new JpxError(`Unsupported progression order ${progressionOrder}`);
8407 }
8408}
8409function parseTilePackets(context, data, offset, dataLength) {
8410 let position = 0;
8411 let buffer,
8412 bufferSize = 0,
8413 skipNextBit = false;
8414 function readBits(count) {
8415 while (bufferSize < count) {
8416 const b = data[offset + position];
8417 position++;
8418 if (skipNextBit) {
8419 buffer = buffer << 7 | b;
8420 bufferSize += 7;
8421 skipNextBit = false;
8422 } else {
8423 buffer = buffer << 8 | b;
8424 bufferSize += 8;
8425 }
8426 if (b === 0xff) {
8427 skipNextBit = true;
8428 }
8429 }
8430 bufferSize -= count;
8431 return buffer >>> bufferSize & (1 << count) - 1;
8432 }
8433 function skipMarkerIfEqual(value) {
8434 if (data[offset + position - 1] === 0xff && data[offset + position] === value) {
8435 skipBytes(1);
8436 return true;
8437 } else if (data[offset + position] === 0xff && data[offset + position + 1] === value) {
8438 skipBytes(2);
8439 return true;
8440 }
8441 return false;
8442 }
8443 function skipBytes(count) {
8444 position += count;
8445 }
8446 function alignToByte() {
8447 bufferSize = 0;
8448 if (skipNextBit) {
8449 position++;
8450 skipNextBit = false;
8451 }
8452 }
8453 function readCodingpasses() {
8454 if (readBits(1) === 0) {
8455 return 1;
8456 }
8457 if (readBits(1) === 0) {
8458 return 2;
8459 }
8460 let value = readBits(2);
8461 if (value < 3) {
8462 return value + 3;
8463 }
8464 value = readBits(5);
8465 if (value < 31) {
8466 return value + 6;
8467 }
8468 value = readBits(7);
8469 return value + 37;
8470 }
8471 const tileIndex = context.currentTile.index;
8472 const tile = context.tiles[tileIndex];
8473 const sopMarkerUsed = context.COD.sopMarkerUsed;
8474 const ephMarkerUsed = context.COD.ephMarkerUsed;
8475 const packetsIterator = tile.packetsIterator;
8476 while (position < dataLength) {
8477 alignToByte();
8478 if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
8479 skipBytes(4);
8480 }
8481 const packet = packetsIterator.nextPacket();
8482 if (!readBits(1)) {
8483 continue;
8484 }
8485 const layerNumber = packet.layerNumber,
8486 queue = [];
8487 let codeblock;
8488 for (let i = 0, ii = packet.codeblocks.length; i < ii; i++) {
8489 codeblock = packet.codeblocks[i];
8490 let precinct = codeblock.precinct;
8491 const codeblockColumn = codeblock.cbx - precinct.cbxMin;
8492 const codeblockRow = codeblock.cby - precinct.cbyMin;
8493 let codeblockIncluded = false;
8494 let firstTimeInclusion = false;
8495 let valueReady, zeroBitPlanesTree;
8496 if (codeblock.included !== undefined) {
8497 codeblockIncluded = !!readBits(1);
8498 } else {
8499 precinct = codeblock.precinct;
8500 let inclusionTree;
8501 if (precinct.inclusionTree !== undefined) {
8502 inclusionTree = precinct.inclusionTree;
8503 } else {
8504 const width = precinct.cbxMax - precinct.cbxMin + 1;
8505 const height = precinct.cbyMax - precinct.cbyMin + 1;
8506 inclusionTree = new InclusionTree(width, height, layerNumber);
8507 zeroBitPlanesTree = new TagTree(width, height);
8508 precinct.inclusionTree = inclusionTree;
8509 precinct.zeroBitPlanesTree = zeroBitPlanesTree;
8510 for (let l = 0; l < layerNumber; l++) {
8511 if (readBits(1) !== 0) {
8512 throw new JpxError("Invalid tag tree");
8513 }
8514 }
8515 }
8516 if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
8517 while (true) {
8518 if (readBits(1)) {
8519 valueReady = !inclusionTree.nextLevel();
8520 if (valueReady) {
8521 codeblock.included = true;
8522 codeblockIncluded = firstTimeInclusion = true;
8523 break;
8524 }
8525 } else {
8526 inclusionTree.incrementValue(layerNumber);
8527 break;
8528 }
8529 }
8530 }
8531 }
8532 if (!codeblockIncluded) {
8533 continue;
8534 }
8535 if (firstTimeInclusion) {
8536 zeroBitPlanesTree = precinct.zeroBitPlanesTree;
8537 zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
8538 while (true) {
8539 if (readBits(1)) {
8540 valueReady = !zeroBitPlanesTree.nextLevel();
8541 if (valueReady) {
8542 break;
8543 }
8544 } else {
8545 zeroBitPlanesTree.incrementValue();
8546 }
8547 }
8548 codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
8549 }
8550 const codingpasses = readCodingpasses();
8551 while (readBits(1)) {
8552 codeblock.Lblock++;
8553 }
8554 const codingpassesLog2 = log2(codingpasses);
8555 const bits = (codingpasses < 1 << codingpassesLog2 ? codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
8556 const codedDataLength = readBits(bits);
8557 queue.push({
8558 codeblock,
8559 codingpasses,
8560 dataLength: codedDataLength
8561 });
8562 }
8563 alignToByte();
8564 if (ephMarkerUsed) {
8565 skipMarkerIfEqual(0x92);
8566 }
8567 while (queue.length > 0) {
8568 const packetItem = queue.shift();
8569 codeblock = packetItem.codeblock;
8570 if (codeblock.data === undefined) {
8571 codeblock.data = [];
8572 }
8573 codeblock.data.push({
8574 data,
8575 start: offset + position,
8576 end: offset + position + packetItem.dataLength,
8577 codingpasses: packetItem.codingpasses
8578 });
8579 position += packetItem.dataLength;
8580 }
8581 }
8582 return position;
8583}
8584function copyCoefficients(coefficients, levelWidth, levelHeight, subband, delta, mb, reversible, segmentationSymbolUsed, resetContextProbabilities) {
8585 const x0 = subband.tbx0;
8586 const y0 = subband.tby0;
8587 const width = subband.tbx1 - subband.tbx0;
8588 const codeblocks = subband.codeblocks;
8589 const right = subband.type.charAt(0) === "H" ? 1 : 0;
8590 const bottom = subband.type.charAt(1) === "H" ? levelWidth : 0;
8591 for (let i = 0, ii = codeblocks.length; i < ii; ++i) {
8592 const codeblock = codeblocks[i];
8593 const blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
8594 const blockHeight = codeblock.tby1_ - codeblock.tby0_;
8595 if (blockWidth === 0 || blockHeight === 0) {
8596 continue;
8597 }
8598 if (codeblock.data === undefined) {
8599 continue;
8600 }
8601 const bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType, codeblock.zeroBitPlanes, mb);
8602 let currentCodingpassType = 2;
8603 const data = codeblock.data;
8604 let totalLength = 0,
8605 codingpasses = 0;
8606 let j, jj, dataItem;
8607 for (j = 0, jj = data.length; j < jj; j++) {
8608 dataItem = data[j];
8609 totalLength += dataItem.end - dataItem.start;
8610 codingpasses += dataItem.codingpasses;
8611 }
8612 const encodedData = new Uint8Array(totalLength);
8613 let position = 0;
8614 for (j = 0, jj = data.length; j < jj; j++) {
8615 dataItem = data[j];
8616 const chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
8617 encodedData.set(chunk, position);
8618 position += chunk.length;
8619 }
8620 const decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
8621 bitModel.setDecoder(decoder);
8622 for (j = 0; j < codingpasses; j++) {
8623 switch (currentCodingpassType) {
8624 case 0:
8625 bitModel.runSignificancePropagationPass();
8626 break;
8627 case 1:
8628 bitModel.runMagnitudeRefinementPass();
8629 break;
8630 case 2:
8631 bitModel.runCleanupPass();
8632 if (segmentationSymbolUsed) {
8633 bitModel.checkSegmentationSymbol();
8634 }
8635 break;
8636 }
8637 if (resetContextProbabilities) {
8638 bitModel.reset();
8639 }
8640 currentCodingpassType = (currentCodingpassType + 1) % 3;
8641 }
8642 let offset = codeblock.tbx0_ - x0 + (codeblock.tby0_ - y0) * width;
8643 const sign = bitModel.coefficentsSign;
8644 const magnitude = bitModel.coefficentsMagnitude;
8645 const bitsDecoded = bitModel.bitsDecoded;
8646 const magnitudeCorrection = reversible ? 0 : 0.5;
8647 let k, n, nb;
8648 position = 0;
8649 const interleave = subband.type !== "LL";
8650 for (j = 0; j < blockHeight; j++) {
8651 const row = offset / width | 0;
8652 const levelOffset = 2 * row * (levelWidth - width) + right + bottom;
8653 for (k = 0; k < blockWidth; k++) {
8654 n = magnitude[position];
8655 if (n !== 0) {
8656 n = (n + magnitudeCorrection) * delta;
8657 if (sign[position] !== 0) {
8658 n = -n;
8659 }
8660 nb = bitsDecoded[position];
8661 const pos = interleave ? levelOffset + (offset << 1) : offset;
8662 coefficients[pos] = reversible && nb >= mb ? n : n * (1 << mb - nb);
8663 }
8664 offset++;
8665 position++;
8666 }
8667 offset += width - blockWidth;
8668 }
8669 }
8670}
8671function transformTile(context, tile, c) {
8672 const component = tile.components[c];
8673 const codingStyleParameters = component.codingStyleParameters;
8674 const quantizationParameters = component.quantizationParameters;
8675 const decompositionLevelsCount = codingStyleParameters.decompositionLevelsCount;
8676 const spqcds = quantizationParameters.SPqcds;
8677 const scalarExpounded = quantizationParameters.scalarExpounded;
8678 const guardBits = quantizationParameters.guardBits;
8679 const segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
8680 const resetContextProbabilities = codingStyleParameters.resetContextProbabilities;
8681 const precision = context.components[c].precision;
8682 const reversible = codingStyleParameters.reversibleTransformation;
8683 const transform = reversible ? new ReversibleTransform() : new IrreversibleTransform();
8684 const subbandCoefficients = [];
8685 let b = 0;
8686 for (let i = 0; i <= decompositionLevelsCount; i++) {
8687 const resolution = component.resolutions[i];
8688 const width = resolution.trx1 - resolution.trx0;
8689 const height = resolution.try1 - resolution.try0;
8690 const coefficients = new Float32Array(width * height);
8691 for (let j = 0, jj = resolution.subbands.length; j < jj; j++) {
8692 let mu, epsilon;
8693 if (!scalarExpounded) {
8694 mu = spqcds[0].mu;
8695 epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
8696 } else {
8697 mu = spqcds[b].mu;
8698 epsilon = spqcds[b].epsilon;
8699 b++;
8700 }
8701 const subband = resolution.subbands[j];
8702 const gainLog2 = SubbandsGainLog2[subband.type];
8703 const delta = reversible ? 1 : 2 ** (precision + gainLog2 - epsilon) * (1 + mu / 2048);
8704 const mb = guardBits + epsilon - 1;
8705 copyCoefficients(coefficients, width, height, subband, delta, mb, reversible, segmentationSymbolUsed, resetContextProbabilities);
8706 }
8707 subbandCoefficients.push({
8708 width,
8709 height,
8710 items: coefficients
8711 });
8712 }
8713 const result = transform.calculate(subbandCoefficients, component.tcx0, component.tcy0);
8714 return {
8715 left: component.tcx0,
8716 top: component.tcy0,
8717 width: result.width,
8718 height: result.height,
8719 items: result.items
8720 };
8721}
8722function transformComponents(context) {
8723 const siz = context.SIZ;
8724 const components = context.components;
8725 const componentsCount = siz.Csiz;
8726 const resultImages = [];
8727 for (let i = 0, ii = context.tiles.length; i < ii; i++) {
8728 const tile = context.tiles[i];
8729 const transformedTiles = [];
8730 for (let c = 0; c < componentsCount; c++) {
8731 transformedTiles[c] = transformTile(context, tile, c);
8732 }
8733 const tile0 = transformedTiles[0];
8734 const out = new Uint8ClampedArray(tile0.items.length * componentsCount);
8735 const result = {
8736 left: tile0.left,
8737 top: tile0.top,
8738 width: tile0.width,
8739 height: tile0.height,
8740 items: out
8741 };
8742 let shift, offset;
8743 let pos = 0,
8744 j,
8745 jj,
8746 y0,
8747 y1,
8748 y2;
8749 if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
8750 const fourComponents = componentsCount === 4;
8751 const y0items = transformedTiles[0].items;
8752 const y1items = transformedTiles[1].items;
8753 const y2items = transformedTiles[2].items;
8754 const y3items = fourComponents ? transformedTiles[3].items : null;
8755 shift = components[0].precision - 8;
8756 offset = (128 << shift) + 0.5;
8757 const component0 = tile.components[0];
8758 const alpha01 = componentsCount - 3;
8759 jj = y0items.length;
8760 if (!component0.codingStyleParameters.reversibleTransformation) {
8761 for (j = 0; j < jj; j++, pos += alpha01) {
8762 y0 = y0items[j] + offset;
8763 y1 = y1items[j];
8764 y2 = y2items[j];
8765 out[pos++] = y0 + 1.402 * y2 >> shift;
8766 out[pos++] = y0 - 0.34413 * y1 - 0.71414 * y2 >> shift;
8767 out[pos++] = y0 + 1.772 * y1 >> shift;
8768 }
8769 } else {
8770 for (j = 0; j < jj; j++, pos += alpha01) {
8771 y0 = y0items[j] + offset;
8772 y1 = y1items[j];
8773 y2 = y2items[j];
8774 const g = y0 - (y2 + y1 >> 2);
8775 out[pos++] = g + y2 >> shift;
8776 out[pos++] = g >> shift;
8777 out[pos++] = g + y1 >> shift;
8778 }
8779 }
8780 if (fourComponents) {
8781 for (j = 0, pos = 3; j < jj; j++, pos += 4) {
8782 out[pos] = y3items[j] + offset >> shift;
8783 }
8784 }
8785 } else {
8786 for (let c = 0; c < componentsCount; c++) {
8787 const items = transformedTiles[c].items;
8788 shift = components[c].precision - 8;
8789 offset = (128 << shift) + 0.5;
8790 for (pos = c, j = 0, jj = items.length; j < jj; j++) {
8791 out[pos] = items[j] + offset >> shift;
8792 pos += componentsCount;
8793 }
8794 }
8795 }
8796 resultImages.push(result);
8797 }
8798 return resultImages;
8799}
8800function initializeTile(context, tileIndex) {
8801 const siz = context.SIZ;
8802 const componentsCount = siz.Csiz;
8803 const tile = context.tiles[tileIndex];
8804 for (let c = 0; c < componentsCount; c++) {
8805 const component = tile.components[c];
8806 const qcdOrQcc = context.currentTile.QCC[c] !== undefined ? context.currentTile.QCC[c] : context.currentTile.QCD;
8807 component.quantizationParameters = qcdOrQcc;
8808 const codOrCoc = context.currentTile.COC[c] !== undefined ? context.currentTile.COC[c] : context.currentTile.COD;
8809 component.codingStyleParameters = codOrCoc;
8810 }
8811 tile.codingStyleDefaultParameters = context.currentTile.COD;
8812}
8813class TagTree {
8814 constructor(width, height) {
8815 const levelsLength = log2(Math.max(width, height)) + 1;
8816 this.levels = [];
8817 for (let i = 0; i < levelsLength; i++) {
8818 const level = {
8819 width,
8820 height,
8821 items: []
8822 };
8823 this.levels.push(level);
8824 width = Math.ceil(width / 2);
8825 height = Math.ceil(height / 2);
8826 }
8827 }
8828 reset(i, j) {
8829 let currentLevel = 0,
8830 value = 0,
8831 level;
8832 while (currentLevel < this.levels.length) {
8833 level = this.levels[currentLevel];
8834 const index = i + j * level.width;
8835 if (level.items[index] !== undefined) {
8836 value = level.items[index];
8837 break;
8838 }
8839 level.index = index;
8840 i >>= 1;
8841 j >>= 1;
8842 currentLevel++;
8843 }
8844 currentLevel--;
8845 level = this.levels[currentLevel];
8846 level.items[level.index] = value;
8847 this.currentLevel = currentLevel;
8848 delete this.value;
8849 }
8850 incrementValue() {
8851 const level = this.levels[this.currentLevel];
8852 level.items[level.index]++;
8853 }
8854 nextLevel() {
8855 let currentLevel = this.currentLevel;
8856 let level = this.levels[currentLevel];
8857 const value = level.items[level.index];
8858 currentLevel--;
8859 if (currentLevel < 0) {
8860 this.value = value;
8861 return false;
8862 }
8863 this.currentLevel = currentLevel;
8864 level = this.levels[currentLevel];
8865 level.items[level.index] = value;
8866 return true;
8867 }
8868}
8869class InclusionTree {
8870 constructor(width, height, defaultValue) {
8871 const levelsLength = log2(Math.max(width, height)) + 1;
8872 this.levels = [];
8873 for (let i = 0; i < levelsLength; i++) {
8874 const items = new Uint8Array(width * height);
8875 for (let j = 0, jj = items.length; j < jj; j++) {
8876 items[j] = defaultValue;
8877 }
8878 const level = {
8879 width,
8880 height,
8881 items
8882 };
8883 this.levels.push(level);
8884 width = Math.ceil(width / 2);
8885 height = Math.ceil(height / 2);
8886 }
8887 }
8888 reset(i, j, stopValue) {
8889 let currentLevel = 0;
8890 while (currentLevel < this.levels.length) {
8891 const level = this.levels[currentLevel];
8892 const index = i + j * level.width;
8893 level.index = index;
8894 const value = level.items[index];
8895 if (value === 0xff) {
8896 break;
8897 }
8898 if (value > stopValue) {
8899 this.currentLevel = currentLevel;
8900 this.propagateValues();
8901 return false;
8902 }
8903 i >>= 1;
8904 j >>= 1;
8905 currentLevel++;
8906 }
8907 this.currentLevel = currentLevel - 1;
8908 return true;
8909 }
8910 incrementValue(stopValue) {
8911 const level = this.levels[this.currentLevel];
8912 level.items[level.index] = stopValue + 1;
8913 this.propagateValues();
8914 }
8915 propagateValues() {
8916 let levelIndex = this.currentLevel;
8917 let level = this.levels[levelIndex];
8918 const currentValue = level.items[level.index];
8919 while (--levelIndex >= 0) {
8920 level = this.levels[levelIndex];
8921 level.items[level.index] = currentValue;
8922 }
8923 }
8924 nextLevel() {
8925 let currentLevel = this.currentLevel;
8926 let level = this.levels[currentLevel];
8927 const value = level.items[level.index];
8928 level.items[level.index] = 0xff;
8929 currentLevel--;
8930 if (currentLevel < 0) {
8931 return false;
8932 }
8933 this.currentLevel = currentLevel;
8934 level = this.levels[currentLevel];
8935 level.items[level.index] = value;
8936 return true;
8937 }
8938}
8939class BitModel {
8940 static UNIFORM_CONTEXT = 17;
8941 static RUNLENGTH_CONTEXT = 18;
8942 static LLAndLHContextsLabel = new Uint8Array([0, 5, 8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 1, 6, 8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 2, 6, 8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 2, 6, 8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 2, 6, 8, 0, 3, 7, 8, 0, 4, 7, 8]);
8943 static HLContextLabel = new Uint8Array([0, 3, 4, 0, 5, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 1, 3, 4, 0, 6, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 2, 3, 4, 0, 6, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 2, 3, 4, 0, 6, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 2, 3, 4, 0, 6, 7, 7, 0, 8, 8, 8]);
8944 static HHContextLabel = new Uint8Array([0, 1, 2, 0, 1, 2, 2, 0, 2, 2, 2, 0, 0, 0, 0, 0, 3, 4, 5, 0, 4, 5, 5, 0, 5, 5, 5, 0, 0, 0, 0, 0, 6, 7, 7, 0, 7, 7, 7, 0, 7, 7, 7, 0, 0, 0, 0, 0, 8, 8, 8, 0, 8, 8, 8, 0, 8, 8, 8, 0, 0, 0, 0, 0, 8, 8, 8, 0, 8, 8, 8, 0, 8, 8, 8]);
8945 constructor(width, height, subband, zeroBitPlanes, mb) {
8946 this.width = width;
8947 this.height = height;
8948 let contextLabelTable;
8949 if (subband === "HH") {
8950 contextLabelTable = BitModel.HHContextLabel;
8951 } else if (subband === "HL") {
8952 contextLabelTable = BitModel.HLContextLabel;
8953 } else {
8954 contextLabelTable = BitModel.LLAndLHContextsLabel;
8955 }
8956 this.contextLabelTable = contextLabelTable;
8957 const coefficientCount = width * height;
8958 this.neighborsSignificance = new Uint8Array(coefficientCount);
8959 this.coefficentsSign = new Uint8Array(coefficientCount);
8960 let coefficentsMagnitude;
8961 if (mb > 14) {
8962 coefficentsMagnitude = new Uint32Array(coefficientCount);
8963 } else if (mb > 6) {
8964 coefficentsMagnitude = new Uint16Array(coefficientCount);
8965 } else {
8966 coefficentsMagnitude = new Uint8Array(coefficientCount);
8967 }
8968 this.coefficentsMagnitude = coefficentsMagnitude;
8969 this.processingFlags = new Uint8Array(coefficientCount);
8970 const bitsDecoded = new Uint8Array(coefficientCount);
8971 if (zeroBitPlanes !== 0) {
8972 for (let i = 0; i < coefficientCount; i++) {
8973 bitsDecoded[i] = zeroBitPlanes;
8974 }
8975 }
8976 this.bitsDecoded = bitsDecoded;
8977 this.reset();
8978 }
8979 setDecoder(decoder) {
8980 this.decoder = decoder;
8981 }
8982 reset() {
8983 this.contexts = new Int8Array(19);
8984 this.contexts[0] = 4 << 1 | 0;
8985 this.contexts[BitModel.UNIFORM_CONTEXT] = 46 << 1 | 0;
8986 this.contexts[BitModel.RUNLENGTH_CONTEXT] = 3 << 1 | 0;
8987 }
8988 setNeighborsSignificance(row, column, index) {
8989 const neighborsSignificance = this.neighborsSignificance;
8990 const width = this.width,
8991 height = this.height;
8992 const left = column > 0;
8993 const right = column + 1 < width;
8994 let i;
8995 if (row > 0) {
8996 i = index - width;
8997 if (left) {
8998 neighborsSignificance[i - 1] += 0x10;
8999 }
9000 if (right) {
9001 neighborsSignificance[i + 1] += 0x10;
9002 }
9003 neighborsSignificance[i] += 0x04;
9004 }
9005 if (row + 1 < height) {
9006 i = index + width;
9007 if (left) {
9008 neighborsSignificance[i - 1] += 0x10;
9009 }
9010 if (right) {
9011 neighborsSignificance[i + 1] += 0x10;
9012 }
9013 neighborsSignificance[i] += 0x04;
9014 }
9015 if (left) {
9016 neighborsSignificance[index - 1] += 0x01;
9017 }
9018 if (right) {
9019 neighborsSignificance[index + 1] += 0x01;
9020 }
9021 neighborsSignificance[index] |= 0x80;
9022 }
9023 runSignificancePropagationPass() {
9024 const decoder = this.decoder;
9025 const width = this.width,
9026 height = this.height;
9027 const coefficentsMagnitude = this.coefficentsMagnitude;
9028 const coefficentsSign = this.coefficentsSign;
9029 const neighborsSignificance = this.neighborsSignificance;
9030 const processingFlags = this.processingFlags;
9031 const contexts = this.contexts;
9032 const labels = this.contextLabelTable;
9033 const bitsDecoded = this.bitsDecoded;
9034 const processedInverseMask = ~1;
9035 const processedMask = 1;
9036 const firstMagnitudeBitMask = 2;
9037 for (let i0 = 0; i0 < height; i0 += 4) {
9038 for (let j = 0; j < width; j++) {
9039 let index = i0 * width + j;
9040 for (let i1 = 0; i1 < 4; i1++, index += width) {
9041 const i = i0 + i1;
9042 if (i >= height) {
9043 break;
9044 }
9045 processingFlags[index] &= processedInverseMask;
9046 if (coefficentsMagnitude[index] || !neighborsSignificance[index]) {
9047 continue;
9048 }
9049 const contextLabel = labels[neighborsSignificance[index]];
9050 const decision = decoder.readBit(contexts, contextLabel);
9051 if (decision) {
9052 const sign = this.decodeSignBit(i, j, index);
9053 coefficentsSign[index] = sign;
9054 coefficentsMagnitude[index] = 1;
9055 this.setNeighborsSignificance(i, j, index);
9056 processingFlags[index] |= firstMagnitudeBitMask;
9057 }
9058 bitsDecoded[index]++;
9059 processingFlags[index] |= processedMask;
9060 }
9061 }
9062 }
9063 }
9064 decodeSignBit(row, column, index) {
9065 const width = this.width,
9066 height = this.height;
9067 const coefficentsMagnitude = this.coefficentsMagnitude;
9068 const coefficentsSign = this.coefficentsSign;
9069 let contribution, sign0, sign1, significance1;
9070 let contextLabel, decoded;
9071 significance1 = column > 0 && coefficentsMagnitude[index - 1] !== 0;
9072 if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
9073 sign1 = coefficentsSign[index + 1];
9074 if (significance1) {
9075 sign0 = coefficentsSign[index - 1];
9076 contribution = 1 - sign1 - sign0;
9077 } else {
9078 contribution = 1 - sign1 - sign1;
9079 }
9080 } else if (significance1) {
9081 sign0 = coefficentsSign[index - 1];
9082 contribution = 1 - sign0 - sign0;
9083 } else {
9084 contribution = 0;
9085 }
9086 const horizontalContribution = 3 * contribution;
9087 significance1 = row > 0 && coefficentsMagnitude[index - width] !== 0;
9088 if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
9089 sign1 = coefficentsSign[index + width];
9090 if (significance1) {
9091 sign0 = coefficentsSign[index - width];
9092 contribution = 1 - sign1 - sign0 + horizontalContribution;
9093 } else {
9094 contribution = 1 - sign1 - sign1 + horizontalContribution;
9095 }
9096 } else if (significance1) {
9097 sign0 = coefficentsSign[index - width];
9098 contribution = 1 - sign0 - sign0 + horizontalContribution;
9099 } else {
9100 contribution = horizontalContribution;
9101 }
9102 if (contribution >= 0) {
9103 contextLabel = 9 + contribution;
9104 decoded = this.decoder.readBit(this.contexts, contextLabel);
9105 } else {
9106 contextLabel = 9 - contribution;
9107 decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
9108 }
9109 return decoded;
9110 }
9111 runMagnitudeRefinementPass() {
9112 const decoder = this.decoder;
9113 const width = this.width,
9114 height = this.height;
9115 const coefficentsMagnitude = this.coefficentsMagnitude;
9116 const neighborsSignificance = this.neighborsSignificance;
9117 const contexts = this.contexts;
9118 const bitsDecoded = this.bitsDecoded;
9119 const processingFlags = this.processingFlags;
9120 const processedMask = 1;
9121 const firstMagnitudeBitMask = 2;
9122 const length = width * height;
9123 const width4 = width * 4;
9124 for (let index0 = 0, indexNext; index0 < length; index0 = indexNext) {
9125 indexNext = Math.min(length, index0 + width4);
9126 for (let j = 0; j < width; j++) {
9127 for (let index = index0 + j; index < indexNext; index += width) {
9128 if (!coefficentsMagnitude[index] || (processingFlags[index] & processedMask) !== 0) {
9129 continue;
9130 }
9131 let contextLabel = 16;
9132 if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
9133 processingFlags[index] ^= firstMagnitudeBitMask;
9134 const significance = neighborsSignificance[index] & 127;
9135 contextLabel = significance === 0 ? 15 : 14;
9136 }
9137 const bit = decoder.readBit(contexts, contextLabel);
9138 coefficentsMagnitude[index] = coefficentsMagnitude[index] << 1 | bit;
9139 bitsDecoded[index]++;
9140 processingFlags[index] |= processedMask;
9141 }
9142 }
9143 }
9144 }
9145 runCleanupPass() {
9146 const decoder = this.decoder;
9147 const width = this.width,
9148 height = this.height;
9149 const neighborsSignificance = this.neighborsSignificance;
9150 const coefficentsMagnitude = this.coefficentsMagnitude;
9151 const coefficentsSign = this.coefficentsSign;
9152 const contexts = this.contexts;
9153 const labels = this.contextLabelTable;
9154 const bitsDecoded = this.bitsDecoded;
9155 const processingFlags = this.processingFlags;
9156 const processedMask = 1;
9157 const firstMagnitudeBitMask = 2;
9158 const oneRowDown = width;
9159 const twoRowsDown = width * 2;
9160 const threeRowsDown = width * 3;
9161 let iNext;
9162 for (let i0 = 0; i0 < height; i0 = iNext) {
9163 iNext = Math.min(i0 + 4, height);
9164 const indexBase = i0 * width;
9165 const checkAllEmpty = i0 + 3 < height;
9166 for (let j = 0; j < width; j++) {
9167 const index0 = indexBase + j;
9168 const allEmpty = checkAllEmpty && processingFlags[index0] === 0 && processingFlags[index0 + oneRowDown] === 0 && processingFlags[index0 + twoRowsDown] === 0 && processingFlags[index0 + threeRowsDown] === 0 && neighborsSignificance[index0] === 0 && neighborsSignificance[index0 + oneRowDown] === 0 && neighborsSignificance[index0 + twoRowsDown] === 0 && neighborsSignificance[index0 + threeRowsDown] === 0;
9169 let i1 = 0,
9170 index = index0;
9171 let i = i0,
9172 sign;
9173 if (allEmpty) {
9174 const hasSignificantCoefficent = decoder.readBit(contexts, BitModel.RUNLENGTH_CONTEXT);
9175 if (!hasSignificantCoefficent) {
9176 bitsDecoded[index0]++;
9177 bitsDecoded[index0 + oneRowDown]++;
9178 bitsDecoded[index0 + twoRowsDown]++;
9179 bitsDecoded[index0 + threeRowsDown]++;
9180 continue;
9181 }
9182 i1 = decoder.readBit(contexts, BitModel.UNIFORM_CONTEXT) << 1 | decoder.readBit(contexts, BitModel.UNIFORM_CONTEXT);
9183 if (i1 !== 0) {
9184 i = i0 + i1;
9185 index += i1 * width;
9186 }
9187 sign = this.decodeSignBit(i, j, index);
9188 coefficentsSign[index] = sign;
9189 coefficentsMagnitude[index] = 1;
9190 this.setNeighborsSignificance(i, j, index);
9191 processingFlags[index] |= firstMagnitudeBitMask;
9192 index = index0;
9193 for (let i2 = i0; i2 <= i; i2++, index += width) {
9194 bitsDecoded[index]++;
9195 }
9196 i1++;
9197 }
9198 for (i = i0 + i1; i < iNext; i++, index += width) {
9199 if (coefficentsMagnitude[index] || (processingFlags[index] & processedMask) !== 0) {
9200 continue;
9201 }
9202 const contextLabel = labels[neighborsSignificance[index]];
9203 const decision = decoder.readBit(contexts, contextLabel);
9204 if (decision === 1) {
9205 sign = this.decodeSignBit(i, j, index);
9206 coefficentsSign[index] = sign;
9207 coefficentsMagnitude[index] = 1;
9208 this.setNeighborsSignificance(i, j, index);
9209 processingFlags[index] |= firstMagnitudeBitMask;
9210 }
9211 bitsDecoded[index]++;
9212 }
9213 }
9214 }
9215 }
9216 checkSegmentationSymbol() {
9217 const decoder = this.decoder;
9218 const contexts = this.contexts;
9219 const symbol = decoder.readBit(contexts, BitModel.UNIFORM_CONTEXT) << 3 | decoder.readBit(contexts, BitModel.UNIFORM_CONTEXT) << 2 | decoder.readBit(contexts, BitModel.UNIFORM_CONTEXT) << 1 | decoder.readBit(contexts, BitModel.UNIFORM_CONTEXT);
9220 if (symbol !== 0xa) {
9221 throw new JpxError("Invalid segmentation symbol");
9222 }
9223 }
9224}
9225class Transform {
9226 constructor() {
9227 if (this.constructor === Transform) {
9228 unreachable("Cannot initialize Transform.");
9229 }
9230 }
9231 calculate(subbands, u0, v0) {
9232 let ll = subbands[0];
9233 for (let i = 1, ii = subbands.length; i < ii; i++) {
9234 ll = this.iterate(ll, subbands[i], u0, v0);
9235 }
9236 return ll;
9237 }
9238 extend(buffer, offset, size) {
9239 let i1 = offset - 1,
9240 j1 = offset + 1;
9241 let i2 = offset + size - 2,
9242 j2 = offset + size;
9243 buffer[i1--] = buffer[j1++];
9244 buffer[j2++] = buffer[i2--];
9245 buffer[i1--] = buffer[j1++];
9246 buffer[j2++] = buffer[i2--];
9247 buffer[i1--] = buffer[j1++];
9248 buffer[j2++] = buffer[i2--];
9249 buffer[i1] = buffer[j1];
9250 buffer[j2] = buffer[i2];
9251 }
9252 filter(x, offset, length) {
9253 unreachable("Abstract method `filter` called");
9254 }
9255 iterate(ll, hl_lh_hh, u0, v0) {
9256 const llWidth = ll.width,
9257 llHeight = ll.height;
9258 let llItems = ll.items;
9259 const width = hl_lh_hh.width;
9260 const height = hl_lh_hh.height;
9261 const items = hl_lh_hh.items;
9262 let i, j, k, l, u, v;
9263 for (k = 0, i = 0; i < llHeight; i++) {
9264 l = i * 2 * width;
9265 for (j = 0; j < llWidth; j++, k++, l += 2) {
9266 items[l] = llItems[k];
9267 }
9268 }
9269 llItems = ll.items = null;
9270 const bufferPadding = 4;
9271 const rowBuffer = new Float32Array(width + 2 * bufferPadding);
9272 if (width === 1) {
9273 if ((u0 & 1) !== 0) {
9274 for (v = 0, k = 0; v < height; v++, k += width) {
9275 items[k] *= 0.5;
9276 }
9277 }
9278 } else {
9279 for (v = 0, k = 0; v < height; v++, k += width) {
9280 rowBuffer.set(items.subarray(k, k + width), bufferPadding);
9281 this.extend(rowBuffer, bufferPadding, width);
9282 this.filter(rowBuffer, bufferPadding, width);
9283 items.set(rowBuffer.subarray(bufferPadding, bufferPadding + width), k);
9284 }
9285 }
9286 let numBuffers = 16;
9287 const colBuffers = [];
9288 for (i = 0; i < numBuffers; i++) {
9289 colBuffers.push(new Float32Array(height + 2 * bufferPadding));
9290 }
9291 let b,
9292 currentBuffer = 0;
9293 ll = bufferPadding + height;
9294 if (height === 1) {
9295 if ((v0 & 1) !== 0) {
9296 for (u = 0; u < width; u++) {
9297 items[u] *= 0.5;
9298 }
9299 }
9300 } else {
9301 for (u = 0; u < width; u++) {
9302 if (currentBuffer === 0) {
9303 numBuffers = Math.min(width - u, numBuffers);
9304 for (k = u, l = bufferPadding; l < ll; k += width, l++) {
9305 for (b = 0; b < numBuffers; b++) {
9306 colBuffers[b][l] = items[k + b];
9307 }
9308 }
9309 currentBuffer = numBuffers;
9310 }
9311 currentBuffer--;
9312 const buffer = colBuffers[currentBuffer];
9313 this.extend(buffer, bufferPadding, height);
9314 this.filter(buffer, bufferPadding, height);
9315 if (currentBuffer === 0) {
9316 k = u - numBuffers + 1;
9317 for (l = bufferPadding; l < ll; k += width, l++) {
9318 for (b = 0; b < numBuffers; b++) {
9319 items[k + b] = colBuffers[b][l];
9320 }
9321 }
9322 }
9323 }
9324 }
9325 return {
9326 width,
9327 height,
9328 items
9329 };
9330 }
9331}
9332class IrreversibleTransform extends Transform {
9333 filter(x, offset, length) {
9334 const len = length >> 1;
9335 offset |= 0;
9336 let j, n, current, next;
9337 const alpha = -1.586134342059924;
9338 const beta = -0.052980118572961;
9339 const gamma = 0.882911075530934;
9340 const delta = 0.443506852043971;
9341 const K = 1.230174104914001;
9342 const K_ = 1 / K;
9343 j = offset - 3;
9344 for (n = len + 4; n--; j += 2) {
9345 x[j] *= K_;
9346 }
9347 j = offset - 2;
9348 current = delta * x[j - 1];
9349 for (n = len + 3; n--; j += 2) {
9350 next = delta * x[j + 1];
9351 x[j] = K * x[j] - current - next;
9352 if (n--) {
9353 j += 2;
9354 current = delta * x[j + 1];
9355 x[j] = K * x[j] - current - next;
9356 } else {
9357 break;
9358 }
9359 }
9360 j = offset - 1;
9361 current = gamma * x[j - 1];
9362 for (n = len + 2; n--; j += 2) {
9363 next = gamma * x[j + 1];
9364 x[j] -= current + next;
9365 if (n--) {
9366 j += 2;
9367 current = gamma * x[j + 1];
9368 x[j] -= current + next;
9369 } else {
9370 break;
9371 }
9372 }
9373 j = offset;
9374 current = beta * x[j - 1];
9375 for (n = len + 1; n--; j += 2) {
9376 next = beta * x[j + 1];
9377 x[j] -= current + next;
9378 if (n--) {
9379 j += 2;
9380 current = beta * x[j + 1];
9381 x[j] -= current + next;
9382 } else {
9383 break;
9384 }
9385 }
9386 if (len !== 0) {
9387 j = offset + 1;
9388 current = alpha * x[j - 1];
9389 for (n = len; n--; j += 2) {
9390 next = alpha * x[j + 1];
9391 x[j] -= current + next;
9392 if (n--) {
9393 j += 2;
9394 current = alpha * x[j + 1];
9395 x[j] -= current + next;
9396 } else {
9397 break;
9398 }
9399 }
9400 }
9401 }
9402}
9403class ReversibleTransform extends Transform {
9404 filter(x, offset, length) {
9405 const len = length >> 1;
9406 offset |= 0;
9407 let j, n;
9408 for (j = offset, n = len + 1; n--; j += 2) {
9409 x[j] -= x[j - 1] + x[j + 1] + 2 >> 2;
9410 }
9411 for (j = offset + 1, n = len; n--; j += 2) {
9412 x[j] += x[j - 1] + x[j + 1] >> 1;
9413 }
9414 }
9415}
9416
9417;// CONCATENATED MODULE: ./src/core/jpx_stream.js
9418
9419
9420
9421class JpxStream extends DecodeStream {
9422 constructor(stream, maybeLength, params) {
9423 super(maybeLength);
9424 this.stream = stream;
9425 this.dict = stream.dict;
9426 this.maybeLength = maybeLength;
9427 this.params = params;
9428 }
9429 get bytes() {
9430 return shadow(this, "bytes", this.stream.getBytes(this.maybeLength));
9431 }
9432 ensureBuffer(requested) {}
9433 readBlock() {
9434 if (this.eof) {
9435 return;
9436 }
9437 const jpxImage = new JpxImage();
9438 jpxImage.parse(this.bytes);
9439 const width = jpxImage.width;
9440 const height = jpxImage.height;
9441 const componentsCount = jpxImage.componentsCount;
9442 const tileCount = jpxImage.tiles.length;
9443 if (tileCount === 1) {
9444 this.buffer = jpxImage.tiles[0].items;
9445 } else {
9446 const data = new Uint8ClampedArray(width * height * componentsCount);
9447 for (let k = 0; k < tileCount; k++) {
9448 const tileComponents = jpxImage.tiles[k];
9449 const tileWidth = tileComponents.width;
9450 const tileHeight = tileComponents.height;
9451 const tileLeft = tileComponents.left;
9452 const tileTop = tileComponents.top;
9453 const src = tileComponents.items;
9454 let srcPosition = 0;
9455 let dataPosition = (width * tileTop + tileLeft) * componentsCount;
9456 const imgRowSize = width * componentsCount;
9457 const tileRowSize = tileWidth * componentsCount;
9458 for (let j = 0; j < tileHeight; j++) {
9459 const rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
9460 data.set(rowBytes, dataPosition);
9461 srcPosition += tileRowSize;
9462 dataPosition += imgRowSize;
9463 }
9464 }
9465 this.buffer = data;
9466 }
9467 this.bufferLength = this.buffer.length;
9468 this.eof = true;
9469 }
9470}
9471
9472;// CONCATENATED MODULE: ./src/core/lzw_stream.js
9473
9474class LZWStream extends DecodeStream {
9475 constructor(str, maybeLength, earlyChange) {
9476 super(maybeLength);
9477 this.str = str;
9478 this.dict = str.dict;
9479 this.cachedData = 0;
9480 this.bitsCached = 0;
9481 const maxLzwDictionarySize = 4096;
9482 const lzwState = {
9483 earlyChange,
9484 codeLength: 9,
9485 nextCode: 258,
9486 dictionaryValues: new Uint8Array(maxLzwDictionarySize),
9487 dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
9488 dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
9489 currentSequence: new Uint8Array(maxLzwDictionarySize),
9490 currentSequenceLength: 0
9491 };
9492 for (let i = 0; i < 256; ++i) {
9493 lzwState.dictionaryValues[i] = i;
9494 lzwState.dictionaryLengths[i] = 1;
9495 }
9496 this.lzwState = lzwState;
9497 }
9498 readBits(n) {
9499 let bitsCached = this.bitsCached;
9500 let cachedData = this.cachedData;
9501 while (bitsCached < n) {
9502 const c = this.str.getByte();
9503 if (c === -1) {
9504 this.eof = true;
9505 return null;
9506 }
9507 cachedData = cachedData << 8 | c;
9508 bitsCached += 8;
9509 }
9510 this.bitsCached = bitsCached -= n;
9511 this.cachedData = cachedData;
9512 this.lastCode = null;
9513 return cachedData >>> bitsCached & (1 << n) - 1;
9514 }
9515 readBlock() {
9516 const blockSize = 512,
9517 decodedSizeDelta = blockSize;
9518 let estimatedDecodedSize = blockSize * 2;
9519 let i, j, q;
9520 const lzwState = this.lzwState;
9521 if (!lzwState) {
9522 return;
9523 }
9524 const earlyChange = lzwState.earlyChange;
9525 let nextCode = lzwState.nextCode;
9526 const dictionaryValues = lzwState.dictionaryValues;
9527 const dictionaryLengths = lzwState.dictionaryLengths;
9528 const dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
9529 let codeLength = lzwState.codeLength;
9530 let prevCode = lzwState.prevCode;
9531 const currentSequence = lzwState.currentSequence;
9532 let currentSequenceLength = lzwState.currentSequenceLength;
9533 let decodedLength = 0;
9534 let currentBufferLength = this.bufferLength;
9535 let buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
9536 for (i = 0; i < blockSize; i++) {
9537 const code = this.readBits(codeLength);
9538 const hasPrev = currentSequenceLength > 0;
9539 if (code < 256) {
9540 currentSequence[0] = code;
9541 currentSequenceLength = 1;
9542 } else if (code >= 258) {
9543 if (code < nextCode) {
9544 currentSequenceLength = dictionaryLengths[code];
9545 for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
9546 currentSequence[j] = dictionaryValues[q];
9547 q = dictionaryPrevCodes[q];
9548 }
9549 } else {
9550 currentSequence[currentSequenceLength++] = currentSequence[0];
9551 }
9552 } else if (code === 256) {
9553 codeLength = 9;
9554 nextCode = 258;
9555 currentSequenceLength = 0;
9556 continue;
9557 } else {
9558 this.eof = true;
9559 delete this.lzwState;
9560 break;
9561 }
9562 if (hasPrev) {
9563 dictionaryPrevCodes[nextCode] = prevCode;
9564 dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
9565 dictionaryValues[nextCode] = currentSequence[0];
9566 nextCode++;
9567 codeLength = nextCode + earlyChange & nextCode + earlyChange - 1 ? codeLength : Math.min(Math.log(nextCode + earlyChange) / 0.6931471805599453 + 1, 12) | 0;
9568 }
9569 prevCode = code;
9570 decodedLength += currentSequenceLength;
9571 if (estimatedDecodedSize < decodedLength) {
9572 do {
9573 estimatedDecodedSize += decodedSizeDelta;
9574 } while (estimatedDecodedSize < decodedLength);
9575 buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
9576 }
9577 for (j = 0; j < currentSequenceLength; j++) {
9578 buffer[currentBufferLength++] = currentSequence[j];
9579 }
9580 }
9581 lzwState.nextCode = nextCode;
9582 lzwState.codeLength = codeLength;
9583 lzwState.prevCode = prevCode;
9584 lzwState.currentSequenceLength = currentSequenceLength;
9585 this.bufferLength = currentBufferLength;
9586 }
9587}
9588
9589;// CONCATENATED MODULE: ./src/core/predictor_stream.js
9590
9591
9592
9593class PredictorStream extends DecodeStream {
9594 constructor(str, maybeLength, params) {
9595 super(maybeLength);
9596 if (!(params instanceof Dict)) {
9597 return str;
9598 }
9599 const predictor = this.predictor = params.get("Predictor") || 1;
9600 if (predictor <= 1) {
9601 return str;
9602 }
9603 if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
9604 throw new FormatError(`Unsupported predictor: ${predictor}`);
9605 }
9606 this.readBlock = predictor === 2 ? this.readBlockTiff : this.readBlockPng;
9607 this.str = str;
9608 this.dict = str.dict;
9609 const colors = this.colors = params.get("Colors") || 1;
9610 const bits = this.bits = params.get("BPC", "BitsPerComponent") || 8;
9611 const columns = this.columns = params.get("Columns") || 1;
9612 this.pixBytes = colors * bits + 7 >> 3;
9613 this.rowBytes = columns * colors * bits + 7 >> 3;
9614 return this;
9615 }
9616 readBlockTiff() {
9617 const rowBytes = this.rowBytes;
9618 const bufferLength = this.bufferLength;
9619 const buffer = this.ensureBuffer(bufferLength + rowBytes);
9620 const bits = this.bits;
9621 const colors = this.colors;
9622 const rawBytes = this.str.getBytes(rowBytes);
9623 this.eof = !rawBytes.length;
9624 if (this.eof) {
9625 return;
9626 }
9627 let inbuf = 0,
9628 outbuf = 0;
9629 let inbits = 0,
9630 outbits = 0;
9631 let pos = bufferLength;
9632 let i;
9633 if (bits === 1 && colors === 1) {
9634 for (i = 0; i < rowBytes; ++i) {
9635 let c = rawBytes[i] ^ inbuf;
9636 c ^= c >> 1;
9637 c ^= c >> 2;
9638 c ^= c >> 4;
9639 inbuf = (c & 1) << 7;
9640 buffer[pos++] = c;
9641 }
9642 } else if (bits === 8) {
9643 for (i = 0; i < colors; ++i) {
9644 buffer[pos++] = rawBytes[i];
9645 }
9646 for (; i < rowBytes; ++i) {
9647 buffer[pos] = buffer[pos - colors] + rawBytes[i];
9648 pos++;
9649 }
9650 } else if (bits === 16) {
9651 const bytesPerPixel = colors * 2;
9652 for (i = 0; i < bytesPerPixel; ++i) {
9653 buffer[pos++] = rawBytes[i];
9654 }
9655 for (; i < rowBytes; i += 2) {
9656 const sum = ((rawBytes[i] & 0xff) << 8) + (rawBytes[i + 1] & 0xff) + ((buffer[pos - bytesPerPixel] & 0xff) << 8) + (buffer[pos - bytesPerPixel + 1] & 0xff);
9657 buffer[pos++] = sum >> 8 & 0xff;
9658 buffer[pos++] = sum & 0xff;
9659 }
9660 } else {
9661 const compArray = new Uint8Array(colors + 1);
9662 const bitMask = (1 << bits) - 1;
9663 let j = 0,
9664 k = bufferLength;
9665 const columns = this.columns;
9666 for (i = 0; i < columns; ++i) {
9667 for (let kk = 0; kk < colors; ++kk) {
9668 if (inbits < bits) {
9669 inbuf = inbuf << 8 | rawBytes[j++] & 0xff;
9670 inbits += 8;
9671 }
9672 compArray[kk] = compArray[kk] + (inbuf >> inbits - bits) & bitMask;
9673 inbits -= bits;
9674 outbuf = outbuf << bits | compArray[kk];
9675 outbits += bits;
9676 if (outbits >= 8) {
9677 buffer[k++] = outbuf >> outbits - 8 & 0xff;
9678 outbits -= 8;
9679 }
9680 }
9681 }
9682 if (outbits > 0) {
9683 buffer[k++] = (outbuf << 8 - outbits) + (inbuf & (1 << 8 - outbits) - 1);
9684 }
9685 }
9686 this.bufferLength += rowBytes;
9687 }
9688 readBlockPng() {
9689 const rowBytes = this.rowBytes;
9690 const pixBytes = this.pixBytes;
9691 const predictor = this.str.getByte();
9692 const rawBytes = this.str.getBytes(rowBytes);
9693 this.eof = !rawBytes.length;
9694 if (this.eof) {
9695 return;
9696 }
9697 const bufferLength = this.bufferLength;
9698 const buffer = this.ensureBuffer(bufferLength + rowBytes);
9699 let prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
9700 if (prevRow.length === 0) {
9701 prevRow = new Uint8Array(rowBytes);
9702 }
9703 let i,
9704 j = bufferLength,
9705 up,
9706 c;
9707 switch (predictor) {
9708 case 0:
9709 for (i = 0; i < rowBytes; ++i) {
9710 buffer[j++] = rawBytes[i];
9711 }
9712 break;
9713 case 1:
9714 for (i = 0; i < pixBytes; ++i) {
9715 buffer[j++] = rawBytes[i];
9716 }
9717 for (; i < rowBytes; ++i) {
9718 buffer[j] = buffer[j - pixBytes] + rawBytes[i] & 0xff;
9719 j++;
9720 }
9721 break;
9722 case 2:
9723 for (i = 0; i < rowBytes; ++i) {
9724 buffer[j++] = prevRow[i] + rawBytes[i] & 0xff;
9725 }
9726 break;
9727 case 3:
9728 for (i = 0; i < pixBytes; ++i) {
9729 buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
9730 }
9731 for (; i < rowBytes; ++i) {
9732 buffer[j] = (prevRow[i] + buffer[j - pixBytes] >> 1) + rawBytes[i] & 0xff;
9733 j++;
9734 }
9735 break;
9736 case 4:
9737 for (i = 0; i < pixBytes; ++i) {
9738 up = prevRow[i];
9739 c = rawBytes[i];
9740 buffer[j++] = up + c;
9741 }
9742 for (; i < rowBytes; ++i) {
9743 up = prevRow[i];
9744 const upLeft = prevRow[i - pixBytes];
9745 const left = buffer[j - pixBytes];
9746 const p = left + up - upLeft;
9747 let pa = p - left;
9748 if (pa < 0) {
9749 pa = -pa;
9750 }
9751 let pb = p - up;
9752 if (pb < 0) {
9753 pb = -pb;
9754 }
9755 let pc = p - upLeft;
9756 if (pc < 0) {
9757 pc = -pc;
9758 }
9759 c = rawBytes[i];
9760 if (pa <= pb && pa <= pc) {
9761 buffer[j++] = left + c;
9762 } else if (pb <= pc) {
9763 buffer[j++] = up + c;
9764 } else {
9765 buffer[j++] = upLeft + c;
9766 }
9767 }
9768 break;
9769 default:
9770 throw new FormatError(`Unsupported predictor: ${predictor}`);
9771 }
9772 this.bufferLength += rowBytes;
9773 }
9774}
9775
9776;// CONCATENATED MODULE: ./src/core/run_length_stream.js
9777
9778class RunLengthStream extends DecodeStream {
9779 constructor(str, maybeLength) {
9780 super(maybeLength);
9781 this.str = str;
9782 this.dict = str.dict;
9783 }
9784 readBlock() {
9785 const repeatHeader = this.str.getBytes(2);
9786 if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
9787 this.eof = true;
9788 return;
9789 }
9790 let buffer;
9791 let bufferLength = this.bufferLength;
9792 let n = repeatHeader[0];
9793 if (n < 128) {
9794 buffer = this.ensureBuffer(bufferLength + n + 1);
9795 buffer[bufferLength++] = repeatHeader[1];
9796 if (n > 0) {
9797 const source = this.str.getBytes(n);
9798 buffer.set(source, bufferLength);
9799 bufferLength += n;
9800 }
9801 } else {
9802 n = 257 - n;
9803 const b = repeatHeader[1];
9804 buffer = this.ensureBuffer(bufferLength + n + 1);
9805 for (let i = 0; i < n; i++) {
9806 buffer[bufferLength++] = b;
9807 }
9808 }
9809 this.bufferLength = bufferLength;
9810 }
9811}
9812
9813;// CONCATENATED MODULE: ./src/core/parser.js
9814
9815
9816
9817
9818
9819
9820
9821
9822
9823
9824
9825
9826
9827
9828const MAX_LENGTH_TO_CACHE = 1000;
9829function getInlineImageCacheKey(bytes) {
9830 const strBuf = [],
9831 ii = bytes.length;
9832 let i = 0;
9833 while (i < ii - 1) {
9834 strBuf.push(bytes[i++] << 8 | bytes[i++]);
9835 }
9836 if (i < ii) {
9837 strBuf.push(bytes[i]);
9838 }
9839 return ii + "_" + String.fromCharCode.apply(null, strBuf);
9840}
9841class Parser {
9842 constructor({
9843 lexer,
9844 xref,
9845 allowStreams = false,
9846 recoveryMode = false
9847 }) {
9848 this.lexer = lexer;
9849 this.xref = xref;
9850 this.allowStreams = allowStreams;
9851 this.recoveryMode = recoveryMode;
9852 this.imageCache = Object.create(null);
9853 this._imageId = 0;
9854 this.refill();
9855 }
9856 refill() {
9857 this.buf1 = this.lexer.getObj();
9858 this.buf2 = this.lexer.getObj();
9859 }
9860 shift() {
9861 if (this.buf2 instanceof Cmd && this.buf2.cmd === "ID") {
9862 this.buf1 = this.buf2;
9863 this.buf2 = null;
9864 } else {
9865 this.buf1 = this.buf2;
9866 this.buf2 = this.lexer.getObj();
9867 }
9868 }
9869 tryShift() {
9870 try {
9871 this.shift();
9872 return true;
9873 } catch (e) {
9874 if (e instanceof MissingDataException) {
9875 throw e;
9876 }
9877 return false;
9878 }
9879 }
9880 getObj(cipherTransform = null) {
9881 const buf1 = this.buf1;
9882 this.shift();
9883 if (buf1 instanceof Cmd) {
9884 switch (buf1.cmd) {
9885 case "BI":
9886 return this.makeInlineImage(cipherTransform);
9887 case "[":
9888 const array = [];
9889 while (!isCmd(this.buf1, "]") && this.buf1 !== EOF) {
9890 array.push(this.getObj(cipherTransform));
9891 }
9892 if (this.buf1 === EOF) {
9893 if (this.recoveryMode) {
9894 return array;
9895 }
9896 throw new ParserEOFException("End of file inside array.");
9897 }
9898 this.shift();
9899 return array;
9900 case "<<":
9901 const dict = new Dict(this.xref);
9902 while (!isCmd(this.buf1, ">>") && this.buf1 !== EOF) {
9903 if (!(this.buf1 instanceof Name)) {
9904 info("Malformed dictionary: key must be a name object");
9905 this.shift();
9906 continue;
9907 }
9908 const key = this.buf1.name;
9909 this.shift();
9910 if (this.buf1 === EOF) {
9911 break;
9912 }
9913 dict.set(key, this.getObj(cipherTransform));
9914 }
9915 if (this.buf1 === EOF) {
9916 if (this.recoveryMode) {
9917 return dict;
9918 }
9919 throw new ParserEOFException("End of file inside dictionary.");
9920 }
9921 if (isCmd(this.buf2, "stream")) {
9922 return this.allowStreams ? this.makeStream(dict, cipherTransform) : dict;
9923 }
9924 this.shift();
9925 return dict;
9926 default:
9927 return buf1;
9928 }
9929 }
9930 if (Number.isInteger(buf1)) {
9931 if (Number.isInteger(this.buf1) && isCmd(this.buf2, "R")) {
9932 const ref = Ref.get(buf1, this.buf1);
9933 this.shift();
9934 this.shift();
9935 return ref;
9936 }
9937 return buf1;
9938 }
9939 if (typeof buf1 === "string") {
9940 if (cipherTransform) {
9941 return cipherTransform.decryptString(buf1);
9942 }
9943 return buf1;
9944 }
9945 return buf1;
9946 }
9947 findDefaultInlineStreamEnd(stream) {
9948 const E = 0x45,
9949 I = 0x49,
9950 SPACE = 0x20,
9951 LF = 0xa,
9952 CR = 0xd,
9953 NUL = 0x0;
9954 const {
9955 knownCommands
9956 } = this.lexer,
9957 startPos = stream.pos,
9958 n = 15;
9959 let state = 0,
9960 ch,
9961 maybeEIPos;
9962 while ((ch = stream.getByte()) !== -1) {
9963 if (state === 0) {
9964 state = ch === E ? 1 : 0;
9965 } else if (state === 1) {
9966 state = ch === I ? 2 : 0;
9967 } else {
9968 if (ch === SPACE || ch === LF || ch === CR) {
9969 maybeEIPos = stream.pos;
9970 const followingBytes = stream.peekBytes(n);
9971 const ii = followingBytes.length;
9972 if (ii === 0) {
9973 break;
9974 }
9975 for (let i = 0; i < ii; i++) {
9976 ch = followingBytes[i];
9977 if (ch === NUL && followingBytes[i + 1] !== NUL) {
9978 continue;
9979 }
9980 if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7f)) {
9981 state = 0;
9982 break;
9983 }
9984 }
9985 if (state !== 2) {
9986 continue;
9987 }
9988 if (!knownCommands) {
9989 warn("findDefaultInlineStreamEnd - `lexer.knownCommands` is undefined.");
9990 continue;
9991 }
9992 const tmpLexer = new Lexer(new Stream(followingBytes.slice()), knownCommands);
9993 tmpLexer._hexStringWarn = () => {};
9994 let numArgs = 0;
9995 while (true) {
9996 const nextObj = tmpLexer.getObj();
9997 if (nextObj === EOF) {
9998 state = 0;
9999 break;
10000 }
10001 if (nextObj instanceof Cmd) {
10002 const knownCommand = knownCommands[nextObj.cmd];
10003 if (!knownCommand) {
10004 state = 0;
10005 break;
10006 } else if (knownCommand.variableArgs ? numArgs <= knownCommand.numArgs : numArgs === knownCommand.numArgs) {
10007 break;
10008 }
10009 numArgs = 0;
10010 continue;
10011 }
10012 numArgs++;
10013 }
10014 if (state === 2) {
10015 break;
10016 }
10017 } else {
10018 state = 0;
10019 }
10020 }
10021 }
10022 if (ch === -1) {
10023 warn("findDefaultInlineStreamEnd: " + "Reached the end of the stream without finding a valid EI marker");
10024 if (maybeEIPos) {
10025 warn('... trying to recover by using the last "EI" occurrence.');
10026 stream.skip(-(stream.pos - maybeEIPos));
10027 }
10028 }
10029 let endOffset = 4;
10030 stream.skip(-endOffset);
10031 ch = stream.peekByte();
10032 stream.skip(endOffset);
10033 if (!isWhiteSpace(ch)) {
10034 endOffset--;
10035 }
10036 return stream.pos - endOffset - startPos;
10037 }
10038 findDCTDecodeInlineStreamEnd(stream) {
10039 const startPos = stream.pos;
10040 let foundEOI = false,
10041 b,
10042 markerLength;
10043 while ((b = stream.getByte()) !== -1) {
10044 if (b !== 0xff) {
10045 continue;
10046 }
10047 switch (stream.getByte()) {
10048 case 0x00:
10049 break;
10050 case 0xff:
10051 stream.skip(-1);
10052 break;
10053 case 0xd9:
10054 foundEOI = true;
10055 break;
10056 case 0xc0:
10057 case 0xc1:
10058 case 0xc2:
10059 case 0xc3:
10060 case 0xc5:
10061 case 0xc6:
10062 case 0xc7:
10063 case 0xc9:
10064 case 0xca:
10065 case 0xcb:
10066 case 0xcd:
10067 case 0xce:
10068 case 0xcf:
10069 case 0xc4:
10070 case 0xcc:
10071 case 0xda:
10072 case 0xdb:
10073 case 0xdc:
10074 case 0xdd:
10075 case 0xde:
10076 case 0xdf:
10077 case 0xe0:
10078 case 0xe1:
10079 case 0xe2:
10080 case 0xe3:
10081 case 0xe4:
10082 case 0xe5:
10083 case 0xe6:
10084 case 0xe7:
10085 case 0xe8:
10086 case 0xe9:
10087 case 0xea:
10088 case 0xeb:
10089 case 0xec:
10090 case 0xed:
10091 case 0xee:
10092 case 0xef:
10093 case 0xfe:
10094 markerLength = stream.getUint16();
10095 if (markerLength > 2) {
10096 stream.skip(markerLength - 2);
10097 } else {
10098 stream.skip(-2);
10099 }
10100 break;
10101 }
10102 if (foundEOI) {
10103 break;
10104 }
10105 }
10106 const length = stream.pos - startPos;
10107 if (b === -1) {
10108 warn("Inline DCTDecode image stream: " + "EOI marker not found, searching for /EI/ instead.");
10109 stream.skip(-length);
10110 return this.findDefaultInlineStreamEnd(stream);
10111 }
10112 this.inlineStreamSkipEI(stream);
10113 return length;
10114 }
10115 findASCII85DecodeInlineStreamEnd(stream) {
10116 const TILDE = 0x7e,
10117 GT = 0x3e;
10118 const startPos = stream.pos;
10119 let ch;
10120 while ((ch = stream.getByte()) !== -1) {
10121 if (ch === TILDE) {
10122 const tildePos = stream.pos;
10123 ch = stream.peekByte();
10124 while (isWhiteSpace(ch)) {
10125 stream.skip();
10126 ch = stream.peekByte();
10127 }
10128 if (ch === GT) {
10129 stream.skip();
10130 break;
10131 }
10132 if (stream.pos > tildePos) {
10133 const maybeEI = stream.peekBytes(2);
10134 if (maybeEI[0] === 0x45 && maybeEI[1] === 0x49) {
10135 break;
10136 }
10137 }
10138 }
10139 }
10140 const length = stream.pos - startPos;
10141 if (ch === -1) {
10142 warn("Inline ASCII85Decode image stream: " + "EOD marker not found, searching for /EI/ instead.");
10143 stream.skip(-length);
10144 return this.findDefaultInlineStreamEnd(stream);
10145 }
10146 this.inlineStreamSkipEI(stream);
10147 return length;
10148 }
10149 findASCIIHexDecodeInlineStreamEnd(stream) {
10150 const GT = 0x3e;
10151 const startPos = stream.pos;
10152 let ch;
10153 while ((ch = stream.getByte()) !== -1) {
10154 if (ch === GT) {
10155 break;
10156 }
10157 }
10158 const length = stream.pos - startPos;
10159 if (ch === -1) {
10160 warn("Inline ASCIIHexDecode image stream: " + "EOD marker not found, searching for /EI/ instead.");
10161 stream.skip(-length);
10162 return this.findDefaultInlineStreamEnd(stream);
10163 }
10164 this.inlineStreamSkipEI(stream);
10165 return length;
10166 }
10167 inlineStreamSkipEI(stream) {
10168 const E = 0x45,
10169 I = 0x49;
10170 let state = 0,
10171 ch;
10172 while ((ch = stream.getByte()) !== -1) {
10173 if (state === 0) {
10174 state = ch === E ? 1 : 0;
10175 } else if (state === 1) {
10176 state = ch === I ? 2 : 0;
10177 } else if (state === 2) {
10178 break;
10179 }
10180 }
10181 }
10182 makeInlineImage(cipherTransform) {
10183 const lexer = this.lexer;
10184 const stream = lexer.stream;
10185 const dictMap = Object.create(null);
10186 let dictLength;
10187 while (!isCmd(this.buf1, "ID") && this.buf1 !== EOF) {
10188 if (!(this.buf1 instanceof Name)) {
10189 throw new FormatError("Dictionary key must be a name object");
10190 }
10191 const key = this.buf1.name;
10192 this.shift();
10193 if (this.buf1 === EOF) {
10194 break;
10195 }
10196 dictMap[key] = this.getObj(cipherTransform);
10197 }
10198 if (lexer.beginInlineImagePos !== -1) {
10199 dictLength = stream.pos - lexer.beginInlineImagePos;
10200 }
10201 const filter = this.xref.fetchIfRef(dictMap.F || dictMap.Filter);
10202 let filterName;
10203 if (filter instanceof Name) {
10204 filterName = filter.name;
10205 } else if (Array.isArray(filter)) {
10206 const filterZero = this.xref.fetchIfRef(filter[0]);
10207 if (filterZero instanceof Name) {
10208 filterName = filterZero.name;
10209 }
10210 }
10211 const startPos = stream.pos;
10212 let length;
10213 switch (filterName) {
10214 case "DCT":
10215 case "DCTDecode":
10216 length = this.findDCTDecodeInlineStreamEnd(stream);
10217 break;
10218 case "A85":
10219 case "ASCII85Decode":
10220 length = this.findASCII85DecodeInlineStreamEnd(stream);
10221 break;
10222 case "AHx":
10223 case "ASCIIHexDecode":
10224 length = this.findASCIIHexDecodeInlineStreamEnd(stream);
10225 break;
10226 default:
10227 length = this.findDefaultInlineStreamEnd(stream);
10228 }
10229 let cacheKey;
10230 if (length < MAX_LENGTH_TO_CACHE && dictLength > 0) {
10231 const initialStreamPos = stream.pos;
10232 stream.pos = lexer.beginInlineImagePos;
10233 cacheKey = getInlineImageCacheKey(stream.getBytes(dictLength + length));
10234 stream.pos = initialStreamPos;
10235 const cacheEntry = this.imageCache[cacheKey];
10236 if (cacheEntry !== undefined) {
10237 this.buf2 = Cmd.get("EI");
10238 this.shift();
10239 cacheEntry.reset();
10240 return cacheEntry;
10241 }
10242 }
10243 const dict = new Dict(this.xref);
10244 for (const key in dictMap) {
10245 dict.set(key, dictMap[key]);
10246 }
10247 let imageStream = stream.makeSubStream(startPos, length, dict);
10248 if (cipherTransform) {
10249 imageStream = cipherTransform.createStream(imageStream, length);
10250 }
10251 imageStream = this.filter(imageStream, dict, length);
10252 imageStream.dict = dict;
10253 if (cacheKey !== undefined) {
10254 imageStream.cacheKey = `inline_img_${++this._imageId}`;
10255 this.imageCache[cacheKey] = imageStream;
10256 }
10257 this.buf2 = Cmd.get("EI");
10258 this.shift();
10259 return imageStream;
10260 }
10261 _findStreamLength(startPos, signature) {
10262 const {
10263 stream
10264 } = this.lexer;
10265 stream.pos = startPos;
10266 const SCAN_BLOCK_LENGTH = 2048;
10267 const signatureLength = signature.length;
10268 while (stream.pos < stream.end) {
10269 const scanBytes = stream.peekBytes(SCAN_BLOCK_LENGTH);
10270 const scanLength = scanBytes.length - signatureLength;
10271 if (scanLength <= 0) {
10272 break;
10273 }
10274 let pos = 0;
10275 while (pos < scanLength) {
10276 let j = 0;
10277 while (j < signatureLength && scanBytes[pos + j] === signature[j]) {
10278 j++;
10279 }
10280 if (j >= signatureLength) {
10281 stream.pos += pos;
10282 return stream.pos - startPos;
10283 }
10284 pos++;
10285 }
10286 stream.pos += scanLength;
10287 }
10288 return -1;
10289 }
10290 makeStream(dict, cipherTransform) {
10291 const lexer = this.lexer;
10292 let stream = lexer.stream;
10293 lexer.skipToNextLine();
10294 const startPos = stream.pos - 1;
10295 let length = dict.get("Length");
10296 if (!Number.isInteger(length)) {
10297 info(`Bad length "${length && length.toString()}" in stream.`);
10298 length = 0;
10299 }
10300 stream.pos = startPos + length;
10301 lexer.nextChar();
10302 if (this.tryShift() && isCmd(this.buf2, "endstream")) {
10303 this.shift();
10304 } else {
10305 const ENDSTREAM_SIGNATURE = new Uint8Array([0x65, 0x6e, 0x64, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d]);
10306 let actualLength = this._findStreamLength(startPos, ENDSTREAM_SIGNATURE);
10307 if (actualLength < 0) {
10308 const MAX_TRUNCATION = 1;
10309 for (let i = 1; i <= MAX_TRUNCATION; i++) {
10310 const end = ENDSTREAM_SIGNATURE.length - i;
10311 const TRUNCATED_SIGNATURE = ENDSTREAM_SIGNATURE.slice(0, end);
10312 const maybeLength = this._findStreamLength(startPos, TRUNCATED_SIGNATURE);
10313 if (maybeLength >= 0) {
10314 const lastByte = stream.peekBytes(end + 1)[end];
10315 if (!isWhiteSpace(lastByte)) {
10316 break;
10317 }
10318 info(`Found "${bytesToString(TRUNCATED_SIGNATURE)}" when ` + "searching for endstream command.");
10319 actualLength = maybeLength;
10320 break;
10321 }
10322 }
10323 if (actualLength < 0) {
10324 throw new FormatError("Missing endstream command.");
10325 }
10326 }
10327 length = actualLength;
10328 lexer.nextChar();
10329 this.shift();
10330 this.shift();
10331 }
10332 this.shift();
10333 stream = stream.makeSubStream(startPos, length, dict);
10334 if (cipherTransform) {
10335 stream = cipherTransform.createStream(stream, length);
10336 }
10337 stream = this.filter(stream, dict, length);
10338 stream.dict = dict;
10339 return stream;
10340 }
10341 filter(stream, dict, length) {
10342 let filter = dict.get("F", "Filter");
10343 let params = dict.get("DP", "DecodeParms");
10344 if (filter instanceof Name) {
10345 if (Array.isArray(params)) {
10346 warn("/DecodeParms should not be an Array, when /Filter is a Name.");
10347 }
10348 return this.makeFilter(stream, filter.name, length, params);
10349 }
10350 let maybeLength = length;
10351 if (Array.isArray(filter)) {
10352 const filterArray = filter;
10353 const paramsArray = params;
10354 for (let i = 0, ii = filterArray.length; i < ii; ++i) {
10355 filter = this.xref.fetchIfRef(filterArray[i]);
10356 if (!(filter instanceof Name)) {
10357 throw new FormatError(`Bad filter name "${filter}"`);
10358 }
10359 params = null;
10360 if (Array.isArray(paramsArray) && i in paramsArray) {
10361 params = this.xref.fetchIfRef(paramsArray[i]);
10362 }
10363 stream = this.makeFilter(stream, filter.name, maybeLength, params);
10364 maybeLength = null;
10365 }
10366 }
10367 return stream;
10368 }
10369 makeFilter(stream, name, maybeLength, params) {
10370 if (maybeLength === 0) {
10371 warn(`Empty "${name}" stream.`);
10372 return new NullStream();
10373 }
10374 try {
10375 switch (name) {
10376 case "Fl":
10377 case "FlateDecode":
10378 if (params) {
10379 return new PredictorStream(new FlateStream(stream, maybeLength), maybeLength, params);
10380 }
10381 return new FlateStream(stream, maybeLength);
10382 case "LZW":
10383 case "LZWDecode":
10384 let earlyChange = 1;
10385 if (params) {
10386 if (params.has("EarlyChange")) {
10387 earlyChange = params.get("EarlyChange");
10388 }
10389 return new PredictorStream(new LZWStream(stream, maybeLength, earlyChange), maybeLength, params);
10390 }
10391 return new LZWStream(stream, maybeLength, earlyChange);
10392 case "DCT":
10393 case "DCTDecode":
10394 return new JpegStream(stream, maybeLength, params);
10395 case "JPX":
10396 case "JPXDecode":
10397 return new JpxStream(stream, maybeLength, params);
10398 case "A85":
10399 case "ASCII85Decode":
10400 return new Ascii85Stream(stream, maybeLength);
10401 case "AHx":
10402 case "ASCIIHexDecode":
10403 return new AsciiHexStream(stream, maybeLength);
10404 case "CCF":
10405 case "CCITTFaxDecode":
10406 return new CCITTFaxStream(stream, maybeLength, params);
10407 case "RL":
10408 case "RunLengthDecode":
10409 return new RunLengthStream(stream, maybeLength);
10410 case "JBIG2Decode":
10411 return new Jbig2Stream(stream, maybeLength, params);
10412 }
10413 warn(`Filter "${name}" is not supported.`);
10414 return stream;
10415 } catch (ex) {
10416 if (ex instanceof MissingDataException) {
10417 throw ex;
10418 }
10419 warn(`Invalid stream: "${ex}"`);
10420 return new NullStream();
10421 }
10422 }
10423}
10424const 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];
10425function toHexDigit(ch) {
10426 if (ch >= 0x30 && ch <= 0x39) {
10427 return ch & 0x0f;
10428 }
10429 if (ch >= 0x41 && ch <= 0x46 || ch >= 0x61 && ch <= 0x66) {
10430 return (ch & 0x0f) + 9;
10431 }
10432 return -1;
10433}
10434class Lexer {
10435 constructor(stream, knownCommands = null) {
10436 this.stream = stream;
10437 this.nextChar();
10438 this.strBuf = [];
10439 this.knownCommands = knownCommands;
10440 this._hexStringNumWarn = 0;
10441 this.beginInlineImagePos = -1;
10442 }
10443 nextChar() {
10444 return this.currentChar = this.stream.getByte();
10445 }
10446 peekChar() {
10447 return this.stream.peekByte();
10448 }
10449 getNumber() {
10450 let ch = this.currentChar;
10451 let eNotation = false;
10452 let divideBy = 0;
10453 let sign = 1;
10454 if (ch === 0x2d) {
10455 sign = -1;
10456 ch = this.nextChar();
10457 if (ch === 0x2d) {
10458 ch = this.nextChar();
10459 }
10460 } else if (ch === 0x2b) {
10461 ch = this.nextChar();
10462 }
10463 if (ch === 0x0a || ch === 0x0d) {
10464 do {
10465 ch = this.nextChar();
10466 } while (ch === 0x0a || ch === 0x0d);
10467 }
10468 if (ch === 0x2e) {
10469 divideBy = 10;
10470 ch = this.nextChar();
10471 }
10472 if (ch < 0x30 || ch > 0x39) {
10473 const msg = `Invalid number: ${String.fromCharCode(ch)} (charCode ${ch})`;
10474 if (isWhiteSpace(ch) || ch === -1) {
10475 info(`Lexer.getNumber - "${msg}".`);
10476 return 0;
10477 }
10478 throw new FormatError(msg);
10479 }
10480 let baseValue = ch - 0x30;
10481 let powerValue = 0;
10482 let powerValueSign = 1;
10483 while ((ch = this.nextChar()) >= 0) {
10484 if (ch >= 0x30 && ch <= 0x39) {
10485 const currentDigit = ch - 0x30;
10486 if (eNotation) {
10487 powerValue = powerValue * 10 + currentDigit;
10488 } else {
10489 if (divideBy !== 0) {
10490 divideBy *= 10;
10491 }
10492 baseValue = baseValue * 10 + currentDigit;
10493 }
10494 } else if (ch === 0x2e) {
10495 if (divideBy === 0) {
10496 divideBy = 1;
10497 } else {
10498 break;
10499 }
10500 } else if (ch === 0x2d) {
10501 warn("Badly formatted number: minus sign in the middle");
10502 } else if (ch === 0x45 || ch === 0x65) {
10503 ch = this.peekChar();
10504 if (ch === 0x2b || ch === 0x2d) {
10505 powerValueSign = ch === 0x2d ? -1 : 1;
10506 this.nextChar();
10507 } else if (ch < 0x30 || ch > 0x39) {
10508 break;
10509 }
10510 eNotation = true;
10511 } else {
10512 break;
10513 }
10514 }
10515 if (divideBy !== 0) {
10516 baseValue /= divideBy;
10517 }
10518 if (eNotation) {
10519 baseValue *= 10 ** (powerValueSign * powerValue);
10520 }
10521 return sign * baseValue;
10522 }
10523 getString() {
10524 let numParen = 1;
10525 let done = false;
10526 const strBuf = this.strBuf;
10527 strBuf.length = 0;
10528 let ch = this.nextChar();
10529 while (true) {
10530 let charBuffered = false;
10531 switch (ch | 0) {
10532 case -1:
10533 warn("Unterminated string");
10534 done = true;
10535 break;
10536 case 0x28:
10537 ++numParen;
10538 strBuf.push("(");
10539 break;
10540 case 0x29:
10541 if (--numParen === 0) {
10542 this.nextChar();
10543 done = true;
10544 } else {
10545 strBuf.push(")");
10546 }
10547 break;
10548 case 0x5c:
10549 ch = this.nextChar();
10550 switch (ch) {
10551 case -1:
10552 warn("Unterminated string");
10553 done = true;
10554 break;
10555 case 0x6e:
10556 strBuf.push("\n");
10557 break;
10558 case 0x72:
10559 strBuf.push("\r");
10560 break;
10561 case 0x74:
10562 strBuf.push("\t");
10563 break;
10564 case 0x62:
10565 strBuf.push("\b");
10566 break;
10567 case 0x66:
10568 strBuf.push("\f");
10569 break;
10570 case 0x5c:
10571 case 0x28:
10572 case 0x29:
10573 strBuf.push(String.fromCharCode(ch));
10574 break;
10575 case 0x30:
10576 case 0x31:
10577 case 0x32:
10578 case 0x33:
10579 case 0x34:
10580 case 0x35:
10581 case 0x36:
10582 case 0x37:
10583 let x = ch & 0x0f;
10584 ch = this.nextChar();
10585 charBuffered = true;
10586 if (ch >= 0x30 && ch <= 0x37) {
10587 x = (x << 3) + (ch & 0x0f);
10588 ch = this.nextChar();
10589 if (ch >= 0x30 && ch <= 0x37) {
10590 charBuffered = false;
10591 x = (x << 3) + (ch & 0x0f);
10592 }
10593 }
10594 strBuf.push(String.fromCharCode(x));
10595 break;
10596 case 0x0d:
10597 if (this.peekChar() === 0x0a) {
10598 this.nextChar();
10599 }
10600 break;
10601 case 0x0a:
10602 break;
10603 default:
10604 strBuf.push(String.fromCharCode(ch));
10605 break;
10606 }
10607 break;
10608 default:
10609 strBuf.push(String.fromCharCode(ch));
10610 break;
10611 }
10612 if (done) {
10613 break;
10614 }
10615 if (!charBuffered) {
10616 ch = this.nextChar();
10617 }
10618 }
10619 return strBuf.join("");
10620 }
10621 getName() {
10622 let ch, previousCh;
10623 const strBuf = this.strBuf;
10624 strBuf.length = 0;
10625 while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
10626 if (ch === 0x23) {
10627 ch = this.nextChar();
10628 if (specialChars[ch]) {
10629 warn("Lexer_getName: " + "NUMBER SIGN (#) should be followed by a hexadecimal number.");
10630 strBuf.push("#");
10631 break;
10632 }
10633 const x = toHexDigit(ch);
10634 if (x !== -1) {
10635 previousCh = ch;
10636 ch = this.nextChar();
10637 const x2 = toHexDigit(ch);
10638 if (x2 === -1) {
10639 warn(`Lexer_getName: Illegal digit (${String.fromCharCode(ch)}) ` + "in hexadecimal number.");
10640 strBuf.push("#", String.fromCharCode(previousCh));
10641 if (specialChars[ch]) {
10642 break;
10643 }
10644 strBuf.push(String.fromCharCode(ch));
10645 continue;
10646 }
10647 strBuf.push(String.fromCharCode(x << 4 | x2));
10648 } else {
10649 strBuf.push("#", String.fromCharCode(ch));
10650 }
10651 } else {
10652 strBuf.push(String.fromCharCode(ch));
10653 }
10654 }
10655 if (strBuf.length > 127) {
10656 warn(`Name token is longer than allowed by the spec: ${strBuf.length}`);
10657 }
10658 return Name.get(strBuf.join(""));
10659 }
10660 _hexStringWarn(ch) {
10661 const MAX_HEX_STRING_NUM_WARN = 5;
10662 if (this._hexStringNumWarn++ === MAX_HEX_STRING_NUM_WARN) {
10663 warn("getHexString - ignoring additional invalid characters.");
10664 return;
10665 }
10666 if (this._hexStringNumWarn > MAX_HEX_STRING_NUM_WARN) {
10667 return;
10668 }
10669 warn(`getHexString - ignoring invalid character: ${ch}`);
10670 }
10671 getHexString() {
10672 const strBuf = this.strBuf;
10673 strBuf.length = 0;
10674 let ch = this.currentChar;
10675 let isFirstHex = true;
10676 let firstDigit, secondDigit;
10677 this._hexStringNumWarn = 0;
10678 while (true) {
10679 if (ch < 0) {
10680 warn("Unterminated hex string");
10681 break;
10682 } else if (ch === 0x3e) {
10683 this.nextChar();
10684 break;
10685 } else if (specialChars[ch] === 1) {
10686 ch = this.nextChar();
10687 continue;
10688 } else {
10689 if (isFirstHex) {
10690 firstDigit = toHexDigit(ch);
10691 if (firstDigit === -1) {
10692 this._hexStringWarn(ch);
10693 ch = this.nextChar();
10694 continue;
10695 }
10696 } else {
10697 secondDigit = toHexDigit(ch);
10698 if (secondDigit === -1) {
10699 this._hexStringWarn(ch);
10700 ch = this.nextChar();
10701 continue;
10702 }
10703 strBuf.push(String.fromCharCode(firstDigit << 4 | secondDigit));
10704 }
10705 isFirstHex = !isFirstHex;
10706 ch = this.nextChar();
10707 }
10708 }
10709 return strBuf.join("");
10710 }
10711 getObj() {
10712 let comment = false;
10713 let ch = this.currentChar;
10714 while (true) {
10715 if (ch < 0) {
10716 return EOF;
10717 }
10718 if (comment) {
10719 if (ch === 0x0a || ch === 0x0d) {
10720 comment = false;
10721 }
10722 } else if (ch === 0x25) {
10723 comment = true;
10724 } else if (specialChars[ch] !== 1) {
10725 break;
10726 }
10727 ch = this.nextChar();
10728 }
10729 switch (ch | 0) {
10730 case 0x30:
10731 case 0x31:
10732 case 0x32:
10733 case 0x33:
10734 case 0x34:
10735 case 0x35:
10736 case 0x36:
10737 case 0x37:
10738 case 0x38:
10739 case 0x39:
10740 case 0x2b:
10741 case 0x2d:
10742 case 0x2e:
10743 return this.getNumber();
10744 case 0x28:
10745 return this.getString();
10746 case 0x2f:
10747 return this.getName();
10748 case 0x5b:
10749 this.nextChar();
10750 return Cmd.get("[");
10751 case 0x5d:
10752 this.nextChar();
10753 return Cmd.get("]");
10754 case 0x3c:
10755 ch = this.nextChar();
10756 if (ch === 0x3c) {
10757 this.nextChar();
10758 return Cmd.get("<<");
10759 }
10760 return this.getHexString();
10761 case 0x3e:
10762 ch = this.nextChar();
10763 if (ch === 0x3e) {
10764 this.nextChar();
10765 return Cmd.get(">>");
10766 }
10767 return Cmd.get(">");
10768 case 0x7b:
10769 this.nextChar();
10770 return Cmd.get("{");
10771 case 0x7d:
10772 this.nextChar();
10773 return Cmd.get("}");
10774 case 0x29:
10775 this.nextChar();
10776 throw new FormatError(`Illegal character: ${ch}`);
10777 }
10778 let str = String.fromCharCode(ch);
10779 if (ch < 0x20 || ch > 0x7f) {
10780 const nextCh = this.peekChar();
10781 if (nextCh >= 0x20 && nextCh <= 0x7f) {
10782 this.nextChar();
10783 return Cmd.get(str);
10784 }
10785 }
10786 const knownCommands = this.knownCommands;
10787 let knownCommandFound = knownCommands?.[str] !== undefined;
10788 while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
10789 const possibleCommand = str + String.fromCharCode(ch);
10790 if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
10791 break;
10792 }
10793 if (str.length === 128) {
10794 throw new FormatError(`Command token too long: ${str.length}`);
10795 }
10796 str = possibleCommand;
10797 knownCommandFound = knownCommands?.[str] !== undefined;
10798 }
10799 if (str === "true") {
10800 return true;
10801 }
10802 if (str === "false") {
10803 return false;
10804 }
10805 if (str === "null") {
10806 return null;
10807 }
10808 if (str === "BI") {
10809 this.beginInlineImagePos = this.stream.pos;
10810 }
10811 return Cmd.get(str);
10812 }
10813 skipToNextLine() {
10814 let ch = this.currentChar;
10815 while (ch >= 0) {
10816 if (ch === 0x0d) {
10817 ch = this.nextChar();
10818 if (ch === 0x0a) {
10819 this.nextChar();
10820 }
10821 break;
10822 } else if (ch === 0x0a) {
10823 this.nextChar();
10824 break;
10825 }
10826 ch = this.nextChar();
10827 }
10828 }
10829}
10830class Linearization {
10831 static create(stream) {
10832 function getInt(linDict, name, allowZeroValue = false) {
10833 const obj = linDict.get(name);
10834 if (Number.isInteger(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
10835 return obj;
10836 }
10837 throw new Error(`The "${name}" parameter in the linearization ` + "dictionary is invalid.");
10838 }
10839 function getHints(linDict) {
10840 const hints = linDict.get("H");
10841 let hintsLength;
10842 if (Array.isArray(hints) && ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
10843 for (let index = 0; index < hintsLength; index++) {
10844 const hint = hints[index];
10845 if (!(Number.isInteger(hint) && hint > 0)) {
10846 throw new Error(`Hint (${index}) in the linearization dictionary is invalid.`);
10847 }
10848 }
10849 return hints;
10850 }
10851 throw new Error("Hint array in the linearization dictionary is invalid.");
10852 }
10853 const parser = new Parser({
10854 lexer: new Lexer(stream),
10855 xref: null
10856 });
10857 const obj1 = parser.getObj();
10858 const obj2 = parser.getObj();
10859 const obj3 = parser.getObj();
10860 const linDict = parser.getObj();
10861 let obj, length;
10862 if (!(Number.isInteger(obj1) && Number.isInteger(obj2) && isCmd(obj3, "obj") && linDict instanceof Dict && typeof (obj = linDict.get("Linearized")) === "number" && obj > 0)) {
10863 return null;
10864 } else if ((length = getInt(linDict, "L")) !== stream.length) {
10865 throw new Error('The "L" parameter in the linearization dictionary ' + "does not equal the stream length.");
10866 }
10867 return {
10868 length,
10869 hints: getHints(linDict),
10870 objectNumberFirst: getInt(linDict, "O"),
10871 endFirst: getInt(linDict, "E"),
10872 numPages: getInt(linDict, "N"),
10873 mainXRefEntriesOffset: getInt(linDict, "T"),
10874 pageFirst: linDict.has("P") ? getInt(linDict, "P", true) : 0
10875 };
10876 }
10877}
10878
10879;// CONCATENATED MODULE: ./src/core/cmap.js
10880
10881
10882
10883
10884
10885
10886
10887const 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"];
10888const MAX_MAP_RANGE = 2 ** 24 - 1;
10889class CMap {
10890 constructor(builtInCMap = false) {
10891 this.codespaceRanges = [[], [], [], []];
10892 this.numCodespaceRanges = 0;
10893 this._map = [];
10894 this.name = "";
10895 this.vertical = false;
10896 this.useCMap = null;
10897 this.builtInCMap = builtInCMap;
10898 }
10899 addCodespaceRange(n, low, high) {
10900 this.codespaceRanges[n - 1].push(low, high);
10901 this.numCodespaceRanges++;
10902 }
10903 mapCidRange(low, high, dstLow) {
10904 if (high - low > MAX_MAP_RANGE) {
10905 throw new Error("mapCidRange - ignoring data above MAX_MAP_RANGE.");
10906 }
10907 while (low <= high) {
10908 this._map[low++] = dstLow++;
10909 }
10910 }
10911 mapBfRange(low, high, dstLow) {
10912 if (high - low > MAX_MAP_RANGE) {
10913 throw new Error("mapBfRange - ignoring data above MAX_MAP_RANGE.");
10914 }
10915 const lastByte = dstLow.length - 1;
10916 while (low <= high) {
10917 this._map[low++] = dstLow;
10918 const nextCharCode = dstLow.charCodeAt(lastByte) + 1;
10919 if (nextCharCode > 0xff) {
10920 dstLow = dstLow.substring(0, lastByte - 1) + String.fromCharCode(dstLow.charCodeAt(lastByte - 1) + 1) + "\x00";
10921 continue;
10922 }
10923 dstLow = dstLow.substring(0, lastByte) + String.fromCharCode(nextCharCode);
10924 }
10925 }
10926 mapBfRangeToArray(low, high, array) {
10927 if (high - low > MAX_MAP_RANGE) {
10928 throw new Error("mapBfRangeToArray - ignoring data above MAX_MAP_RANGE.");
10929 }
10930 const ii = array.length;
10931 let i = 0;
10932 while (low <= high && i < ii) {
10933 this._map[low] = array[i++];
10934 ++low;
10935 }
10936 }
10937 mapOne(src, dst) {
10938 this._map[src] = dst;
10939 }
10940 lookup(code) {
10941 return this._map[code];
10942 }
10943 contains(code) {
10944 return this._map[code] !== undefined;
10945 }
10946 forEach(callback) {
10947 const map = this._map;
10948 const length = map.length;
10949 if (length <= 0x10000) {
10950 for (let i = 0; i < length; i++) {
10951 if (map[i] !== undefined) {
10952 callback(i, map[i]);
10953 }
10954 }
10955 } else {
10956 for (const i in map) {
10957 callback(i, map[i]);
10958 }
10959 }
10960 }
10961 charCodeOf(value) {
10962 const map = this._map;
10963 if (map.length <= 0x10000) {
10964 return map.indexOf(value);
10965 }
10966 for (const charCode in map) {
10967 if (map[charCode] === value) {
10968 return charCode | 0;
10969 }
10970 }
10971 return -1;
10972 }
10973 getMap() {
10974 return this._map;
10975 }
10976 readCharCode(str, offset, out) {
10977 let c = 0;
10978 const codespaceRanges = this.codespaceRanges;
10979 for (let n = 0, nn = codespaceRanges.length; n < nn; n++) {
10980 c = (c << 8 | str.charCodeAt(offset + n)) >>> 0;
10981 const codespaceRange = codespaceRanges[n];
10982 for (let k = 0, kk = codespaceRange.length; k < kk;) {
10983 const low = codespaceRange[k++];
10984 const high = codespaceRange[k++];
10985 if (c >= low && c <= high) {
10986 out.charcode = c;
10987 out.length = n + 1;
10988 return;
10989 }
10990 }
10991 }
10992 out.charcode = 0;
10993 out.length = 1;
10994 }
10995 getCharCodeLength(charCode) {
10996 const codespaceRanges = this.codespaceRanges;
10997 for (let n = 0, nn = codespaceRanges.length; n < nn; n++) {
10998 const codespaceRange = codespaceRanges[n];
10999 for (let k = 0, kk = codespaceRange.length; k < kk;) {
11000 const low = codespaceRange[k++];
11001 const high = codespaceRange[k++];
11002 if (charCode >= low && charCode <= high) {
11003 return n + 1;
11004 }
11005 }
11006 }
11007 return 1;
11008 }
11009 get length() {
11010 return this._map.length;
11011 }
11012 get isIdentityCMap() {
11013 if (!(this.name === "Identity-H" || this.name === "Identity-V")) {
11014 return false;
11015 }
11016 if (this._map.length !== 0x10000) {
11017 return false;
11018 }
11019 for (let i = 0; i < 0x10000; i++) {
11020 if (this._map[i] !== i) {
11021 return false;
11022 }
11023 }
11024 return true;
11025 }
11026}
11027class IdentityCMap extends CMap {
11028 constructor(vertical, n) {
11029 super();
11030 this.vertical = vertical;
11031 this.addCodespaceRange(n, 0, 0xffff);
11032 }
11033 mapCidRange(low, high, dstLow) {
11034 unreachable("should not call mapCidRange");
11035 }
11036 mapBfRange(low, high, dstLow) {
11037 unreachable("should not call mapBfRange");
11038 }
11039 mapBfRangeToArray(low, high, array) {
11040 unreachable("should not call mapBfRangeToArray");
11041 }
11042 mapOne(src, dst) {
11043 unreachable("should not call mapCidOne");
11044 }
11045 lookup(code) {
11046 return Number.isInteger(code) && code <= 0xffff ? code : undefined;
11047 }
11048 contains(code) {
11049 return Number.isInteger(code) && code <= 0xffff;
11050 }
11051 forEach(callback) {
11052 for (let i = 0; i <= 0xffff; i++) {
11053 callback(i, i);
11054 }
11055 }
11056 charCodeOf(value) {
11057 return Number.isInteger(value) && value <= 0xffff ? value : -1;
11058 }
11059 getMap() {
11060 const map = new Array(0x10000);
11061 for (let i = 0; i <= 0xffff; i++) {
11062 map[i] = i;
11063 }
11064 return map;
11065 }
11066 get length() {
11067 return 0x10000;
11068 }
11069 get isIdentityCMap() {
11070 unreachable("should not access .isIdentityCMap");
11071 }
11072}
11073function strToInt(str) {
11074 let a = 0;
11075 for (let i = 0; i < str.length; i++) {
11076 a = a << 8 | str.charCodeAt(i);
11077 }
11078 return a >>> 0;
11079}
11080function expectString(obj) {
11081 if (typeof obj !== "string") {
11082 throw new FormatError("Malformed CMap: expected string.");
11083 }
11084}
11085function expectInt(obj) {
11086 if (!Number.isInteger(obj)) {
11087 throw new FormatError("Malformed CMap: expected int.");
11088 }
11089}
11090function parseBfChar(cMap, lexer) {
11091 while (true) {
11092 let obj = lexer.getObj();
11093 if (obj === EOF) {
11094 break;
11095 }
11096 if (isCmd(obj, "endbfchar")) {
11097 return;
11098 }
11099 expectString(obj);
11100 const src = strToInt(obj);
11101 obj = lexer.getObj();
11102 expectString(obj);
11103 const dst = obj;
11104 cMap.mapOne(src, dst);
11105 }
11106}
11107function parseBfRange(cMap, lexer) {
11108 while (true) {
11109 let obj = lexer.getObj();
11110 if (obj === EOF) {
11111 break;
11112 }
11113 if (isCmd(obj, "endbfrange")) {
11114 return;
11115 }
11116 expectString(obj);
11117 const low = strToInt(obj);
11118 obj = lexer.getObj();
11119 expectString(obj);
11120 const high = strToInt(obj);
11121 obj = lexer.getObj();
11122 if (Number.isInteger(obj) || typeof obj === "string") {
11123 const dstLow = Number.isInteger(obj) ? String.fromCharCode(obj) : obj;
11124 cMap.mapBfRange(low, high, dstLow);
11125 } else if (isCmd(obj, "[")) {
11126 obj = lexer.getObj();
11127 const array = [];
11128 while (!isCmd(obj, "]") && obj !== EOF) {
11129 array.push(obj);
11130 obj = lexer.getObj();
11131 }
11132 cMap.mapBfRangeToArray(low, high, array);
11133 } else {
11134 break;
11135 }
11136 }
11137 throw new FormatError("Invalid bf range.");
11138}
11139function parseCidChar(cMap, lexer) {
11140 while (true) {
11141 let obj = lexer.getObj();
11142 if (obj === EOF) {
11143 break;
11144 }
11145 if (isCmd(obj, "endcidchar")) {
11146 return;
11147 }
11148 expectString(obj);
11149 const src = strToInt(obj);
11150 obj = lexer.getObj();
11151 expectInt(obj);
11152 const dst = obj;
11153 cMap.mapOne(src, dst);
11154 }
11155}
11156function parseCidRange(cMap, lexer) {
11157 while (true) {
11158 let obj = lexer.getObj();
11159 if (obj === EOF) {
11160 break;
11161 }
11162 if (isCmd(obj, "endcidrange")) {
11163 return;
11164 }
11165 expectString(obj);
11166 const low = strToInt(obj);
11167 obj = lexer.getObj();
11168 expectString(obj);
11169 const high = strToInt(obj);
11170 obj = lexer.getObj();
11171 expectInt(obj);
11172 const dstLow = obj;
11173 cMap.mapCidRange(low, high, dstLow);
11174 }
11175}
11176function parseCodespaceRange(cMap, lexer) {
11177 while (true) {
11178 let obj = lexer.getObj();
11179 if (obj === EOF) {
11180 break;
11181 }
11182 if (isCmd(obj, "endcodespacerange")) {
11183 return;
11184 }
11185 if (typeof obj !== "string") {
11186 break;
11187 }
11188 const low = strToInt(obj);
11189 obj = lexer.getObj();
11190 if (typeof obj !== "string") {
11191 break;
11192 }
11193 const high = strToInt(obj);
11194 cMap.addCodespaceRange(obj.length, low, high);
11195 }
11196 throw new FormatError("Invalid codespace range.");
11197}
11198function parseWMode(cMap, lexer) {
11199 const obj = lexer.getObj();
11200 if (Number.isInteger(obj)) {
11201 cMap.vertical = !!obj;
11202 }
11203}
11204function parseCMapName(cMap, lexer) {
11205 const obj = lexer.getObj();
11206 if (obj instanceof Name) {
11207 cMap.name = obj.name;
11208 }
11209}
11210async function parseCMap(cMap, lexer, fetchBuiltInCMap, useCMap) {
11211 let previous, embeddedUseCMap;
11212 objLoop: while (true) {
11213 try {
11214 const obj = lexer.getObj();
11215 if (obj === EOF) {
11216 break;
11217 } else if (obj instanceof Name) {
11218 if (obj.name === "WMode") {
11219 parseWMode(cMap, lexer);
11220 } else if (obj.name === "CMapName") {
11221 parseCMapName(cMap, lexer);
11222 }
11223 previous = obj;
11224 } else if (obj instanceof Cmd) {
11225 switch (obj.cmd) {
11226 case "endcmap":
11227 break objLoop;
11228 case "usecmap":
11229 if (previous instanceof Name) {
11230 embeddedUseCMap = previous.name;
11231 }
11232 break;
11233 case "begincodespacerange":
11234 parseCodespaceRange(cMap, lexer);
11235 break;
11236 case "beginbfchar":
11237 parseBfChar(cMap, lexer);
11238 break;
11239 case "begincidchar":
11240 parseCidChar(cMap, lexer);
11241 break;
11242 case "beginbfrange":
11243 parseBfRange(cMap, lexer);
11244 break;
11245 case "begincidrange":
11246 parseCidRange(cMap, lexer);
11247 break;
11248 }
11249 }
11250 } catch (ex) {
11251 if (ex instanceof MissingDataException) {
11252 throw ex;
11253 }
11254 warn("Invalid cMap data: " + ex);
11255 continue;
11256 }
11257 }
11258 if (!useCMap && embeddedUseCMap) {
11259 useCMap = embeddedUseCMap;
11260 }
11261 if (useCMap) {
11262 return extendCMap(cMap, fetchBuiltInCMap, useCMap);
11263 }
11264 return cMap;
11265}
11266async function extendCMap(cMap, fetchBuiltInCMap, useCMap) {
11267 cMap.useCMap = await createBuiltInCMap(useCMap, fetchBuiltInCMap);
11268 if (cMap.numCodespaceRanges === 0) {
11269 const useCodespaceRanges = cMap.useCMap.codespaceRanges;
11270 for (let i = 0; i < useCodespaceRanges.length; i++) {
11271 cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
11272 }
11273 cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
11274 }
11275 cMap.useCMap.forEach(function (key, value) {
11276 if (!cMap.contains(key)) {
11277 cMap.mapOne(key, cMap.useCMap.lookup(key));
11278 }
11279 });
11280 return cMap;
11281}
11282async function createBuiltInCMap(name, fetchBuiltInCMap) {
11283 if (name === "Identity-H") {
11284 return new IdentityCMap(false, 2);
11285 } else if (name === "Identity-V") {
11286 return new IdentityCMap(true, 2);
11287 }
11288 if (!BUILT_IN_CMAPS.includes(name)) {
11289 throw new Error("Unknown CMap name: " + name);
11290 }
11291 if (!fetchBuiltInCMap) {
11292 throw new Error("Built-in CMap parameters are not provided.");
11293 }
11294 const {
11295 cMapData,
11296 compressionType
11297 } = await fetchBuiltInCMap(name);
11298 const cMap = new CMap(true);
11299 if (compressionType === CMapCompressionType.BINARY) {
11300 return new BinaryCMapReader().process(cMapData, cMap, useCMap => extendCMap(cMap, fetchBuiltInCMap, useCMap));
11301 }
11302 if (compressionType === CMapCompressionType.NONE) {
11303 const lexer = new Lexer(new Stream(cMapData));
11304 return parseCMap(cMap, lexer, fetchBuiltInCMap, null);
11305 }
11306 throw new Error(`Invalid CMap "compressionType" value: ${compressionType}`);
11307}
11308class CMapFactory {
11309 static async create({
11310 encoding,
11311 fetchBuiltInCMap,
11312 useCMap
11313 }) {
11314 if (encoding instanceof Name) {
11315 return createBuiltInCMap(encoding.name, fetchBuiltInCMap);
11316 } else if (encoding instanceof BaseStream) {
11317 const parsedCMap = await parseCMap(new CMap(), new Lexer(encoding), fetchBuiltInCMap, useCMap);
11318 if (parsedCMap.isIdentityCMap) {
11319 return createBuiltInCMap(parsedCMap.name, fetchBuiltInCMap);
11320 }
11321 return parsedCMap;
11322 }
11323 throw new Error("Encoding required.");
11324 }
11325}
11326
11327;// CONCATENATED MODULE: ./src/core/charsets.js
11328const 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", "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"];
11329const 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"];
11330const 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"];
11331
11332;// CONCATENATED MODULE: ./src/core/encodings.js
11333const 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"];
11334const 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", "", "", "", ""];
11335const 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", "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"];
11336const 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", "", "", "", ""];
11337const 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"];
11338const 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", ""];
11339const 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", ""];
11340function getEncoding(encodingName) {
11341 switch (encodingName) {
11342 case "WinAnsiEncoding":
11343 return WinAnsiEncoding;
11344 case "StandardEncoding":
11345 return StandardEncoding;
11346 case "MacRomanEncoding":
11347 return MacRomanEncoding;
11348 case "SymbolSetEncoding":
11349 return SymbolSetEncoding;
11350 case "ZapfDingbatsEncoding":
11351 return ZapfDingbatsEncoding;
11352 case "ExpertEncoding":
11353 return ExpertEncoding;
11354 case "MacExpertEncoding":
11355 return MacExpertEncoding;
11356 default:
11357 return null;
11358 }
11359}
11360
11361;// CONCATENATED MODULE: ./src/core/cff_parser.js
11362
11363
11364
11365const MAX_SUBR_NESTING = 10;
11366const 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"];
11367const NUM_STANDARD_CFF_STRINGS = 391;
11368const CharstringValidationData = [null, {
11369 id: "hstem",
11370 min: 2,
11371 stackClearing: true,
11372 stem: true
11373}, null, {
11374 id: "vstem",
11375 min: 2,
11376 stackClearing: true,
11377 stem: true
11378}, {
11379 id: "vmoveto",
11380 min: 1,
11381 stackClearing: true
11382}, {
11383 id: "rlineto",
11384 min: 2,
11385 resetStack: true
11386}, {
11387 id: "hlineto",
11388 min: 1,
11389 resetStack: true
11390}, {
11391 id: "vlineto",
11392 min: 1,
11393 resetStack: true
11394}, {
11395 id: "rrcurveto",
11396 min: 6,
11397 resetStack: true
11398}, null, {
11399 id: "callsubr",
11400 min: 1,
11401 undefStack: true
11402}, {
11403 id: "return",
11404 min: 0,
11405 undefStack: true
11406}, null, null, {
11407 id: "endchar",
11408 min: 0,
11409 stackClearing: true
11410}, null, null, null, {
11411 id: "hstemhm",
11412 min: 2,
11413 stackClearing: true,
11414 stem: true
11415}, {
11416 id: "hintmask",
11417 min: 0,
11418 stackClearing: true
11419}, {
11420 id: "cntrmask",
11421 min: 0,
11422 stackClearing: true
11423}, {
11424 id: "rmoveto",
11425 min: 2,
11426 stackClearing: true
11427}, {
11428 id: "hmoveto",
11429 min: 1,
11430 stackClearing: true
11431}, {
11432 id: "vstemhm",
11433 min: 2,
11434 stackClearing: true,
11435 stem: true
11436}, {
11437 id: "rcurveline",
11438 min: 8,
11439 resetStack: true
11440}, {
11441 id: "rlinecurve",
11442 min: 8,
11443 resetStack: true
11444}, {
11445 id: "vvcurveto",
11446 min: 4,
11447 resetStack: true
11448}, {
11449 id: "hhcurveto",
11450 min: 4,
11451 resetStack: true
11452}, null, {
11453 id: "callgsubr",
11454 min: 1,
11455 undefStack: true
11456}, {
11457 id: "vhcurveto",
11458 min: 4,
11459 resetStack: true
11460}, {
11461 id: "hvcurveto",
11462 min: 4,
11463 resetStack: true
11464}];
11465const CharstringValidationData12 = [null, null, null, {
11466 id: "and",
11467 min: 2,
11468 stackDelta: -1
11469}, {
11470 id: "or",
11471 min: 2,
11472 stackDelta: -1
11473}, {
11474 id: "not",
11475 min: 1,
11476 stackDelta: 0
11477}, null, null, null, {
11478 id: "abs",
11479 min: 1,
11480 stackDelta: 0
11481}, {
11482 id: "add",
11483 min: 2,
11484 stackDelta: -1,
11485 stackFn(stack, index) {
11486 stack[index - 2] = stack[index - 2] + stack[index - 1];
11487 }
11488}, {
11489 id: "sub",
11490 min: 2,
11491 stackDelta: -1,
11492 stackFn(stack, index) {
11493 stack[index - 2] = stack[index - 2] - stack[index - 1];
11494 }
11495}, {
11496 id: "div",
11497 min: 2,
11498 stackDelta: -1,
11499 stackFn(stack, index) {
11500 stack[index - 2] = stack[index - 2] / stack[index - 1];
11501 }
11502}, null, {
11503 id: "neg",
11504 min: 1,
11505 stackDelta: 0,
11506 stackFn(stack, index) {
11507 stack[index - 1] = -stack[index - 1];
11508 }
11509}, {
11510 id: "eq",
11511 min: 2,
11512 stackDelta: -1
11513}, null, null, {
11514 id: "drop",
11515 min: 1,
11516 stackDelta: -1
11517}, null, {
11518 id: "put",
11519 min: 2,
11520 stackDelta: -2
11521}, {
11522 id: "get",
11523 min: 1,
11524 stackDelta: 0
11525}, {
11526 id: "ifelse",
11527 min: 4,
11528 stackDelta: -3
11529}, {
11530 id: "random",
11531 min: 0,
11532 stackDelta: 1
11533}, {
11534 id: "mul",
11535 min: 2,
11536 stackDelta: -1,
11537 stackFn(stack, index) {
11538 stack[index - 2] = stack[index - 2] * stack[index - 1];
11539 }
11540}, null, {
11541 id: "sqrt",
11542 min: 1,
11543 stackDelta: 0
11544}, {
11545 id: "dup",
11546 min: 1,
11547 stackDelta: 1
11548}, {
11549 id: "exch",
11550 min: 2,
11551 stackDelta: 0
11552}, {
11553 id: "index",
11554 min: 2,
11555 stackDelta: 0
11556}, {
11557 id: "roll",
11558 min: 3,
11559 stackDelta: -2
11560}, null, null, null, {
11561 id: "hflex",
11562 min: 7,
11563 resetStack: true
11564}, {
11565 id: "flex",
11566 min: 13,
11567 resetStack: true
11568}, {
11569 id: "hflex1",
11570 min: 9,
11571 resetStack: true
11572}, {
11573 id: "flex1",
11574 min: 11,
11575 resetStack: true
11576}];
11577class CFFParser {
11578 constructor(file, properties, seacAnalysisEnabled) {
11579 this.bytes = file.getBytes();
11580 this.properties = properties;
11581 this.seacAnalysisEnabled = !!seacAnalysisEnabled;
11582 }
11583 parse() {
11584 const properties = this.properties;
11585 const cff = new CFF();
11586 this.cff = cff;
11587 const header = this.parseHeader();
11588 const nameIndex = this.parseIndex(header.endPos);
11589 const topDictIndex = this.parseIndex(nameIndex.endPos);
11590 const stringIndex = this.parseIndex(topDictIndex.endPos);
11591 const globalSubrIndex = this.parseIndex(stringIndex.endPos);
11592 const topDictParsed = this.parseDict(topDictIndex.obj.get(0));
11593 const topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
11594 cff.header = header.obj;
11595 cff.names = this.parseNameIndex(nameIndex.obj);
11596 cff.strings = this.parseStringIndex(stringIndex.obj);
11597 cff.topDict = topDict;
11598 cff.globalSubrIndex = globalSubrIndex.obj;
11599 this.parsePrivateDict(cff.topDict);
11600 cff.isCIDFont = topDict.hasName("ROS");
11601 const charStringOffset = topDict.getByName("CharStrings");
11602 const charStringIndex = this.parseIndex(charStringOffset).obj;
11603 const fontMatrix = topDict.getByName("FontMatrix");
11604 if (fontMatrix) {
11605 properties.fontMatrix = fontMatrix;
11606 }
11607 const fontBBox = topDict.getByName("FontBBox");
11608 if (fontBBox) {
11609 properties.ascent = Math.max(fontBBox[3], fontBBox[1]);
11610 properties.descent = Math.min(fontBBox[1], fontBBox[3]);
11611 properties.ascentScaled = true;
11612 }
11613 let charset, encoding;
11614 if (cff.isCIDFont) {
11615 const fdArrayIndex = this.parseIndex(topDict.getByName("FDArray")).obj;
11616 for (let i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
11617 const dictRaw = fdArrayIndex.get(i);
11618 const fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw), cff.strings);
11619 this.parsePrivateDict(fontDict);
11620 cff.fdArray.push(fontDict);
11621 }
11622 encoding = null;
11623 charset = this.parseCharsets(topDict.getByName("charset"), charStringIndex.count, cff.strings, true);
11624 cff.fdSelect = this.parseFDSelect(topDict.getByName("FDSelect"), charStringIndex.count);
11625 } else {
11626 charset = this.parseCharsets(topDict.getByName("charset"), charStringIndex.count, cff.strings, false);
11627 encoding = this.parseEncoding(topDict.getByName("Encoding"), properties, cff.strings, charset.charset);
11628 }
11629 cff.charset = charset;
11630 cff.encoding = encoding;
11631 const charStringsAndSeacs = this.parseCharStrings({
11632 charStrings: charStringIndex,
11633 localSubrIndex: topDict.privateDict.subrsIndex,
11634 globalSubrIndex: globalSubrIndex.obj,
11635 fdSelect: cff.fdSelect,
11636 fdArray: cff.fdArray,
11637 privateDict: topDict.privateDict
11638 });
11639 cff.charStrings = charStringsAndSeacs.charStrings;
11640 cff.seacs = charStringsAndSeacs.seacs;
11641 cff.widths = charStringsAndSeacs.widths;
11642 return cff;
11643 }
11644 parseHeader() {
11645 let bytes = this.bytes;
11646 const bytesLength = bytes.length;
11647 let offset = 0;
11648 while (offset < bytesLength && bytes[offset] !== 1) {
11649 ++offset;
11650 }
11651 if (offset >= bytesLength) {
11652 throw new FormatError("Invalid CFF header");
11653 }
11654 if (offset !== 0) {
11655 info("cff data is shifted");
11656 bytes = bytes.subarray(offset);
11657 this.bytes = bytes;
11658 }
11659 const major = bytes[0];
11660 const minor = bytes[1];
11661 const hdrSize = bytes[2];
11662 const offSize = bytes[3];
11663 const header = new CFFHeader(major, minor, hdrSize, offSize);
11664 return {
11665 obj: header,
11666 endPos: hdrSize
11667 };
11668 }
11669 parseDict(dict) {
11670 let pos = 0;
11671 function parseOperand() {
11672 let value = dict[pos++];
11673 if (value === 30) {
11674 return parseFloatOperand();
11675 } else if (value === 28) {
11676 value = dict[pos++];
11677 value = (value << 24 | dict[pos++] << 16) >> 16;
11678 return value;
11679 } else if (value === 29) {
11680 value = dict[pos++];
11681 value = value << 8 | dict[pos++];
11682 value = value << 8 | dict[pos++];
11683 value = value << 8 | dict[pos++];
11684 return value;
11685 } else if (value >= 32 && value <= 246) {
11686 return value - 139;
11687 } else if (value >= 247 && value <= 250) {
11688 return (value - 247) * 256 + dict[pos++] + 108;
11689 } else if (value >= 251 && value <= 254) {
11690 return -((value - 251) * 256) - dict[pos++] - 108;
11691 }
11692 warn('CFFParser_parseDict: "' + value + '" is a reserved command.');
11693 return NaN;
11694 }
11695 function parseFloatOperand() {
11696 let str = "";
11697 const eof = 15;
11698 const lookup = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ".", "E", "E-", null, "-"];
11699 const length = dict.length;
11700 while (pos < length) {
11701 const b = dict[pos++];
11702 const b1 = b >> 4;
11703 const b2 = b & 15;
11704 if (b1 === eof) {
11705 break;
11706 }
11707 str += lookup[b1];
11708 if (b2 === eof) {
11709 break;
11710 }
11711 str += lookup[b2];
11712 }
11713 return parseFloat(str);
11714 }
11715 let operands = [];
11716 const entries = [];
11717 pos = 0;
11718 const end = dict.length;
11719 while (pos < end) {
11720 let b = dict[pos];
11721 if (b <= 21) {
11722 if (b === 12) {
11723 b = b << 8 | dict[++pos];
11724 }
11725 entries.push([b, operands]);
11726 operands = [];
11727 ++pos;
11728 } else {
11729 operands.push(parseOperand());
11730 }
11731 }
11732 return entries;
11733 }
11734 parseIndex(pos) {
11735 const cffIndex = new CFFIndex();
11736 const bytes = this.bytes;
11737 const count = bytes[pos++] << 8 | bytes[pos++];
11738 const offsets = [];
11739 let end = pos;
11740 let i, ii;
11741 if (count !== 0) {
11742 const offsetSize = bytes[pos++];
11743 const startPos = pos + (count + 1) * offsetSize - 1;
11744 for (i = 0, ii = count + 1; i < ii; ++i) {
11745 let offset = 0;
11746 for (let j = 0; j < offsetSize; ++j) {
11747 offset <<= 8;
11748 offset += bytes[pos++];
11749 }
11750 offsets.push(startPos + offset);
11751 }
11752 end = offsets[count];
11753 }
11754 for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
11755 const offsetStart = offsets[i];
11756 const offsetEnd = offsets[i + 1];
11757 cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
11758 }
11759 return {
11760 obj: cffIndex,
11761 endPos: end
11762 };
11763 }
11764 parseNameIndex(index) {
11765 const names = [];
11766 for (let i = 0, ii = index.count; i < ii; ++i) {
11767 const name = index.get(i);
11768 names.push(bytesToString(name));
11769 }
11770 return names;
11771 }
11772 parseStringIndex(index) {
11773 const strings = new CFFStrings();
11774 for (let i = 0, ii = index.count; i < ii; ++i) {
11775 const data = index.get(i);
11776 strings.add(bytesToString(data));
11777 }
11778 return strings;
11779 }
11780 createDict(Type, dict, strings) {
11781 const cffDict = new Type(strings);
11782 for (const [key, value] of dict) {
11783 cffDict.setByKey(key, value);
11784 }
11785 return cffDict;
11786 }
11787 parseCharString(state, data, localSubrIndex, globalSubrIndex) {
11788 if (!data || state.callDepth > MAX_SUBR_NESTING) {
11789 return false;
11790 }
11791 let stackSize = state.stackSize;
11792 const stack = state.stack;
11793 let length = data.length;
11794 for (let j = 0; j < length;) {
11795 const value = data[j++];
11796 let validationCommand = null;
11797 if (value === 12) {
11798 const q = data[j++];
11799 if (q === 0) {
11800 data[j - 2] = 139;
11801 data[j - 1] = 22;
11802 stackSize = 0;
11803 } else {
11804 validationCommand = CharstringValidationData12[q];
11805 }
11806 } else if (value === 28) {
11807 stack[stackSize] = (data[j] << 24 | data[j + 1] << 16) >> 16;
11808 j += 2;
11809 stackSize++;
11810 } else if (value === 14) {
11811 if (stackSize >= 4) {
11812 stackSize -= 4;
11813 if (this.seacAnalysisEnabled) {
11814 state.seac = stack.slice(stackSize, stackSize + 4);
11815 return false;
11816 }
11817 }
11818 validationCommand = CharstringValidationData[value];
11819 } else if (value >= 32 && value <= 246) {
11820 stack[stackSize] = value - 139;
11821 stackSize++;
11822 } else if (value >= 247 && value <= 254) {
11823 stack[stackSize] = value < 251 ? (value - 247 << 8) + data[j] + 108 : -(value - 251 << 8) - data[j] - 108;
11824 j++;
11825 stackSize++;
11826 } else if (value === 255) {
11827 stack[stackSize] = (data[j] << 24 | data[j + 1] << 16 | data[j + 2] << 8 | data[j + 3]) / 65536;
11828 j += 4;
11829 stackSize++;
11830 } else if (value === 19 || value === 20) {
11831 state.hints += stackSize >> 1;
11832 if (state.hints === 0) {
11833 data.copyWithin(j - 1, j, -1);
11834 j -= 1;
11835 length -= 1;
11836 continue;
11837 }
11838 j += state.hints + 7 >> 3;
11839 stackSize %= 2;
11840 validationCommand = CharstringValidationData[value];
11841 } else if (value === 10 || value === 29) {
11842 const subrsIndex = value === 10 ? localSubrIndex : globalSubrIndex;
11843 if (!subrsIndex) {
11844 validationCommand = CharstringValidationData[value];
11845 warn("Missing subrsIndex for " + validationCommand.id);
11846 return false;
11847 }
11848 let bias = 32768;
11849 if (subrsIndex.count < 1240) {
11850 bias = 107;
11851 } else if (subrsIndex.count < 33900) {
11852 bias = 1131;
11853 }
11854 const subrNumber = stack[--stackSize] + bias;
11855 if (subrNumber < 0 || subrNumber >= subrsIndex.count || isNaN(subrNumber)) {
11856 validationCommand = CharstringValidationData[value];
11857 warn("Out of bounds subrIndex for " + validationCommand.id);
11858 return false;
11859 }
11860 state.stackSize = stackSize;
11861 state.callDepth++;
11862 const valid = this.parseCharString(state, subrsIndex.get(subrNumber), localSubrIndex, globalSubrIndex);
11863 if (!valid) {
11864 return false;
11865 }
11866 state.callDepth--;
11867 stackSize = state.stackSize;
11868 continue;
11869 } else if (value === 11) {
11870 state.stackSize = stackSize;
11871 return true;
11872 } else if (value === 0 && j === data.length) {
11873 data[j - 1] = 14;
11874 validationCommand = CharstringValidationData[14];
11875 } else if (value === 9) {
11876 data.copyWithin(j - 1, j, -1);
11877 j -= 1;
11878 length -= 1;
11879 continue;
11880 } else {
11881 validationCommand = CharstringValidationData[value];
11882 }
11883 if (validationCommand) {
11884 if (validationCommand.stem) {
11885 state.hints += stackSize >> 1;
11886 if (value === 3 || value === 23) {
11887 state.hasVStems = true;
11888 } else if (state.hasVStems && (value === 1 || value === 18)) {
11889 warn("CFF stem hints are in wrong order");
11890 data[j - 1] = value === 1 ? 3 : 23;
11891 }
11892 }
11893 if ("min" in validationCommand) {
11894 if (!state.undefStack && stackSize < validationCommand.min) {
11895 warn("Not enough parameters for " + validationCommand.id + "; actual: " + stackSize + ", expected: " + validationCommand.min);
11896 if (stackSize === 0) {
11897 data[j - 1] = 14;
11898 return true;
11899 }
11900 return false;
11901 }
11902 }
11903 if (state.firstStackClearing && validationCommand.stackClearing) {
11904 state.firstStackClearing = false;
11905 stackSize -= validationCommand.min;
11906 if (stackSize >= 2 && validationCommand.stem) {
11907 stackSize %= 2;
11908 } else if (stackSize > 1) {
11909 warn("Found too many parameters for stack-clearing command");
11910 }
11911 if (stackSize > 0) {
11912 state.width = stack[stackSize - 1];
11913 }
11914 }
11915 if ("stackDelta" in validationCommand) {
11916 if ("stackFn" in validationCommand) {
11917 validationCommand.stackFn(stack, stackSize);
11918 }
11919 stackSize += validationCommand.stackDelta;
11920 } else if (validationCommand.stackClearing) {
11921 stackSize = 0;
11922 } else if (validationCommand.resetStack) {
11923 stackSize = 0;
11924 state.undefStack = false;
11925 } else if (validationCommand.undefStack) {
11926 stackSize = 0;
11927 state.undefStack = true;
11928 state.firstStackClearing = false;
11929 }
11930 }
11931 }
11932 if (length < data.length) {
11933 data.fill(14, length);
11934 }
11935 state.stackSize = stackSize;
11936 return true;
11937 }
11938 parseCharStrings({
11939 charStrings,
11940 localSubrIndex,
11941 globalSubrIndex,
11942 fdSelect,
11943 fdArray,
11944 privateDict
11945 }) {
11946 const seacs = [];
11947 const widths = [];
11948 const count = charStrings.count;
11949 for (let i = 0; i < count; i++) {
11950 const charstring = charStrings.get(i);
11951 const state = {
11952 callDepth: 0,
11953 stackSize: 0,
11954 stack: [],
11955 undefStack: true,
11956 hints: 0,
11957 firstStackClearing: true,
11958 seac: null,
11959 width: null,
11960 hasVStems: false
11961 };
11962 let valid = true;
11963 let localSubrToUse = null;
11964 let privateDictToUse = privateDict;
11965 if (fdSelect && fdArray.length) {
11966 const fdIndex = fdSelect.getFDIndex(i);
11967 if (fdIndex === -1) {
11968 warn("Glyph index is not in fd select.");
11969 valid = false;
11970 }
11971 if (fdIndex >= fdArray.length) {
11972 warn("Invalid fd index for glyph index.");
11973 valid = false;
11974 }
11975 if (valid) {
11976 privateDictToUse = fdArray[fdIndex].privateDict;
11977 localSubrToUse = privateDictToUse.subrsIndex;
11978 }
11979 } else if (localSubrIndex) {
11980 localSubrToUse = localSubrIndex;
11981 }
11982 if (valid) {
11983 valid = this.parseCharString(state, charstring, localSubrToUse, globalSubrIndex);
11984 }
11985 if (state.width !== null) {
11986 const nominalWidth = privateDictToUse.getByName("nominalWidthX");
11987 widths[i] = nominalWidth + state.width;
11988 } else {
11989 const defaultWidth = privateDictToUse.getByName("defaultWidthX");
11990 widths[i] = defaultWidth;
11991 }
11992 if (state.seac !== null) {
11993 seacs[i] = state.seac;
11994 }
11995 if (!valid) {
11996 charStrings.set(i, new Uint8Array([14]));
11997 }
11998 }
11999 return {
12000 charStrings,
12001 seacs,
12002 widths
12003 };
12004 }
12005 emptyPrivateDictionary(parentDict) {
12006 const privateDict = this.createDict(CFFPrivateDict, [], parentDict.strings);
12007 parentDict.setByKey(18, [0, 0]);
12008 parentDict.privateDict = privateDict;
12009 }
12010 parsePrivateDict(parentDict) {
12011 if (!parentDict.hasName("Private")) {
12012 this.emptyPrivateDictionary(parentDict);
12013 return;
12014 }
12015 const privateOffset = parentDict.getByName("Private");
12016 if (!Array.isArray(privateOffset) || privateOffset.length !== 2) {
12017 parentDict.removeByName("Private");
12018 return;
12019 }
12020 const size = privateOffset[0];
12021 const offset = privateOffset[1];
12022 if (size === 0 || offset >= this.bytes.length) {
12023 this.emptyPrivateDictionary(parentDict);
12024 return;
12025 }
12026 const privateDictEnd = offset + size;
12027 const dictData = this.bytes.subarray(offset, privateDictEnd);
12028 const dict = this.parseDict(dictData);
12029 const privateDict = this.createDict(CFFPrivateDict, dict, parentDict.strings);
12030 parentDict.privateDict = privateDict;
12031 if (privateDict.getByName("ExpansionFactor") === 0) {
12032 privateDict.setByName("ExpansionFactor", 0.06);
12033 }
12034 if (!privateDict.getByName("Subrs")) {
12035 return;
12036 }
12037 const subrsOffset = privateDict.getByName("Subrs");
12038 const relativeOffset = offset + subrsOffset;
12039 if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
12040 this.emptyPrivateDictionary(parentDict);
12041 return;
12042 }
12043 const subrsIndex = this.parseIndex(relativeOffset);
12044 privateDict.subrsIndex = subrsIndex.obj;
12045 }
12046 parseCharsets(pos, length, strings, cid) {
12047 if (pos === 0) {
12048 return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE, ISOAdobeCharset);
12049 } else if (pos === 1) {
12050 return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT, ExpertCharset);
12051 } else if (pos === 2) {
12052 return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET, ExpertSubsetCharset);
12053 }
12054 const bytes = this.bytes;
12055 const start = pos;
12056 const format = bytes[pos++];
12057 const charset = [cid ? 0 : ".notdef"];
12058 let id, count, i;
12059 length -= 1;
12060 switch (format) {
12061 case 0:
12062 for (i = 0; i < length; i++) {
12063 id = bytes[pos++] << 8 | bytes[pos++];
12064 charset.push(cid ? id : strings.get(id));
12065 }
12066 break;
12067 case 1:
12068 while (charset.length <= length) {
12069 id = bytes[pos++] << 8 | bytes[pos++];
12070 count = bytes[pos++];
12071 for (i = 0; i <= count; i++) {
12072 charset.push(cid ? id++ : strings.get(id++));
12073 }
12074 }
12075 break;
12076 case 2:
12077 while (charset.length <= length) {
12078 id = bytes[pos++] << 8 | bytes[pos++];
12079 count = bytes[pos++] << 8 | bytes[pos++];
12080 for (i = 0; i <= count; i++) {
12081 charset.push(cid ? id++ : strings.get(id++));
12082 }
12083 }
12084 break;
12085 default:
12086 throw new FormatError("Unknown charset format");
12087 }
12088 const end = pos;
12089 const raw = bytes.subarray(start, end);
12090 return new CFFCharset(false, format, charset, raw);
12091 }
12092 parseEncoding(pos, properties, strings, charset) {
12093 const encoding = Object.create(null);
12094 const bytes = this.bytes;
12095 let predefined = false;
12096 let format, i, ii;
12097 let raw = null;
12098 function readSupplement() {
12099 const supplementsCount = bytes[pos++];
12100 for (i = 0; i < supplementsCount; i++) {
12101 const code = bytes[pos++];
12102 const sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
12103 encoding[code] = charset.indexOf(strings.get(sid));
12104 }
12105 }
12106 if (pos === 0 || pos === 1) {
12107 predefined = true;
12108 format = pos;
12109 const baseEncoding = pos ? ExpertEncoding : StandardEncoding;
12110 for (i = 0, ii = charset.length; i < ii; i++) {
12111 const index = baseEncoding.indexOf(charset[i]);
12112 if (index !== -1) {
12113 encoding[index] = i;
12114 }
12115 }
12116 } else {
12117 const dataStart = pos;
12118 format = bytes[pos++];
12119 switch (format & 0x7f) {
12120 case 0:
12121 const glyphsCount = bytes[pos++];
12122 for (i = 1; i <= glyphsCount; i++) {
12123 encoding[bytes[pos++]] = i;
12124 }
12125 break;
12126 case 1:
12127 const rangesCount = bytes[pos++];
12128 let gid = 1;
12129 for (i = 0; i < rangesCount; i++) {
12130 const start = bytes[pos++];
12131 const left = bytes[pos++];
12132 for (let j = start; j <= start + left; j++) {
12133 encoding[j] = gid++;
12134 }
12135 }
12136 break;
12137 default:
12138 throw new FormatError(`Unknown encoding format: ${format} in CFF`);
12139 }
12140 const dataEnd = pos;
12141 if (format & 0x80) {
12142 bytes[dataStart] &= 0x7f;
12143 readSupplement();
12144 }
12145 raw = bytes.subarray(dataStart, dataEnd);
12146 }
12147 format &= 0x7f;
12148 return new CFFEncoding(predefined, format, encoding, raw);
12149 }
12150 parseFDSelect(pos, length) {
12151 const bytes = this.bytes;
12152 const format = bytes[pos++];
12153 const fdSelect = [];
12154 let i;
12155 switch (format) {
12156 case 0:
12157 for (i = 0; i < length; ++i) {
12158 const id = bytes[pos++];
12159 fdSelect.push(id);
12160 }
12161 break;
12162 case 3:
12163 const rangesCount = bytes[pos++] << 8 | bytes[pos++];
12164 for (i = 0; i < rangesCount; ++i) {
12165 let first = bytes[pos++] << 8 | bytes[pos++];
12166 if (i === 0 && first !== 0) {
12167 warn("parseFDSelect: The first range must have a first GID of 0" + " -- trying to recover.");
12168 first = 0;
12169 }
12170 const fdIndex = bytes[pos++];
12171 const next = bytes[pos] << 8 | bytes[pos + 1];
12172 for (let j = first; j < next; ++j) {
12173 fdSelect.push(fdIndex);
12174 }
12175 }
12176 pos += 2;
12177 break;
12178 default:
12179 throw new FormatError(`parseFDSelect: Unknown format "${format}".`);
12180 }
12181 if (fdSelect.length !== length) {
12182 throw new FormatError("parseFDSelect: Invalid font data.");
12183 }
12184 return new CFFFDSelect(format, fdSelect);
12185 }
12186}
12187class CFF {
12188 constructor() {
12189 this.header = null;
12190 this.names = [];
12191 this.topDict = null;
12192 this.strings = new CFFStrings();
12193 this.globalSubrIndex = null;
12194 this.encoding = null;
12195 this.charset = null;
12196 this.charStrings = null;
12197 this.fdArray = [];
12198 this.fdSelect = null;
12199 this.isCIDFont = false;
12200 }
12201 duplicateFirstGlyph() {
12202 if (this.charStrings.count >= 65535) {
12203 warn("Not enough space in charstrings to duplicate first glyph.");
12204 return;
12205 }
12206 const glyphZero = this.charStrings.get(0);
12207 this.charStrings.add(glyphZero);
12208 if (this.isCIDFont) {
12209 this.fdSelect.fdSelect.push(this.fdSelect.fdSelect[0]);
12210 }
12211 }
12212 hasGlyphId(id) {
12213 if (id < 0 || id >= this.charStrings.count) {
12214 return false;
12215 }
12216 const glyph = this.charStrings.get(id);
12217 return glyph.length > 0;
12218 }
12219}
12220class CFFHeader {
12221 constructor(major, minor, hdrSize, offSize) {
12222 this.major = major;
12223 this.minor = minor;
12224 this.hdrSize = hdrSize;
12225 this.offSize = offSize;
12226 }
12227}
12228class CFFStrings {
12229 constructor() {
12230 this.strings = [];
12231 }
12232 get(index) {
12233 if (index >= 0 && index <= NUM_STANDARD_CFF_STRINGS - 1) {
12234 return CFFStandardStrings[index];
12235 }
12236 if (index - NUM_STANDARD_CFF_STRINGS <= this.strings.length) {
12237 return this.strings[index - NUM_STANDARD_CFF_STRINGS];
12238 }
12239 return CFFStandardStrings[0];
12240 }
12241 getSID(str) {
12242 let index = CFFStandardStrings.indexOf(str);
12243 if (index !== -1) {
12244 return index;
12245 }
12246 index = this.strings.indexOf(str);
12247 if (index !== -1) {
12248 return index + NUM_STANDARD_CFF_STRINGS;
12249 }
12250 return -1;
12251 }
12252 add(value) {
12253 this.strings.push(value);
12254 }
12255 get count() {
12256 return this.strings.length;
12257 }
12258}
12259class CFFIndex {
12260 constructor() {
12261 this.objects = [];
12262 this.length = 0;
12263 }
12264 add(data) {
12265 this.length += data.length;
12266 this.objects.push(data);
12267 }
12268 set(index, data) {
12269 this.length += data.length - this.objects[index].length;
12270 this.objects[index] = data;
12271 }
12272 get(index) {
12273 return this.objects[index];
12274 }
12275 get count() {
12276 return this.objects.length;
12277 }
12278}
12279class CFFDict {
12280 constructor(tables, strings) {
12281 this.keyToNameMap = tables.keyToNameMap;
12282 this.nameToKeyMap = tables.nameToKeyMap;
12283 this.defaults = tables.defaults;
12284 this.types = tables.types;
12285 this.opcodes = tables.opcodes;
12286 this.order = tables.order;
12287 this.strings = strings;
12288 this.values = Object.create(null);
12289 }
12290 setByKey(key, value) {
12291 if (!(key in this.keyToNameMap)) {
12292 return false;
12293 }
12294 if (value.length === 0) {
12295 return true;
12296 }
12297 for (const val of value) {
12298 if (isNaN(val)) {
12299 warn(`Invalid CFFDict value: "${value}" for key "${key}".`);
12300 return true;
12301 }
12302 }
12303 const type = this.types[key];
12304 if (type === "num" || type === "sid" || type === "offset") {
12305 value = value[0];
12306 }
12307 this.values[key] = value;
12308 return true;
12309 }
12310 setByName(name, value) {
12311 if (!(name in this.nameToKeyMap)) {
12312 throw new FormatError(`Invalid dictionary name "${name}"`);
12313 }
12314 this.values[this.nameToKeyMap[name]] = value;
12315 }
12316 hasName(name) {
12317 return this.nameToKeyMap[name] in this.values;
12318 }
12319 getByName(name) {
12320 if (!(name in this.nameToKeyMap)) {
12321 throw new FormatError(`Invalid dictionary name ${name}"`);
12322 }
12323 const key = this.nameToKeyMap[name];
12324 if (!(key in this.values)) {
12325 return this.defaults[key];
12326 }
12327 return this.values[key];
12328 }
12329 removeByName(name) {
12330 delete this.values[this.nameToKeyMap[name]];
12331 }
12332 static createTables(layout) {
12333 const tables = {
12334 keyToNameMap: {},
12335 nameToKeyMap: {},
12336 defaults: {},
12337 types: {},
12338 opcodes: {},
12339 order: []
12340 };
12341 for (const entry of layout) {
12342 const key = Array.isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
12343 tables.keyToNameMap[key] = entry[1];
12344 tables.nameToKeyMap[entry[1]] = key;
12345 tables.types[key] = entry[2];
12346 tables.defaults[key] = entry[3];
12347 tables.opcodes[key] = Array.isArray(entry[0]) ? entry[0] : [entry[0]];
12348 tables.order.push(key);
12349 }
12350 return tables;
12351 }
12352}
12353const 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]];
12354class CFFTopDict extends CFFDict {
12355 static get tables() {
12356 return shadow(this, "tables", this.createTables(CFFTopDictLayout));
12357 }
12358 constructor(strings) {
12359 super(CFFTopDict.tables, strings);
12360 this.privateDict = null;
12361 }
12362}
12363const 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]];
12364class CFFPrivateDict extends CFFDict {
12365 static get tables() {
12366 return shadow(this, "tables", this.createTables(CFFPrivateDictLayout));
12367 }
12368 constructor(strings) {
12369 super(CFFPrivateDict.tables, strings);
12370 this.subrsIndex = null;
12371 }
12372}
12373const CFFCharsetPredefinedTypes = {
12374 ISO_ADOBE: 0,
12375 EXPERT: 1,
12376 EXPERT_SUBSET: 2
12377};
12378class CFFCharset {
12379 constructor(predefined, format, charset, raw) {
12380 this.predefined = predefined;
12381 this.format = format;
12382 this.charset = charset;
12383 this.raw = raw;
12384 }
12385}
12386class CFFEncoding {
12387 constructor(predefined, format, encoding, raw) {
12388 this.predefined = predefined;
12389 this.format = format;
12390 this.encoding = encoding;
12391 this.raw = raw;
12392 }
12393}
12394class CFFFDSelect {
12395 constructor(format, fdSelect) {
12396 this.format = format;
12397 this.fdSelect = fdSelect;
12398 }
12399 getFDIndex(glyphIndex) {
12400 if (glyphIndex < 0 || glyphIndex >= this.fdSelect.length) {
12401 return -1;
12402 }
12403 return this.fdSelect[glyphIndex];
12404 }
12405}
12406class CFFOffsetTracker {
12407 constructor() {
12408 this.offsets = Object.create(null);
12409 }
12410 isTracking(key) {
12411 return key in this.offsets;
12412 }
12413 track(key, location) {
12414 if (key in this.offsets) {
12415 throw new FormatError(`Already tracking location of ${key}`);
12416 }
12417 this.offsets[key] = location;
12418 }
12419 offset(value) {
12420 for (const key in this.offsets) {
12421 this.offsets[key] += value;
12422 }
12423 }
12424 setEntryLocation(key, values, output) {
12425 if (!(key in this.offsets)) {
12426 throw new FormatError(`Not tracking location of ${key}`);
12427 }
12428 const data = output.data;
12429 const dataOffset = this.offsets[key];
12430 const size = 5;
12431 for (let i = 0, ii = values.length; i < ii; ++i) {
12432 const offset0 = i * size + dataOffset;
12433 const offset1 = offset0 + 1;
12434 const offset2 = offset0 + 2;
12435 const offset3 = offset0 + 3;
12436 const offset4 = offset0 + 4;
12437 if (data[offset0] !== 0x1d || data[offset1] !== 0 || data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
12438 throw new FormatError("writing to an offset that is not empty");
12439 }
12440 const value = values[i];
12441 data[offset0] = 0x1d;
12442 data[offset1] = value >> 24 & 0xff;
12443 data[offset2] = value >> 16 & 0xff;
12444 data[offset3] = value >> 8 & 0xff;
12445 data[offset4] = value & 0xff;
12446 }
12447 }
12448}
12449class CFFCompiler {
12450 constructor(cff) {
12451 this.cff = cff;
12452 }
12453 compile() {
12454 const cff = this.cff;
12455 const output = {
12456 data: [],
12457 length: 0,
12458 add(data) {
12459 try {
12460 this.data.push(...data);
12461 } catch {
12462 this.data = this.data.concat(data);
12463 }
12464 this.length = this.data.length;
12465 }
12466 };
12467 const header = this.compileHeader(cff.header);
12468 output.add(header);
12469 const nameIndex = this.compileNameIndex(cff.names);
12470 output.add(nameIndex);
12471 if (cff.isCIDFont) {
12472 if (cff.topDict.hasName("FontMatrix")) {
12473 const base = cff.topDict.getByName("FontMatrix");
12474 cff.topDict.removeByName("FontMatrix");
12475 for (const subDict of cff.fdArray) {
12476 let matrix = base.slice(0);
12477 if (subDict.hasName("FontMatrix")) {
12478 matrix = Util.transform(matrix, subDict.getByName("FontMatrix"));
12479 }
12480 subDict.setByName("FontMatrix", matrix);
12481 }
12482 }
12483 }
12484 const xuid = cff.topDict.getByName("XUID");
12485 if (xuid?.length > 16) {
12486 cff.topDict.removeByName("XUID");
12487 }
12488 cff.topDict.setByName("charset", 0);
12489 let compiled = this.compileTopDicts([cff.topDict], output.length, cff.isCIDFont);
12490 output.add(compiled.output);
12491 const topDictTracker = compiled.trackers[0];
12492 const stringIndex = this.compileStringIndex(cff.strings.strings);
12493 output.add(stringIndex);
12494 const globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
12495 output.add(globalSubrIndex);
12496 if (cff.encoding && cff.topDict.hasName("Encoding")) {
12497 if (cff.encoding.predefined) {
12498 topDictTracker.setEntryLocation("Encoding", [cff.encoding.format], output);
12499 } else {
12500 const encoding = this.compileEncoding(cff.encoding);
12501 topDictTracker.setEntryLocation("Encoding", [output.length], output);
12502 output.add(encoding);
12503 }
12504 }
12505 const charset = this.compileCharset(cff.charset, cff.charStrings.count, cff.strings, cff.isCIDFont);
12506 topDictTracker.setEntryLocation("charset", [output.length], output);
12507 output.add(charset);
12508 const charStrings = this.compileCharStrings(cff.charStrings);
12509 topDictTracker.setEntryLocation("CharStrings", [output.length], output);
12510 output.add(charStrings);
12511 if (cff.isCIDFont) {
12512 topDictTracker.setEntryLocation("FDSelect", [output.length], output);
12513 const fdSelect = this.compileFDSelect(cff.fdSelect);
12514 output.add(fdSelect);
12515 compiled = this.compileTopDicts(cff.fdArray, output.length, true);
12516 topDictTracker.setEntryLocation("FDArray", [output.length], output);
12517 output.add(compiled.output);
12518 const fontDictTrackers = compiled.trackers;
12519 this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
12520 }
12521 this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
12522 output.add([0]);
12523 return output.data;
12524 }
12525 encodeNumber(value) {
12526 if (Number.isInteger(value)) {
12527 return this.encodeInteger(value);
12528 }
12529 return this.encodeFloat(value);
12530 }
12531 static get EncodeFloatRegExp() {
12532 return shadow(this, "EncodeFloatRegExp", /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/);
12533 }
12534 encodeFloat(num) {
12535 let value = num.toString();
12536 const m = CFFCompiler.EncodeFloatRegExp.exec(value);
12537 if (m) {
12538 const epsilon = parseFloat("1e" + ((m[2] ? +m[2] : 0) + m[1].length));
12539 value = (Math.round(num * epsilon) / epsilon).toString();
12540 }
12541 let nibbles = "";
12542 let i, ii;
12543 for (i = 0, ii = value.length; i < ii; ++i) {
12544 const a = value[i];
12545 if (a === "e") {
12546 nibbles += value[++i] === "-" ? "c" : "b";
12547 } else if (a === ".") {
12548 nibbles += "a";
12549 } else if (a === "-") {
12550 nibbles += "e";
12551 } else {
12552 nibbles += a;
12553 }
12554 }
12555 nibbles += nibbles.length & 1 ? "f" : "ff";
12556 const out = [30];
12557 for (i = 0, ii = nibbles.length; i < ii; i += 2) {
12558 out.push(parseInt(nibbles.substring(i, i + 2), 16));
12559 }
12560 return out;
12561 }
12562 encodeInteger(value) {
12563 let code;
12564 if (value >= -107 && value <= 107) {
12565 code = [value + 139];
12566 } else if (value >= 108 && value <= 1131) {
12567 value -= 108;
12568 code = [(value >> 8) + 247, value & 0xff];
12569 } else if (value >= -1131 && value <= -108) {
12570 value = -value - 108;
12571 code = [(value >> 8) + 251, value & 0xff];
12572 } else if (value >= -32768 && value <= 32767) {
12573 code = [0x1c, value >> 8 & 0xff, value & 0xff];
12574 } else {
12575 code = [0x1d, value >> 24 & 0xff, value >> 16 & 0xff, value >> 8 & 0xff, value & 0xff];
12576 }
12577 return code;
12578 }
12579 compileHeader(header) {
12580 return [header.major, header.minor, 4, header.offSize];
12581 }
12582 compileNameIndex(names) {
12583 const nameIndex = new CFFIndex();
12584 for (const name of names) {
12585 const length = Math.min(name.length, 127);
12586 let sanitizedName = new Array(length);
12587 for (let j = 0; j < length; j++) {
12588 let char = name[j];
12589 if (char < "!" || char > "~" || char === "[" || char === "]" || char === "(" || char === ")" || char === "{" || char === "}" || char === "<" || char === ">" || char === "/" || char === "%") {
12590 char = "_";
12591 }
12592 sanitizedName[j] = char;
12593 }
12594 sanitizedName = sanitizedName.join("");
12595 if (sanitizedName === "") {
12596 sanitizedName = "Bad_Font_Name";
12597 }
12598 nameIndex.add(stringToBytes(sanitizedName));
12599 }
12600 return this.compileIndex(nameIndex);
12601 }
12602 compileTopDicts(dicts, length, removeCidKeys) {
12603 const fontDictTrackers = [];
12604 let fdArrayIndex = new CFFIndex();
12605 for (const fontDict of dicts) {
12606 if (removeCidKeys) {
12607 fontDict.removeByName("CIDFontVersion");
12608 fontDict.removeByName("CIDFontRevision");
12609 fontDict.removeByName("CIDFontType");
12610 fontDict.removeByName("CIDCount");
12611 fontDict.removeByName("UIDBase");
12612 }
12613 const fontDictTracker = new CFFOffsetTracker();
12614 const fontDictData = this.compileDict(fontDict, fontDictTracker);
12615 fontDictTrackers.push(fontDictTracker);
12616 fdArrayIndex.add(fontDictData);
12617 fontDictTracker.offset(length);
12618 }
12619 fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
12620 return {
12621 trackers: fontDictTrackers,
12622 output: fdArrayIndex
12623 };
12624 }
12625 compilePrivateDicts(dicts, trackers, output) {
12626 for (let i = 0, ii = dicts.length; i < ii; ++i) {
12627 const fontDict = dicts[i];
12628 const privateDict = fontDict.privateDict;
12629 if (!privateDict || !fontDict.hasName("Private")) {
12630 throw new FormatError("There must be a private dictionary.");
12631 }
12632 const privateDictTracker = new CFFOffsetTracker();
12633 const privateDictData = this.compileDict(privateDict, privateDictTracker);
12634 let outputLength = output.length;
12635 privateDictTracker.offset(outputLength);
12636 if (!privateDictData.length) {
12637 outputLength = 0;
12638 }
12639 trackers[i].setEntryLocation("Private", [privateDictData.length, outputLength], output);
12640 output.add(privateDictData);
12641 if (privateDict.subrsIndex && privateDict.hasName("Subrs")) {
12642 const subrs = this.compileIndex(privateDict.subrsIndex);
12643 privateDictTracker.setEntryLocation("Subrs", [privateDictData.length], output);
12644 output.add(subrs);
12645 }
12646 }
12647 }
12648 compileDict(dict, offsetTracker) {
12649 const out = [];
12650 for (const key of dict.order) {
12651 if (!(key in dict.values)) {
12652 continue;
12653 }
12654 let values = dict.values[key];
12655 let types = dict.types[key];
12656 if (!Array.isArray(types)) {
12657 types = [types];
12658 }
12659 if (!Array.isArray(values)) {
12660 values = [values];
12661 }
12662 if (values.length === 0) {
12663 continue;
12664 }
12665 for (let j = 0, jj = types.length; j < jj; ++j) {
12666 const type = types[j];
12667 const value = values[j];
12668 switch (type) {
12669 case "num":
12670 case "sid":
12671 out.push(...this.encodeNumber(value));
12672 break;
12673 case "offset":
12674 const name = dict.keyToNameMap[key];
12675 if (!offsetTracker.isTracking(name)) {
12676 offsetTracker.track(name, out.length);
12677 }
12678 out.push(0x1d, 0, 0, 0, 0);
12679 break;
12680 case "array":
12681 case "delta":
12682 out.push(...this.encodeNumber(value));
12683 for (let k = 1, kk = values.length; k < kk; ++k) {
12684 out.push(...this.encodeNumber(values[k]));
12685 }
12686 break;
12687 default:
12688 throw new FormatError(`Unknown data type of ${type}`);
12689 }
12690 }
12691 out.push(...dict.opcodes[key]);
12692 }
12693 return out;
12694 }
12695 compileStringIndex(strings) {
12696 const stringIndex = new CFFIndex();
12697 for (const string of strings) {
12698 stringIndex.add(stringToBytes(string));
12699 }
12700 return this.compileIndex(stringIndex);
12701 }
12702 compileCharStrings(charStrings) {
12703 const charStringsIndex = new CFFIndex();
12704 for (let i = 0; i < charStrings.count; i++) {
12705 const glyph = charStrings.get(i);
12706 if (glyph.length === 0) {
12707 charStringsIndex.add(new Uint8Array([0x8b, 0x0e]));
12708 continue;
12709 }
12710 charStringsIndex.add(glyph);
12711 }
12712 return this.compileIndex(charStringsIndex);
12713 }
12714 compileCharset(charset, numGlyphs, strings, isCIDFont) {
12715 let out;
12716 const numGlyphsLessNotDef = numGlyphs - 1;
12717 if (isCIDFont) {
12718 out = new Uint8Array([2, 0, 0, numGlyphsLessNotDef >> 8 & 0xff, numGlyphsLessNotDef & 0xff]);
12719 } else {
12720 const length = 1 + numGlyphsLessNotDef * 2;
12721 out = new Uint8Array(length);
12722 out[0] = 0;
12723 let charsetIndex = 0;
12724 const numCharsets = charset.charset.length;
12725 let warned = false;
12726 for (let i = 1; i < out.length; i += 2) {
12727 let sid = 0;
12728 if (charsetIndex < numCharsets) {
12729 const name = charset.charset[charsetIndex++];
12730 sid = strings.getSID(name);
12731 if (sid === -1) {
12732 sid = 0;
12733 if (!warned) {
12734 warned = true;
12735 warn(`Couldn't find ${name} in CFF strings`);
12736 }
12737 }
12738 }
12739 out[i] = sid >> 8 & 0xff;
12740 out[i + 1] = sid & 0xff;
12741 }
12742 }
12743 return this.compileTypedArray(out);
12744 }
12745 compileEncoding(encoding) {
12746 return this.compileTypedArray(encoding.raw);
12747 }
12748 compileFDSelect(fdSelect) {
12749 const format = fdSelect.format;
12750 let out, i;
12751 switch (format) {
12752 case 0:
12753 out = new Uint8Array(1 + fdSelect.fdSelect.length);
12754 out[0] = format;
12755 for (i = 0; i < fdSelect.fdSelect.length; i++) {
12756 out[i + 1] = fdSelect.fdSelect[i];
12757 }
12758 break;
12759 case 3:
12760 const start = 0;
12761 let lastFD = fdSelect.fdSelect[0];
12762 const ranges = [format, 0, 0, start >> 8 & 0xff, start & 0xff, lastFD];
12763 for (i = 1; i < fdSelect.fdSelect.length; i++) {
12764 const currentFD = fdSelect.fdSelect[i];
12765 if (currentFD !== lastFD) {
12766 ranges.push(i >> 8 & 0xff, i & 0xff, currentFD);
12767 lastFD = currentFD;
12768 }
12769 }
12770 const numRanges = (ranges.length - 3) / 3;
12771 ranges[1] = numRanges >> 8 & 0xff;
12772 ranges[2] = numRanges & 0xff;
12773 ranges.push(i >> 8 & 0xff, i & 0xff);
12774 out = new Uint8Array(ranges);
12775 break;
12776 }
12777 return this.compileTypedArray(out);
12778 }
12779 compileTypedArray(data) {
12780 return Array.from(data);
12781 }
12782 compileIndex(index, trackers = []) {
12783 const objects = index.objects;
12784 const count = objects.length;
12785 if (count === 0) {
12786 return [0, 0];
12787 }
12788 const data = [count >> 8 & 0xff, count & 0xff];
12789 let lastOffset = 1,
12790 i;
12791 for (i = 0; i < count; ++i) {
12792 lastOffset += objects[i].length;
12793 }
12794 let offsetSize;
12795 if (lastOffset < 0x100) {
12796 offsetSize = 1;
12797 } else if (lastOffset < 0x10000) {
12798 offsetSize = 2;
12799 } else if (lastOffset < 0x1000000) {
12800 offsetSize = 3;
12801 } else {
12802 offsetSize = 4;
12803 }
12804 data.push(offsetSize);
12805 let relativeOffset = 1;
12806 for (i = 0; i < count + 1; i++) {
12807 if (offsetSize === 1) {
12808 data.push(relativeOffset & 0xff);
12809 } else if (offsetSize === 2) {
12810 data.push(relativeOffset >> 8 & 0xff, relativeOffset & 0xff);
12811 } else if (offsetSize === 3) {
12812 data.push(relativeOffset >> 16 & 0xff, relativeOffset >> 8 & 0xff, relativeOffset & 0xff);
12813 } else {
12814 data.push(relativeOffset >>> 24 & 0xff, relativeOffset >> 16 & 0xff, relativeOffset >> 8 & 0xff, relativeOffset & 0xff);
12815 }
12816 if (objects[i]) {
12817 relativeOffset += objects[i].length;
12818 }
12819 }
12820 for (i = 0; i < count; i++) {
12821 if (trackers[i]) {
12822 trackers[i].offset(data.length);
12823 }
12824 data.push(...objects[i]);
12825 }
12826 return data;
12827 }
12828}
12829
12830;// CONCATENATED MODULE: ./src/core/glyphlist.js
12831
12832const getGlyphsUnicode = getLookupTableFactory(function (t) {
12833 t.A = 0x0041;
12834 t.AE = 0x00c6;
12835 t.AEacute = 0x01fc;
12836 t.AEmacron = 0x01e2;
12837 t.AEsmall = 0xf7e6;
12838 t.Aacute = 0x00c1;
12839 t.Aacutesmall = 0xf7e1;
12840 t.Abreve = 0x0102;
12841 t.Abreveacute = 0x1eae;
12842 t.Abrevecyrillic = 0x04d0;
12843 t.Abrevedotbelow = 0x1eb6;
12844 t.Abrevegrave = 0x1eb0;
12845 t.Abrevehookabove = 0x1eb2;
12846 t.Abrevetilde = 0x1eb4;
12847 t.Acaron = 0x01cd;
12848 t.Acircle = 0x24b6;
12849 t.Acircumflex = 0x00c2;
12850 t.Acircumflexacute = 0x1ea4;
12851 t.Acircumflexdotbelow = 0x1eac;
12852 t.Acircumflexgrave = 0x1ea6;
12853 t.Acircumflexhookabove = 0x1ea8;
12854 t.Acircumflexsmall = 0xf7e2;
12855 t.Acircumflextilde = 0x1eaa;
12856 t.Acute = 0xf6c9;
12857 t.Acutesmall = 0xf7b4;
12858 t.Acyrillic = 0x0410;
12859 t.Adblgrave = 0x0200;
12860 t.Adieresis = 0x00c4;
12861 t.Adieresiscyrillic = 0x04d2;
12862 t.Adieresismacron = 0x01de;
12863 t.Adieresissmall = 0xf7e4;
12864 t.Adotbelow = 0x1ea0;
12865 t.Adotmacron = 0x01e0;
12866 t.Agrave = 0x00c0;
12867 t.Agravesmall = 0xf7e0;
12868 t.Ahookabove = 0x1ea2;
12869 t.Aiecyrillic = 0x04d4;
12870 t.Ainvertedbreve = 0x0202;
12871 t.Alpha = 0x0391;
12872 t.Alphatonos = 0x0386;
12873 t.Amacron = 0x0100;
12874 t.Amonospace = 0xff21;
12875 t.Aogonek = 0x0104;
12876 t.Aring = 0x00c5;
12877 t.Aringacute = 0x01fa;
12878 t.Aringbelow = 0x1e00;
12879 t.Aringsmall = 0xf7e5;
12880 t.Asmall = 0xf761;
12881 t.Atilde = 0x00c3;
12882 t.Atildesmall = 0xf7e3;
12883 t.Aybarmenian = 0x0531;
12884 t.B = 0x0042;
12885 t.Bcircle = 0x24b7;
12886 t.Bdotaccent = 0x1e02;
12887 t.Bdotbelow = 0x1e04;
12888 t.Becyrillic = 0x0411;
12889 t.Benarmenian = 0x0532;
12890 t.Beta = 0x0392;
12891 t.Bhook = 0x0181;
12892 t.Blinebelow = 0x1e06;
12893 t.Bmonospace = 0xff22;
12894 t.Brevesmall = 0xf6f4;
12895 t.Bsmall = 0xf762;
12896 t.Btopbar = 0x0182;
12897 t.C = 0x0043;
12898 t.Caarmenian = 0x053e;
12899 t.Cacute = 0x0106;
12900 t.Caron = 0xf6ca;
12901 t.Caronsmall = 0xf6f5;
12902 t.Ccaron = 0x010c;
12903 t.Ccedilla = 0x00c7;
12904 t.Ccedillaacute = 0x1e08;
12905 t.Ccedillasmall = 0xf7e7;
12906 t.Ccircle = 0x24b8;
12907 t.Ccircumflex = 0x0108;
12908 t.Cdot = 0x010a;
12909 t.Cdotaccent = 0x010a;
12910 t.Cedillasmall = 0xf7b8;
12911 t.Chaarmenian = 0x0549;
12912 t.Cheabkhasiancyrillic = 0x04bc;
12913 t.Checyrillic = 0x0427;
12914 t.Chedescenderabkhasiancyrillic = 0x04be;
12915 t.Chedescendercyrillic = 0x04b6;
12916 t.Chedieresiscyrillic = 0x04f4;
12917 t.Cheharmenian = 0x0543;
12918 t.Chekhakassiancyrillic = 0x04cb;
12919 t.Cheverticalstrokecyrillic = 0x04b8;
12920 t.Chi = 0x03a7;
12921 t.Chook = 0x0187;
12922 t.Circumflexsmall = 0xf6f6;
12923 t.Cmonospace = 0xff23;
12924 t.Coarmenian = 0x0551;
12925 t.Csmall = 0xf763;
12926 t.D = 0x0044;
12927 t.DZ = 0x01f1;
12928 t.DZcaron = 0x01c4;
12929 t.Daarmenian = 0x0534;
12930 t.Dafrican = 0x0189;
12931 t.Dcaron = 0x010e;
12932 t.Dcedilla = 0x1e10;
12933 t.Dcircle = 0x24b9;
12934 t.Dcircumflexbelow = 0x1e12;
12935 t.Dcroat = 0x0110;
12936 t.Ddotaccent = 0x1e0a;
12937 t.Ddotbelow = 0x1e0c;
12938 t.Decyrillic = 0x0414;
12939 t.Deicoptic = 0x03ee;
12940 t.Delta = 0x2206;
12941 t.Deltagreek = 0x0394;
12942 t.Dhook = 0x018a;
12943 t.Dieresis = 0xf6cb;
12944 t.DieresisAcute = 0xf6cc;
12945 t.DieresisGrave = 0xf6cd;
12946 t.Dieresissmall = 0xf7a8;
12947 t.Digammagreek = 0x03dc;
12948 t.Djecyrillic = 0x0402;
12949 t.Dlinebelow = 0x1e0e;
12950 t.Dmonospace = 0xff24;
12951 t.Dotaccentsmall = 0xf6f7;
12952 t.Dslash = 0x0110;
12953 t.Dsmall = 0xf764;
12954 t.Dtopbar = 0x018b;
12955 t.Dz = 0x01f2;
12956 t.Dzcaron = 0x01c5;
12957 t.Dzeabkhasiancyrillic = 0x04e0;
12958 t.Dzecyrillic = 0x0405;
12959 t.Dzhecyrillic = 0x040f;
12960 t.E = 0x0045;
12961 t.Eacute = 0x00c9;
12962 t.Eacutesmall = 0xf7e9;
12963 t.Ebreve = 0x0114;
12964 t.Ecaron = 0x011a;
12965 t.Ecedillabreve = 0x1e1c;
12966 t.Echarmenian = 0x0535;
12967 t.Ecircle = 0x24ba;
12968 t.Ecircumflex = 0x00ca;
12969 t.Ecircumflexacute = 0x1ebe;
12970 t.Ecircumflexbelow = 0x1e18;
12971 t.Ecircumflexdotbelow = 0x1ec6;
12972 t.Ecircumflexgrave = 0x1ec0;
12973 t.Ecircumflexhookabove = 0x1ec2;
12974 t.Ecircumflexsmall = 0xf7ea;
12975 t.Ecircumflextilde = 0x1ec4;
12976 t.Ecyrillic = 0x0404;
12977 t.Edblgrave = 0x0204;
12978 t.Edieresis = 0x00cb;
12979 t.Edieresissmall = 0xf7eb;
12980 t.Edot = 0x0116;
12981 t.Edotaccent = 0x0116;
12982 t.Edotbelow = 0x1eb8;
12983 t.Efcyrillic = 0x0424;
12984 t.Egrave = 0x00c8;
12985 t.Egravesmall = 0xf7e8;
12986 t.Eharmenian = 0x0537;
12987 t.Ehookabove = 0x1eba;
12988 t.Eightroman = 0x2167;
12989 t.Einvertedbreve = 0x0206;
12990 t.Eiotifiedcyrillic = 0x0464;
12991 t.Elcyrillic = 0x041b;
12992 t.Elevenroman = 0x216a;
12993 t.Emacron = 0x0112;
12994 t.Emacronacute = 0x1e16;
12995 t.Emacrongrave = 0x1e14;
12996 t.Emcyrillic = 0x041c;
12997 t.Emonospace = 0xff25;
12998 t.Encyrillic = 0x041d;
12999 t.Endescendercyrillic = 0x04a2;
13000 t.Eng = 0x014a;
13001 t.Enghecyrillic = 0x04a4;
13002 t.Enhookcyrillic = 0x04c7;
13003 t.Eogonek = 0x0118;
13004 t.Eopen = 0x0190;
13005 t.Epsilon = 0x0395;
13006 t.Epsilontonos = 0x0388;
13007 t.Ercyrillic = 0x0420;
13008 t.Ereversed = 0x018e;
13009 t.Ereversedcyrillic = 0x042d;
13010 t.Escyrillic = 0x0421;
13011 t.Esdescendercyrillic = 0x04aa;
13012 t.Esh = 0x01a9;
13013 t.Esmall = 0xf765;
13014 t.Eta = 0x0397;
13015 t.Etarmenian = 0x0538;
13016 t.Etatonos = 0x0389;
13017 t.Eth = 0x00d0;
13018 t.Ethsmall = 0xf7f0;
13019 t.Etilde = 0x1ebc;
13020 t.Etildebelow = 0x1e1a;
13021 t.Euro = 0x20ac;
13022 t.Ezh = 0x01b7;
13023 t.Ezhcaron = 0x01ee;
13024 t.Ezhreversed = 0x01b8;
13025 t.F = 0x0046;
13026 t.Fcircle = 0x24bb;
13027 t.Fdotaccent = 0x1e1e;
13028 t.Feharmenian = 0x0556;
13029 t.Feicoptic = 0x03e4;
13030 t.Fhook = 0x0191;
13031 t.Fitacyrillic = 0x0472;
13032 t.Fiveroman = 0x2164;
13033 t.Fmonospace = 0xff26;
13034 t.Fourroman = 0x2163;
13035 t.Fsmall = 0xf766;
13036 t.G = 0x0047;
13037 t.GBsquare = 0x3387;
13038 t.Gacute = 0x01f4;
13039 t.Gamma = 0x0393;
13040 t.Gammaafrican = 0x0194;
13041 t.Gangiacoptic = 0x03ea;
13042 t.Gbreve = 0x011e;
13043 t.Gcaron = 0x01e6;
13044 t.Gcedilla = 0x0122;
13045 t.Gcircle = 0x24bc;
13046 t.Gcircumflex = 0x011c;
13047 t.Gcommaaccent = 0x0122;
13048 t.Gdot = 0x0120;
13049 t.Gdotaccent = 0x0120;
13050 t.Gecyrillic = 0x0413;
13051 t.Ghadarmenian = 0x0542;
13052 t.Ghemiddlehookcyrillic = 0x0494;
13053 t.Ghestrokecyrillic = 0x0492;
13054 t.Gheupturncyrillic = 0x0490;
13055 t.Ghook = 0x0193;
13056 t.Gimarmenian = 0x0533;
13057 t.Gjecyrillic = 0x0403;
13058 t.Gmacron = 0x1e20;
13059 t.Gmonospace = 0xff27;
13060 t.Grave = 0xf6ce;
13061 t.Gravesmall = 0xf760;
13062 t.Gsmall = 0xf767;
13063 t.Gsmallhook = 0x029b;
13064 t.Gstroke = 0x01e4;
13065 t.H = 0x0048;
13066 t.H18533 = 0x25cf;
13067 t.H18543 = 0x25aa;
13068 t.H18551 = 0x25ab;
13069 t.H22073 = 0x25a1;
13070 t.HPsquare = 0x33cb;
13071 t.Haabkhasiancyrillic = 0x04a8;
13072 t.Hadescendercyrillic = 0x04b2;
13073 t.Hardsigncyrillic = 0x042a;
13074 t.Hbar = 0x0126;
13075 t.Hbrevebelow = 0x1e2a;
13076 t.Hcedilla = 0x1e28;
13077 t.Hcircle = 0x24bd;
13078 t.Hcircumflex = 0x0124;
13079 t.Hdieresis = 0x1e26;
13080 t.Hdotaccent = 0x1e22;
13081 t.Hdotbelow = 0x1e24;
13082 t.Hmonospace = 0xff28;
13083 t.Hoarmenian = 0x0540;
13084 t.Horicoptic = 0x03e8;
13085 t.Hsmall = 0xf768;
13086 t.Hungarumlaut = 0xf6cf;
13087 t.Hungarumlautsmall = 0xf6f8;
13088 t.Hzsquare = 0x3390;
13089 t.I = 0x0049;
13090 t.IAcyrillic = 0x042f;
13091 t.IJ = 0x0132;
13092 t.IUcyrillic = 0x042e;
13093 t.Iacute = 0x00cd;
13094 t.Iacutesmall = 0xf7ed;
13095 t.Ibreve = 0x012c;
13096 t.Icaron = 0x01cf;
13097 t.Icircle = 0x24be;
13098 t.Icircumflex = 0x00ce;
13099 t.Icircumflexsmall = 0xf7ee;
13100 t.Icyrillic = 0x0406;
13101 t.Idblgrave = 0x0208;
13102 t.Idieresis = 0x00cf;
13103 t.Idieresisacute = 0x1e2e;
13104 t.Idieresiscyrillic = 0x04e4;
13105 t.Idieresissmall = 0xf7ef;
13106 t.Idot = 0x0130;
13107 t.Idotaccent = 0x0130;
13108 t.Idotbelow = 0x1eca;
13109 t.Iebrevecyrillic = 0x04d6;
13110 t.Iecyrillic = 0x0415;
13111 t.Ifraktur = 0x2111;
13112 t.Igrave = 0x00cc;
13113 t.Igravesmall = 0xf7ec;
13114 t.Ihookabove = 0x1ec8;
13115 t.Iicyrillic = 0x0418;
13116 t.Iinvertedbreve = 0x020a;
13117 t.Iishortcyrillic = 0x0419;
13118 t.Imacron = 0x012a;
13119 t.Imacroncyrillic = 0x04e2;
13120 t.Imonospace = 0xff29;
13121 t.Iniarmenian = 0x053b;
13122 t.Iocyrillic = 0x0401;
13123 t.Iogonek = 0x012e;
13124 t.Iota = 0x0399;
13125 t.Iotaafrican = 0x0196;
13126 t.Iotadieresis = 0x03aa;
13127 t.Iotatonos = 0x038a;
13128 t.Ismall = 0xf769;
13129 t.Istroke = 0x0197;
13130 t.Itilde = 0x0128;
13131 t.Itildebelow = 0x1e2c;
13132 t.Izhitsacyrillic = 0x0474;
13133 t.Izhitsadblgravecyrillic = 0x0476;
13134 t.J = 0x004a;
13135 t.Jaarmenian = 0x0541;
13136 t.Jcircle = 0x24bf;
13137 t.Jcircumflex = 0x0134;
13138 t.Jecyrillic = 0x0408;
13139 t.Jheharmenian = 0x054b;
13140 t.Jmonospace = 0xff2a;
13141 t.Jsmall = 0xf76a;
13142 t.K = 0x004b;
13143 t.KBsquare = 0x3385;
13144 t.KKsquare = 0x33cd;
13145 t.Kabashkircyrillic = 0x04a0;
13146 t.Kacute = 0x1e30;
13147 t.Kacyrillic = 0x041a;
13148 t.Kadescendercyrillic = 0x049a;
13149 t.Kahookcyrillic = 0x04c3;
13150 t.Kappa = 0x039a;
13151 t.Kastrokecyrillic = 0x049e;
13152 t.Kaverticalstrokecyrillic = 0x049c;
13153 t.Kcaron = 0x01e8;
13154 t.Kcedilla = 0x0136;
13155 t.Kcircle = 0x24c0;
13156 t.Kcommaaccent = 0x0136;
13157 t.Kdotbelow = 0x1e32;
13158 t.Keharmenian = 0x0554;
13159 t.Kenarmenian = 0x053f;
13160 t.Khacyrillic = 0x0425;
13161 t.Kheicoptic = 0x03e6;
13162 t.Khook = 0x0198;
13163 t.Kjecyrillic = 0x040c;
13164 t.Klinebelow = 0x1e34;
13165 t.Kmonospace = 0xff2b;
13166 t.Koppacyrillic = 0x0480;
13167 t.Koppagreek = 0x03de;
13168 t.Ksicyrillic = 0x046e;
13169 t.Ksmall = 0xf76b;
13170 t.L = 0x004c;
13171 t.LJ = 0x01c7;
13172 t.LL = 0xf6bf;
13173 t.Lacute = 0x0139;
13174 t.Lambda = 0x039b;
13175 t.Lcaron = 0x013d;
13176 t.Lcedilla = 0x013b;
13177 t.Lcircle = 0x24c1;
13178 t.Lcircumflexbelow = 0x1e3c;
13179 t.Lcommaaccent = 0x013b;
13180 t.Ldot = 0x013f;
13181 t.Ldotaccent = 0x013f;
13182 t.Ldotbelow = 0x1e36;
13183 t.Ldotbelowmacron = 0x1e38;
13184 t.Liwnarmenian = 0x053c;
13185 t.Lj = 0x01c8;
13186 t.Ljecyrillic = 0x0409;
13187 t.Llinebelow = 0x1e3a;
13188 t.Lmonospace = 0xff2c;
13189 t.Lslash = 0x0141;
13190 t.Lslashsmall = 0xf6f9;
13191 t.Lsmall = 0xf76c;
13192 t.M = 0x004d;
13193 t.MBsquare = 0x3386;
13194 t.Macron = 0xf6d0;
13195 t.Macronsmall = 0xf7af;
13196 t.Macute = 0x1e3e;
13197 t.Mcircle = 0x24c2;
13198 t.Mdotaccent = 0x1e40;
13199 t.Mdotbelow = 0x1e42;
13200 t.Menarmenian = 0x0544;
13201 t.Mmonospace = 0xff2d;
13202 t.Msmall = 0xf76d;
13203 t.Mturned = 0x019c;
13204 t.Mu = 0x039c;
13205 t.N = 0x004e;
13206 t.NJ = 0x01ca;
13207 t.Nacute = 0x0143;
13208 t.Ncaron = 0x0147;
13209 t.Ncedilla = 0x0145;
13210 t.Ncircle = 0x24c3;
13211 t.Ncircumflexbelow = 0x1e4a;
13212 t.Ncommaaccent = 0x0145;
13213 t.Ndotaccent = 0x1e44;
13214 t.Ndotbelow = 0x1e46;
13215 t.Nhookleft = 0x019d;
13216 t.Nineroman = 0x2168;
13217 t.Nj = 0x01cb;
13218 t.Njecyrillic = 0x040a;
13219 t.Nlinebelow = 0x1e48;
13220 t.Nmonospace = 0xff2e;
13221 t.Nowarmenian = 0x0546;
13222 t.Nsmall = 0xf76e;
13223 t.Ntilde = 0x00d1;
13224 t.Ntildesmall = 0xf7f1;
13225 t.Nu = 0x039d;
13226 t.O = 0x004f;
13227 t.OE = 0x0152;
13228 t.OEsmall = 0xf6fa;
13229 t.Oacute = 0x00d3;
13230 t.Oacutesmall = 0xf7f3;
13231 t.Obarredcyrillic = 0x04e8;
13232 t.Obarreddieresiscyrillic = 0x04ea;
13233 t.Obreve = 0x014e;
13234 t.Ocaron = 0x01d1;
13235 t.Ocenteredtilde = 0x019f;
13236 t.Ocircle = 0x24c4;
13237 t.Ocircumflex = 0x00d4;
13238 t.Ocircumflexacute = 0x1ed0;
13239 t.Ocircumflexdotbelow = 0x1ed8;
13240 t.Ocircumflexgrave = 0x1ed2;
13241 t.Ocircumflexhookabove = 0x1ed4;
13242 t.Ocircumflexsmall = 0xf7f4;
13243 t.Ocircumflextilde = 0x1ed6;
13244 t.Ocyrillic = 0x041e;
13245 t.Odblacute = 0x0150;
13246 t.Odblgrave = 0x020c;
13247 t.Odieresis = 0x00d6;
13248 t.Odieresiscyrillic = 0x04e6;
13249 t.Odieresissmall = 0xf7f6;
13250 t.Odotbelow = 0x1ecc;
13251 t.Ogoneksmall = 0xf6fb;
13252 t.Ograve = 0x00d2;
13253 t.Ogravesmall = 0xf7f2;
13254 t.Oharmenian = 0x0555;
13255 t.Ohm = 0x2126;
13256 t.Ohookabove = 0x1ece;
13257 t.Ohorn = 0x01a0;
13258 t.Ohornacute = 0x1eda;
13259 t.Ohorndotbelow = 0x1ee2;
13260 t.Ohorngrave = 0x1edc;
13261 t.Ohornhookabove = 0x1ede;
13262 t.Ohorntilde = 0x1ee0;
13263 t.Ohungarumlaut = 0x0150;
13264 t.Oi = 0x01a2;
13265 t.Oinvertedbreve = 0x020e;
13266 t.Omacron = 0x014c;
13267 t.Omacronacute = 0x1e52;
13268 t.Omacrongrave = 0x1e50;
13269 t.Omega = 0x2126;
13270 t.Omegacyrillic = 0x0460;
13271 t.Omegagreek = 0x03a9;
13272 t.Omegaroundcyrillic = 0x047a;
13273 t.Omegatitlocyrillic = 0x047c;
13274 t.Omegatonos = 0x038f;
13275 t.Omicron = 0x039f;
13276 t.Omicrontonos = 0x038c;
13277 t.Omonospace = 0xff2f;
13278 t.Oneroman = 0x2160;
13279 t.Oogonek = 0x01ea;
13280 t.Oogonekmacron = 0x01ec;
13281 t.Oopen = 0x0186;
13282 t.Oslash = 0x00d8;
13283 t.Oslashacute = 0x01fe;
13284 t.Oslashsmall = 0xf7f8;
13285 t.Osmall = 0xf76f;
13286 t.Ostrokeacute = 0x01fe;
13287 t.Otcyrillic = 0x047e;
13288 t.Otilde = 0x00d5;
13289 t.Otildeacute = 0x1e4c;
13290 t.Otildedieresis = 0x1e4e;
13291 t.Otildesmall = 0xf7f5;
13292 t.P = 0x0050;
13293 t.Pacute = 0x1e54;
13294 t.Pcircle = 0x24c5;
13295 t.Pdotaccent = 0x1e56;
13296 t.Pecyrillic = 0x041f;
13297 t.Peharmenian = 0x054a;
13298 t.Pemiddlehookcyrillic = 0x04a6;
13299 t.Phi = 0x03a6;
13300 t.Phook = 0x01a4;
13301 t.Pi = 0x03a0;
13302 t.Piwrarmenian = 0x0553;
13303 t.Pmonospace = 0xff30;
13304 t.Psi = 0x03a8;
13305 t.Psicyrillic = 0x0470;
13306 t.Psmall = 0xf770;
13307 t.Q = 0x0051;
13308 t.Qcircle = 0x24c6;
13309 t.Qmonospace = 0xff31;
13310 t.Qsmall = 0xf771;
13311 t.R = 0x0052;
13312 t.Raarmenian = 0x054c;
13313 t.Racute = 0x0154;
13314 t.Rcaron = 0x0158;
13315 t.Rcedilla = 0x0156;
13316 t.Rcircle = 0x24c7;
13317 t.Rcommaaccent = 0x0156;
13318 t.Rdblgrave = 0x0210;
13319 t.Rdotaccent = 0x1e58;
13320 t.Rdotbelow = 0x1e5a;
13321 t.Rdotbelowmacron = 0x1e5c;
13322 t.Reharmenian = 0x0550;
13323 t.Rfraktur = 0x211c;
13324 t.Rho = 0x03a1;
13325 t.Ringsmall = 0xf6fc;
13326 t.Rinvertedbreve = 0x0212;
13327 t.Rlinebelow = 0x1e5e;
13328 t.Rmonospace = 0xff32;
13329 t.Rsmall = 0xf772;
13330 t.Rsmallinverted = 0x0281;
13331 t.Rsmallinvertedsuperior = 0x02b6;
13332 t.S = 0x0053;
13333 t.SF010000 = 0x250c;
13334 t.SF020000 = 0x2514;
13335 t.SF030000 = 0x2510;
13336 t.SF040000 = 0x2518;
13337 t.SF050000 = 0x253c;
13338 t.SF060000 = 0x252c;
13339 t.SF070000 = 0x2534;
13340 t.SF080000 = 0x251c;
13341 t.SF090000 = 0x2524;
13342 t.SF100000 = 0x2500;
13343 t.SF110000 = 0x2502;
13344 t.SF190000 = 0x2561;
13345 t.SF200000 = 0x2562;
13346 t.SF210000 = 0x2556;
13347 t.SF220000 = 0x2555;
13348 t.SF230000 = 0x2563;
13349 t.SF240000 = 0x2551;
13350 t.SF250000 = 0x2557;
13351 t.SF260000 = 0x255d;
13352 t.SF270000 = 0x255c;
13353 t.SF280000 = 0x255b;
13354 t.SF360000 = 0x255e;
13355 t.SF370000 = 0x255f;
13356 t.SF380000 = 0x255a;
13357 t.SF390000 = 0x2554;
13358 t.SF400000 = 0x2569;
13359 t.SF410000 = 0x2566;
13360 t.SF420000 = 0x2560;
13361 t.SF430000 = 0x2550;
13362 t.SF440000 = 0x256c;
13363 t.SF450000 = 0x2567;
13364 t.SF460000 = 0x2568;
13365 t.SF470000 = 0x2564;
13366 t.SF480000 = 0x2565;
13367 t.SF490000 = 0x2559;
13368 t.SF500000 = 0x2558;
13369 t.SF510000 = 0x2552;
13370 t.SF520000 = 0x2553;
13371 t.SF530000 = 0x256b;
13372 t.SF540000 = 0x256a;
13373 t.Sacute = 0x015a;
13374 t.Sacutedotaccent = 0x1e64;
13375 t.Sampigreek = 0x03e0;
13376 t.Scaron = 0x0160;
13377 t.Scarondotaccent = 0x1e66;
13378 t.Scaronsmall = 0xf6fd;
13379 t.Scedilla = 0x015e;
13380 t.Schwa = 0x018f;
13381 t.Schwacyrillic = 0x04d8;
13382 t.Schwadieresiscyrillic = 0x04da;
13383 t.Scircle = 0x24c8;
13384 t.Scircumflex = 0x015c;
13385 t.Scommaaccent = 0x0218;
13386 t.Sdotaccent = 0x1e60;
13387 t.Sdotbelow = 0x1e62;
13388 t.Sdotbelowdotaccent = 0x1e68;
13389 t.Seharmenian = 0x054d;
13390 t.Sevenroman = 0x2166;
13391 t.Shaarmenian = 0x0547;
13392 t.Shacyrillic = 0x0428;
13393 t.Shchacyrillic = 0x0429;
13394 t.Sheicoptic = 0x03e2;
13395 t.Shhacyrillic = 0x04ba;
13396 t.Shimacoptic = 0x03ec;
13397 t.Sigma = 0x03a3;
13398 t.Sixroman = 0x2165;
13399 t.Smonospace = 0xff33;
13400 t.Softsigncyrillic = 0x042c;
13401 t.Ssmall = 0xf773;
13402 t.Stigmagreek = 0x03da;
13403 t.T = 0x0054;
13404 t.Tau = 0x03a4;
13405 t.Tbar = 0x0166;
13406 t.Tcaron = 0x0164;
13407 t.Tcedilla = 0x0162;
13408 t.Tcircle = 0x24c9;
13409 t.Tcircumflexbelow = 0x1e70;
13410 t.Tcommaaccent = 0x0162;
13411 t.Tdotaccent = 0x1e6a;
13412 t.Tdotbelow = 0x1e6c;
13413 t.Tecyrillic = 0x0422;
13414 t.Tedescendercyrillic = 0x04ac;
13415 t.Tenroman = 0x2169;
13416 t.Tetsecyrillic = 0x04b4;
13417 t.Theta = 0x0398;
13418 t.Thook = 0x01ac;
13419 t.Thorn = 0x00de;
13420 t.Thornsmall = 0xf7fe;
13421 t.Threeroman = 0x2162;
13422 t.Tildesmall = 0xf6fe;
13423 t.Tiwnarmenian = 0x054f;
13424 t.Tlinebelow = 0x1e6e;
13425 t.Tmonospace = 0xff34;
13426 t.Toarmenian = 0x0539;
13427 t.Tonefive = 0x01bc;
13428 t.Tonesix = 0x0184;
13429 t.Tonetwo = 0x01a7;
13430 t.Tretroflexhook = 0x01ae;
13431 t.Tsecyrillic = 0x0426;
13432 t.Tshecyrillic = 0x040b;
13433 t.Tsmall = 0xf774;
13434 t.Twelveroman = 0x216b;
13435 t.Tworoman = 0x2161;
13436 t.U = 0x0055;
13437 t.Uacute = 0x00da;
13438 t.Uacutesmall = 0xf7fa;
13439 t.Ubreve = 0x016c;
13440 t.Ucaron = 0x01d3;
13441 t.Ucircle = 0x24ca;
13442 t.Ucircumflex = 0x00db;
13443 t.Ucircumflexbelow = 0x1e76;
13444 t.Ucircumflexsmall = 0xf7fb;
13445 t.Ucyrillic = 0x0423;
13446 t.Udblacute = 0x0170;
13447 t.Udblgrave = 0x0214;
13448 t.Udieresis = 0x00dc;
13449 t.Udieresisacute = 0x01d7;
13450 t.Udieresisbelow = 0x1e72;
13451 t.Udieresiscaron = 0x01d9;
13452 t.Udieresiscyrillic = 0x04f0;
13453 t.Udieresisgrave = 0x01db;
13454 t.Udieresismacron = 0x01d5;
13455 t.Udieresissmall = 0xf7fc;
13456 t.Udotbelow = 0x1ee4;
13457 t.Ugrave = 0x00d9;
13458 t.Ugravesmall = 0xf7f9;
13459 t.Uhookabove = 0x1ee6;
13460 t.Uhorn = 0x01af;
13461 t.Uhornacute = 0x1ee8;
13462 t.Uhorndotbelow = 0x1ef0;
13463 t.Uhorngrave = 0x1eea;
13464 t.Uhornhookabove = 0x1eec;
13465 t.Uhorntilde = 0x1eee;
13466 t.Uhungarumlaut = 0x0170;
13467 t.Uhungarumlautcyrillic = 0x04f2;
13468 t.Uinvertedbreve = 0x0216;
13469 t.Ukcyrillic = 0x0478;
13470 t.Umacron = 0x016a;
13471 t.Umacroncyrillic = 0x04ee;
13472 t.Umacrondieresis = 0x1e7a;
13473 t.Umonospace = 0xff35;
13474 t.Uogonek = 0x0172;
13475 t.Upsilon = 0x03a5;
13476 t.Upsilon1 = 0x03d2;
13477 t.Upsilonacutehooksymbolgreek = 0x03d3;
13478 t.Upsilonafrican = 0x01b1;
13479 t.Upsilondieresis = 0x03ab;
13480 t.Upsilondieresishooksymbolgreek = 0x03d4;
13481 t.Upsilonhooksymbol = 0x03d2;
13482 t.Upsilontonos = 0x038e;
13483 t.Uring = 0x016e;
13484 t.Ushortcyrillic = 0x040e;
13485 t.Usmall = 0xf775;
13486 t.Ustraightcyrillic = 0x04ae;
13487 t.Ustraightstrokecyrillic = 0x04b0;
13488 t.Utilde = 0x0168;
13489 t.Utildeacute = 0x1e78;
13490 t.Utildebelow = 0x1e74;
13491 t.V = 0x0056;
13492 t.Vcircle = 0x24cb;
13493 t.Vdotbelow = 0x1e7e;
13494 t.Vecyrillic = 0x0412;
13495 t.Vewarmenian = 0x054e;
13496 t.Vhook = 0x01b2;
13497 t.Vmonospace = 0xff36;
13498 t.Voarmenian = 0x0548;
13499 t.Vsmall = 0xf776;
13500 t.Vtilde = 0x1e7c;
13501 t.W = 0x0057;
13502 t.Wacute = 0x1e82;
13503 t.Wcircle = 0x24cc;
13504 t.Wcircumflex = 0x0174;
13505 t.Wdieresis = 0x1e84;
13506 t.Wdotaccent = 0x1e86;
13507 t.Wdotbelow = 0x1e88;
13508 t.Wgrave = 0x1e80;
13509 t.Wmonospace = 0xff37;
13510 t.Wsmall = 0xf777;
13511 t.X = 0x0058;
13512 t.Xcircle = 0x24cd;
13513 t.Xdieresis = 0x1e8c;
13514 t.Xdotaccent = 0x1e8a;
13515 t.Xeharmenian = 0x053d;
13516 t.Xi = 0x039e;
13517 t.Xmonospace = 0xff38;
13518 t.Xsmall = 0xf778;
13519 t.Y = 0x0059;
13520 t.Yacute = 0x00dd;
13521 t.Yacutesmall = 0xf7fd;
13522 t.Yatcyrillic = 0x0462;
13523 t.Ycircle = 0x24ce;
13524 t.Ycircumflex = 0x0176;
13525 t.Ydieresis = 0x0178;
13526 t.Ydieresissmall = 0xf7ff;
13527 t.Ydotaccent = 0x1e8e;
13528 t.Ydotbelow = 0x1ef4;
13529 t.Yericyrillic = 0x042b;
13530 t.Yerudieresiscyrillic = 0x04f8;
13531 t.Ygrave = 0x1ef2;
13532 t.Yhook = 0x01b3;
13533 t.Yhookabove = 0x1ef6;
13534 t.Yiarmenian = 0x0545;
13535 t.Yicyrillic = 0x0407;
13536 t.Yiwnarmenian = 0x0552;
13537 t.Ymonospace = 0xff39;
13538 t.Ysmall = 0xf779;
13539 t.Ytilde = 0x1ef8;
13540 t.Yusbigcyrillic = 0x046a;
13541 t.Yusbigiotifiedcyrillic = 0x046c;
13542 t.Yuslittlecyrillic = 0x0466;
13543 t.Yuslittleiotifiedcyrillic = 0x0468;
13544 t.Z = 0x005a;
13545 t.Zaarmenian = 0x0536;
13546 t.Zacute = 0x0179;
13547 t.Zcaron = 0x017d;
13548 t.Zcaronsmall = 0xf6ff;
13549 t.Zcircle = 0x24cf;
13550 t.Zcircumflex = 0x1e90;
13551 t.Zdot = 0x017b;
13552 t.Zdotaccent = 0x017b;
13553 t.Zdotbelow = 0x1e92;
13554 t.Zecyrillic = 0x0417;
13555 t.Zedescendercyrillic = 0x0498;
13556 t.Zedieresiscyrillic = 0x04de;
13557 t.Zeta = 0x0396;
13558 t.Zhearmenian = 0x053a;
13559 t.Zhebrevecyrillic = 0x04c1;
13560 t.Zhecyrillic = 0x0416;
13561 t.Zhedescendercyrillic = 0x0496;
13562 t.Zhedieresiscyrillic = 0x04dc;
13563 t.Zlinebelow = 0x1e94;
13564 t.Zmonospace = 0xff3a;
13565 t.Zsmall = 0xf77a;
13566 t.Zstroke = 0x01b5;
13567 t.a = 0x0061;
13568 t.aabengali = 0x0986;
13569 t.aacute = 0x00e1;
13570 t.aadeva = 0x0906;
13571 t.aagujarati = 0x0a86;
13572 t.aagurmukhi = 0x0a06;
13573 t.aamatragurmukhi = 0x0a3e;
13574 t.aarusquare = 0x3303;
13575 t.aavowelsignbengali = 0x09be;
13576 t.aavowelsigndeva = 0x093e;
13577 t.aavowelsigngujarati = 0x0abe;
13578 t.abbreviationmarkarmenian = 0x055f;
13579 t.abbreviationsigndeva = 0x0970;
13580 t.abengali = 0x0985;
13581 t.abopomofo = 0x311a;
13582 t.abreve = 0x0103;
13583 t.abreveacute = 0x1eaf;
13584 t.abrevecyrillic = 0x04d1;
13585 t.abrevedotbelow = 0x1eb7;
13586 t.abrevegrave = 0x1eb1;
13587 t.abrevehookabove = 0x1eb3;
13588 t.abrevetilde = 0x1eb5;
13589 t.acaron = 0x01ce;
13590 t.acircle = 0x24d0;
13591 t.acircumflex = 0x00e2;
13592 t.acircumflexacute = 0x1ea5;
13593 t.acircumflexdotbelow = 0x1ead;
13594 t.acircumflexgrave = 0x1ea7;
13595 t.acircumflexhookabove = 0x1ea9;
13596 t.acircumflextilde = 0x1eab;
13597 t.acute = 0x00b4;
13598 t.acutebelowcmb = 0x0317;
13599 t.acutecmb = 0x0301;
13600 t.acutecomb = 0x0301;
13601 t.acutedeva = 0x0954;
13602 t.acutelowmod = 0x02cf;
13603 t.acutetonecmb = 0x0341;
13604 t.acyrillic = 0x0430;
13605 t.adblgrave = 0x0201;
13606 t.addakgurmukhi = 0x0a71;
13607 t.adeva = 0x0905;
13608 t.adieresis = 0x00e4;
13609 t.adieresiscyrillic = 0x04d3;
13610 t.adieresismacron = 0x01df;
13611 t.adotbelow = 0x1ea1;
13612 t.adotmacron = 0x01e1;
13613 t.ae = 0x00e6;
13614 t.aeacute = 0x01fd;
13615 t.aekorean = 0x3150;
13616 t.aemacron = 0x01e3;
13617 t.afii00208 = 0x2015;
13618 t.afii08941 = 0x20a4;
13619 t.afii10017 = 0x0410;
13620 t.afii10018 = 0x0411;
13621 t.afii10019 = 0x0412;
13622 t.afii10020 = 0x0413;
13623 t.afii10021 = 0x0414;
13624 t.afii10022 = 0x0415;
13625 t.afii10023 = 0x0401;
13626 t.afii10024 = 0x0416;
13627 t.afii10025 = 0x0417;
13628 t.afii10026 = 0x0418;
13629 t.afii10027 = 0x0419;
13630 t.afii10028 = 0x041a;
13631 t.afii10029 = 0x041b;
13632 t.afii10030 = 0x041c;
13633 t.afii10031 = 0x041d;
13634 t.afii10032 = 0x041e;
13635 t.afii10033 = 0x041f;
13636 t.afii10034 = 0x0420;
13637 t.afii10035 = 0x0421;
13638 t.afii10036 = 0x0422;
13639 t.afii10037 = 0x0423;
13640 t.afii10038 = 0x0424;
13641 t.afii10039 = 0x0425;
13642 t.afii10040 = 0x0426;
13643 t.afii10041 = 0x0427;
13644 t.afii10042 = 0x0428;
13645 t.afii10043 = 0x0429;
13646 t.afii10044 = 0x042a;
13647 t.afii10045 = 0x042b;
13648 t.afii10046 = 0x042c;
13649 t.afii10047 = 0x042d;
13650 t.afii10048 = 0x042e;
13651 t.afii10049 = 0x042f;
13652 t.afii10050 = 0x0490;
13653 t.afii10051 = 0x0402;
13654 t.afii10052 = 0x0403;
13655 t.afii10053 = 0x0404;
13656 t.afii10054 = 0x0405;
13657 t.afii10055 = 0x0406;
13658 t.afii10056 = 0x0407;
13659 t.afii10057 = 0x0408;
13660 t.afii10058 = 0x0409;
13661 t.afii10059 = 0x040a;
13662 t.afii10060 = 0x040b;
13663 t.afii10061 = 0x040c;
13664 t.afii10062 = 0x040e;
13665 t.afii10063 = 0xf6c4;
13666 t.afii10064 = 0xf6c5;
13667 t.afii10065 = 0x0430;
13668 t.afii10066 = 0x0431;
13669 t.afii10067 = 0x0432;
13670 t.afii10068 = 0x0433;
13671 t.afii10069 = 0x0434;
13672 t.afii10070 = 0x0435;
13673 t.afii10071 = 0x0451;
13674 t.afii10072 = 0x0436;
13675 t.afii10073 = 0x0437;
13676 t.afii10074 = 0x0438;
13677 t.afii10075 = 0x0439;
13678 t.afii10076 = 0x043a;
13679 t.afii10077 = 0x043b;
13680 t.afii10078 = 0x043c;
13681 t.afii10079 = 0x043d;
13682 t.afii10080 = 0x043e;
13683 t.afii10081 = 0x043f;
13684 t.afii10082 = 0x0440;
13685 t.afii10083 = 0x0441;
13686 t.afii10084 = 0x0442;
13687 t.afii10085 = 0x0443;
13688 t.afii10086 = 0x0444;
13689 t.afii10087 = 0x0445;
13690 t.afii10088 = 0x0446;
13691 t.afii10089 = 0x0447;
13692 t.afii10090 = 0x0448;
13693 t.afii10091 = 0x0449;
13694 t.afii10092 = 0x044a;
13695 t.afii10093 = 0x044b;
13696 t.afii10094 = 0x044c;
13697 t.afii10095 = 0x044d;
13698 t.afii10096 = 0x044e;
13699 t.afii10097 = 0x044f;
13700 t.afii10098 = 0x0491;
13701 t.afii10099 = 0x0452;
13702 t.afii10100 = 0x0453;
13703 t.afii10101 = 0x0454;
13704 t.afii10102 = 0x0455;
13705 t.afii10103 = 0x0456;
13706 t.afii10104 = 0x0457;
13707 t.afii10105 = 0x0458;
13708 t.afii10106 = 0x0459;
13709 t.afii10107 = 0x045a;
13710 t.afii10108 = 0x045b;
13711 t.afii10109 = 0x045c;
13712 t.afii10110 = 0x045e;
13713 t.afii10145 = 0x040f;
13714 t.afii10146 = 0x0462;
13715 t.afii10147 = 0x0472;
13716 t.afii10148 = 0x0474;
13717 t.afii10192 = 0xf6c6;
13718 t.afii10193 = 0x045f;
13719 t.afii10194 = 0x0463;
13720 t.afii10195 = 0x0473;
13721 t.afii10196 = 0x0475;
13722 t.afii10831 = 0xf6c7;
13723 t.afii10832 = 0xf6c8;
13724 t.afii10846 = 0x04d9;
13725 t.afii299 = 0x200e;
13726 t.afii300 = 0x200f;
13727 t.afii301 = 0x200d;
13728 t.afii57381 = 0x066a;
13729 t.afii57388 = 0x060c;
13730 t.afii57392 = 0x0660;
13731 t.afii57393 = 0x0661;
13732 t.afii57394 = 0x0662;
13733 t.afii57395 = 0x0663;
13734 t.afii57396 = 0x0664;
13735 t.afii57397 = 0x0665;
13736 t.afii57398 = 0x0666;
13737 t.afii57399 = 0x0667;
13738 t.afii57400 = 0x0668;
13739 t.afii57401 = 0x0669;
13740 t.afii57403 = 0x061b;
13741 t.afii57407 = 0x061f;
13742 t.afii57409 = 0x0621;
13743 t.afii57410 = 0x0622;
13744 t.afii57411 = 0x0623;
13745 t.afii57412 = 0x0624;
13746 t.afii57413 = 0x0625;
13747 t.afii57414 = 0x0626;
13748 t.afii57415 = 0x0627;
13749 t.afii57416 = 0x0628;
13750 t.afii57417 = 0x0629;
13751 t.afii57418 = 0x062a;
13752 t.afii57419 = 0x062b;
13753 t.afii57420 = 0x062c;
13754 t.afii57421 = 0x062d;
13755 t.afii57422 = 0x062e;
13756 t.afii57423 = 0x062f;
13757 t.afii57424 = 0x0630;
13758 t.afii57425 = 0x0631;
13759 t.afii57426 = 0x0632;
13760 t.afii57427 = 0x0633;
13761 t.afii57428 = 0x0634;
13762 t.afii57429 = 0x0635;
13763 t.afii57430 = 0x0636;
13764 t.afii57431 = 0x0637;
13765 t.afii57432 = 0x0638;
13766 t.afii57433 = 0x0639;
13767 t.afii57434 = 0x063a;
13768 t.afii57440 = 0x0640;
13769 t.afii57441 = 0x0641;
13770 t.afii57442 = 0x0642;
13771 t.afii57443 = 0x0643;
13772 t.afii57444 = 0x0644;
13773 t.afii57445 = 0x0645;
13774 t.afii57446 = 0x0646;
13775 t.afii57448 = 0x0648;
13776 t.afii57449 = 0x0649;
13777 t.afii57450 = 0x064a;
13778 t.afii57451 = 0x064b;
13779 t.afii57452 = 0x064c;
13780 t.afii57453 = 0x064d;
13781 t.afii57454 = 0x064e;
13782 t.afii57455 = 0x064f;
13783 t.afii57456 = 0x0650;
13784 t.afii57457 = 0x0651;
13785 t.afii57458 = 0x0652;
13786 t.afii57470 = 0x0647;
13787 t.afii57505 = 0x06a4;
13788 t.afii57506 = 0x067e;
13789 t.afii57507 = 0x0686;
13790 t.afii57508 = 0x0698;
13791 t.afii57509 = 0x06af;
13792 t.afii57511 = 0x0679;
13793 t.afii57512 = 0x0688;
13794 t.afii57513 = 0x0691;
13795 t.afii57514 = 0x06ba;
13796 t.afii57519 = 0x06d2;
13797 t.afii57534 = 0x06d5;
13798 t.afii57636 = 0x20aa;
13799 t.afii57645 = 0x05be;
13800 t.afii57658 = 0x05c3;
13801 t.afii57664 = 0x05d0;
13802 t.afii57665 = 0x05d1;
13803 t.afii57666 = 0x05d2;
13804 t.afii57667 = 0x05d3;
13805 t.afii57668 = 0x05d4;
13806 t.afii57669 = 0x05d5;
13807 t.afii57670 = 0x05d6;
13808 t.afii57671 = 0x05d7;
13809 t.afii57672 = 0x05d8;
13810 t.afii57673 = 0x05d9;
13811 t.afii57674 = 0x05da;
13812 t.afii57675 = 0x05db;
13813 t.afii57676 = 0x05dc;
13814 t.afii57677 = 0x05dd;
13815 t.afii57678 = 0x05de;
13816 t.afii57679 = 0x05df;
13817 t.afii57680 = 0x05e0;
13818 t.afii57681 = 0x05e1;
13819 t.afii57682 = 0x05e2;
13820 t.afii57683 = 0x05e3;
13821 t.afii57684 = 0x05e4;
13822 t.afii57685 = 0x05e5;
13823 t.afii57686 = 0x05e6;
13824 t.afii57687 = 0x05e7;
13825 t.afii57688 = 0x05e8;
13826 t.afii57689 = 0x05e9;
13827 t.afii57690 = 0x05ea;
13828 t.afii57694 = 0xfb2a;
13829 t.afii57695 = 0xfb2b;
13830 t.afii57700 = 0xfb4b;
13831 t.afii57705 = 0xfb1f;
13832 t.afii57716 = 0x05f0;
13833 t.afii57717 = 0x05f1;
13834 t.afii57718 = 0x05f2;
13835 t.afii57723 = 0xfb35;
13836 t.afii57793 = 0x05b4;
13837 t.afii57794 = 0x05b5;
13838 t.afii57795 = 0x05b6;
13839 t.afii57796 = 0x05bb;
13840 t.afii57797 = 0x05b8;
13841 t.afii57798 = 0x05b7;
13842 t.afii57799 = 0x05b0;
13843 t.afii57800 = 0x05b2;
13844 t.afii57801 = 0x05b1;
13845 t.afii57802 = 0x05b3;
13846 t.afii57803 = 0x05c2;
13847 t.afii57804 = 0x05c1;
13848 t.afii57806 = 0x05b9;
13849 t.afii57807 = 0x05bc;
13850 t.afii57839 = 0x05bd;
13851 t.afii57841 = 0x05bf;
13852 t.afii57842 = 0x05c0;
13853 t.afii57929 = 0x02bc;
13854 t.afii61248 = 0x2105;
13855 t.afii61289 = 0x2113;
13856 t.afii61352 = 0x2116;
13857 t.afii61573 = 0x202c;
13858 t.afii61574 = 0x202d;
13859 t.afii61575 = 0x202e;
13860 t.afii61664 = 0x200c;
13861 t.afii63167 = 0x066d;
13862 t.afii64937 = 0x02bd;
13863 t.agrave = 0x00e0;
13864 t.agujarati = 0x0a85;
13865 t.agurmukhi = 0x0a05;
13866 t.ahiragana = 0x3042;
13867 t.ahookabove = 0x1ea3;
13868 t.aibengali = 0x0990;
13869 t.aibopomofo = 0x311e;
13870 t.aideva = 0x0910;
13871 t.aiecyrillic = 0x04d5;
13872 t.aigujarati = 0x0a90;
13873 t.aigurmukhi = 0x0a10;
13874 t.aimatragurmukhi = 0x0a48;
13875 t.ainarabic = 0x0639;
13876 t.ainfinalarabic = 0xfeca;
13877 t.aininitialarabic = 0xfecb;
13878 t.ainmedialarabic = 0xfecc;
13879 t.ainvertedbreve = 0x0203;
13880 t.aivowelsignbengali = 0x09c8;
13881 t.aivowelsigndeva = 0x0948;
13882 t.aivowelsigngujarati = 0x0ac8;
13883 t.akatakana = 0x30a2;
13884 t.akatakanahalfwidth = 0xff71;
13885 t.akorean = 0x314f;
13886 t.alef = 0x05d0;
13887 t.alefarabic = 0x0627;
13888 t.alefdageshhebrew = 0xfb30;
13889 t.aleffinalarabic = 0xfe8e;
13890 t.alefhamzaabovearabic = 0x0623;
13891 t.alefhamzaabovefinalarabic = 0xfe84;
13892 t.alefhamzabelowarabic = 0x0625;
13893 t.alefhamzabelowfinalarabic = 0xfe88;
13894 t.alefhebrew = 0x05d0;
13895 t.aleflamedhebrew = 0xfb4f;
13896 t.alefmaddaabovearabic = 0x0622;
13897 t.alefmaddaabovefinalarabic = 0xfe82;
13898 t.alefmaksuraarabic = 0x0649;
13899 t.alefmaksurafinalarabic = 0xfef0;
13900 t.alefmaksurainitialarabic = 0xfef3;
13901 t.alefmaksuramedialarabic = 0xfef4;
13902 t.alefpatahhebrew = 0xfb2e;
13903 t.alefqamatshebrew = 0xfb2f;
13904 t.aleph = 0x2135;
13905 t.allequal = 0x224c;
13906 t.alpha = 0x03b1;
13907 t.alphatonos = 0x03ac;
13908 t.amacron = 0x0101;
13909 t.amonospace = 0xff41;
13910 t.ampersand = 0x0026;
13911 t.ampersandmonospace = 0xff06;
13912 t.ampersandsmall = 0xf726;
13913 t.amsquare = 0x33c2;
13914 t.anbopomofo = 0x3122;
13915 t.angbopomofo = 0x3124;
13916 t.angbracketleft = 0x3008;
13917 t.angbracketright = 0x3009;
13918 t.angkhankhuthai = 0x0e5a;
13919 t.angle = 0x2220;
13920 t.anglebracketleft = 0x3008;
13921 t.anglebracketleftvertical = 0xfe3f;
13922 t.anglebracketright = 0x3009;
13923 t.anglebracketrightvertical = 0xfe40;
13924 t.angleleft = 0x2329;
13925 t.angleright = 0x232a;
13926 t.angstrom = 0x212b;
13927 t.anoteleia = 0x0387;
13928 t.anudattadeva = 0x0952;
13929 t.anusvarabengali = 0x0982;
13930 t.anusvaradeva = 0x0902;
13931 t.anusvaragujarati = 0x0a82;
13932 t.aogonek = 0x0105;
13933 t.apaatosquare = 0x3300;
13934 t.aparen = 0x249c;
13935 t.apostrophearmenian = 0x055a;
13936 t.apostrophemod = 0x02bc;
13937 t.apple = 0xf8ff;
13938 t.approaches = 0x2250;
13939 t.approxequal = 0x2248;
13940 t.approxequalorimage = 0x2252;
13941 t.approximatelyequal = 0x2245;
13942 t.araeaekorean = 0x318e;
13943 t.araeakorean = 0x318d;
13944 t.arc = 0x2312;
13945 t.arighthalfring = 0x1e9a;
13946 t.aring = 0x00e5;
13947 t.aringacute = 0x01fb;
13948 t.aringbelow = 0x1e01;
13949 t.arrowboth = 0x2194;
13950 t.arrowdashdown = 0x21e3;
13951 t.arrowdashleft = 0x21e0;
13952 t.arrowdashright = 0x21e2;
13953 t.arrowdashup = 0x21e1;
13954 t.arrowdblboth = 0x21d4;
13955 t.arrowdbldown = 0x21d3;
13956 t.arrowdblleft = 0x21d0;
13957 t.arrowdblright = 0x21d2;
13958 t.arrowdblup = 0x21d1;
13959 t.arrowdown = 0x2193;
13960 t.arrowdownleft = 0x2199;
13961 t.arrowdownright = 0x2198;
13962 t.arrowdownwhite = 0x21e9;
13963 t.arrowheaddownmod = 0x02c5;
13964 t.arrowheadleftmod = 0x02c2;
13965 t.arrowheadrightmod = 0x02c3;
13966 t.arrowheadupmod = 0x02c4;
13967 t.arrowhorizex = 0xf8e7;
13968 t.arrowleft = 0x2190;
13969 t.arrowleftdbl = 0x21d0;
13970 t.arrowleftdblstroke = 0x21cd;
13971 t.arrowleftoverright = 0x21c6;
13972 t.arrowleftwhite = 0x21e6;
13973 t.arrowright = 0x2192;
13974 t.arrowrightdblstroke = 0x21cf;
13975 t.arrowrightheavy = 0x279e;
13976 t.arrowrightoverleft = 0x21c4;
13977 t.arrowrightwhite = 0x21e8;
13978 t.arrowtableft = 0x21e4;
13979 t.arrowtabright = 0x21e5;
13980 t.arrowup = 0x2191;
13981 t.arrowupdn = 0x2195;
13982 t.arrowupdnbse = 0x21a8;
13983 t.arrowupdownbase = 0x21a8;
13984 t.arrowupleft = 0x2196;
13985 t.arrowupleftofdown = 0x21c5;
13986 t.arrowupright = 0x2197;
13987 t.arrowupwhite = 0x21e7;
13988 t.arrowvertex = 0xf8e6;
13989 t.asciicircum = 0x005e;
13990 t.asciicircummonospace = 0xff3e;
13991 t.asciitilde = 0x007e;
13992 t.asciitildemonospace = 0xff5e;
13993 t.ascript = 0x0251;
13994 t.ascriptturned = 0x0252;
13995 t.asmallhiragana = 0x3041;
13996 t.asmallkatakana = 0x30a1;
13997 t.asmallkatakanahalfwidth = 0xff67;
13998 t.asterisk = 0x002a;
13999 t.asteriskaltonearabic = 0x066d;
14000 t.asteriskarabic = 0x066d;
14001 t.asteriskmath = 0x2217;
14002 t.asteriskmonospace = 0xff0a;
14003 t.asterisksmall = 0xfe61;
14004 t.asterism = 0x2042;
14005 t.asuperior = 0xf6e9;
14006 t.asymptoticallyequal = 0x2243;
14007 t.at = 0x0040;
14008 t.atilde = 0x00e3;
14009 t.atmonospace = 0xff20;
14010 t.atsmall = 0xfe6b;
14011 t.aturned = 0x0250;
14012 t.aubengali = 0x0994;
14013 t.aubopomofo = 0x3120;
14014 t.audeva = 0x0914;
14015 t.augujarati = 0x0a94;
14016 t.augurmukhi = 0x0a14;
14017 t.aulengthmarkbengali = 0x09d7;
14018 t.aumatragurmukhi = 0x0a4c;
14019 t.auvowelsignbengali = 0x09cc;
14020 t.auvowelsigndeva = 0x094c;
14021 t.auvowelsigngujarati = 0x0acc;
14022 t.avagrahadeva = 0x093d;
14023 t.aybarmenian = 0x0561;
14024 t.ayin = 0x05e2;
14025 t.ayinaltonehebrew = 0xfb20;
14026 t.ayinhebrew = 0x05e2;
14027 t.b = 0x0062;
14028 t.babengali = 0x09ac;
14029 t.backslash = 0x005c;
14030 t.backslashmonospace = 0xff3c;
14031 t.badeva = 0x092c;
14032 t.bagujarati = 0x0aac;
14033 t.bagurmukhi = 0x0a2c;
14034 t.bahiragana = 0x3070;
14035 t.bahtthai = 0x0e3f;
14036 t.bakatakana = 0x30d0;
14037 t.bar = 0x007c;
14038 t.barmonospace = 0xff5c;
14039 t.bbopomofo = 0x3105;
14040 t.bcircle = 0x24d1;
14041 t.bdotaccent = 0x1e03;
14042 t.bdotbelow = 0x1e05;
14043 t.beamedsixteenthnotes = 0x266c;
14044 t.because = 0x2235;
14045 t.becyrillic = 0x0431;
14046 t.beharabic = 0x0628;
14047 t.behfinalarabic = 0xfe90;
14048 t.behinitialarabic = 0xfe91;
14049 t.behiragana = 0x3079;
14050 t.behmedialarabic = 0xfe92;
14051 t.behmeeminitialarabic = 0xfc9f;
14052 t.behmeemisolatedarabic = 0xfc08;
14053 t.behnoonfinalarabic = 0xfc6d;
14054 t.bekatakana = 0x30d9;
14055 t.benarmenian = 0x0562;
14056 t.bet = 0x05d1;
14057 t.beta = 0x03b2;
14058 t.betasymbolgreek = 0x03d0;
14059 t.betdagesh = 0xfb31;
14060 t.betdageshhebrew = 0xfb31;
14061 t.bethebrew = 0x05d1;
14062 t.betrafehebrew = 0xfb4c;
14063 t.bhabengali = 0x09ad;
14064 t.bhadeva = 0x092d;
14065 t.bhagujarati = 0x0aad;
14066 t.bhagurmukhi = 0x0a2d;
14067 t.bhook = 0x0253;
14068 t.bihiragana = 0x3073;
14069 t.bikatakana = 0x30d3;
14070 t.bilabialclick = 0x0298;
14071 t.bindigurmukhi = 0x0a02;
14072 t.birusquare = 0x3331;
14073 t.blackcircle = 0x25cf;
14074 t.blackdiamond = 0x25c6;
14075 t.blackdownpointingtriangle = 0x25bc;
14076 t.blackleftpointingpointer = 0x25c4;
14077 t.blackleftpointingtriangle = 0x25c0;
14078 t.blacklenticularbracketleft = 0x3010;
14079 t.blacklenticularbracketleftvertical = 0xfe3b;
14080 t.blacklenticularbracketright = 0x3011;
14081 t.blacklenticularbracketrightvertical = 0xfe3c;
14082 t.blacklowerlefttriangle = 0x25e3;
14083 t.blacklowerrighttriangle = 0x25e2;
14084 t.blackrectangle = 0x25ac;
14085 t.blackrightpointingpointer = 0x25ba;
14086 t.blackrightpointingtriangle = 0x25b6;
14087 t.blacksmallsquare = 0x25aa;
14088 t.blacksmilingface = 0x263b;
14089 t.blacksquare = 0x25a0;
14090 t.blackstar = 0x2605;
14091 t.blackupperlefttriangle = 0x25e4;
14092 t.blackupperrighttriangle = 0x25e5;
14093 t.blackuppointingsmalltriangle = 0x25b4;
14094 t.blackuppointingtriangle = 0x25b2;
14095 t.blank = 0x2423;
14096 t.blinebelow = 0x1e07;
14097 t.block = 0x2588;
14098 t.bmonospace = 0xff42;
14099 t.bobaimaithai = 0x0e1a;
14100 t.bohiragana = 0x307c;
14101 t.bokatakana = 0x30dc;
14102 t.bparen = 0x249d;
14103 t.bqsquare = 0x33c3;
14104 t.braceex = 0xf8f4;
14105 t.braceleft = 0x007b;
14106 t.braceleftbt = 0xf8f3;
14107 t.braceleftmid = 0xf8f2;
14108 t.braceleftmonospace = 0xff5b;
14109 t.braceleftsmall = 0xfe5b;
14110 t.bracelefttp = 0xf8f1;
14111 t.braceleftvertical = 0xfe37;
14112 t.braceright = 0x007d;
14113 t.bracerightbt = 0xf8fe;
14114 t.bracerightmid = 0xf8fd;
14115 t.bracerightmonospace = 0xff5d;
14116 t.bracerightsmall = 0xfe5c;
14117 t.bracerighttp = 0xf8fc;
14118 t.bracerightvertical = 0xfe38;
14119 t.bracketleft = 0x005b;
14120 t.bracketleftbt = 0xf8f0;
14121 t.bracketleftex = 0xf8ef;
14122 t.bracketleftmonospace = 0xff3b;
14123 t.bracketlefttp = 0xf8ee;
14124 t.bracketright = 0x005d;
14125 t.bracketrightbt = 0xf8fb;
14126 t.bracketrightex = 0xf8fa;
14127 t.bracketrightmonospace = 0xff3d;
14128 t.bracketrighttp = 0xf8f9;
14129 t.breve = 0x02d8;
14130 t.brevebelowcmb = 0x032e;
14131 t.brevecmb = 0x0306;
14132 t.breveinvertedbelowcmb = 0x032f;
14133 t.breveinvertedcmb = 0x0311;
14134 t.breveinverteddoublecmb = 0x0361;
14135 t.bridgebelowcmb = 0x032a;
14136 t.bridgeinvertedbelowcmb = 0x033a;
14137 t.brokenbar = 0x00a6;
14138 t.bstroke = 0x0180;
14139 t.bsuperior = 0xf6ea;
14140 t.btopbar = 0x0183;
14141 t.buhiragana = 0x3076;
14142 t.bukatakana = 0x30d6;
14143 t.bullet = 0x2022;
14144 t.bulletinverse = 0x25d8;
14145 t.bulletoperator = 0x2219;
14146 t.bullseye = 0x25ce;
14147 t.c = 0x0063;
14148 t.caarmenian = 0x056e;
14149 t.cabengali = 0x099a;
14150 t.cacute = 0x0107;
14151 t.cadeva = 0x091a;
14152 t.cagujarati = 0x0a9a;
14153 t.cagurmukhi = 0x0a1a;
14154 t.calsquare = 0x3388;
14155 t.candrabindubengali = 0x0981;
14156 t.candrabinducmb = 0x0310;
14157 t.candrabindudeva = 0x0901;
14158 t.candrabindugujarati = 0x0a81;
14159 t.capslock = 0x21ea;
14160 t.careof = 0x2105;
14161 t.caron = 0x02c7;
14162 t.caronbelowcmb = 0x032c;
14163 t.caroncmb = 0x030c;
14164 t.carriagereturn = 0x21b5;
14165 t.cbopomofo = 0x3118;
14166 t.ccaron = 0x010d;
14167 t.ccedilla = 0x00e7;
14168 t.ccedillaacute = 0x1e09;
14169 t.ccircle = 0x24d2;
14170 t.ccircumflex = 0x0109;
14171 t.ccurl = 0x0255;
14172 t.cdot = 0x010b;
14173 t.cdotaccent = 0x010b;
14174 t.cdsquare = 0x33c5;
14175 t.cedilla = 0x00b8;
14176 t.cedillacmb = 0x0327;
14177 t.cent = 0x00a2;
14178 t.centigrade = 0x2103;
14179 t.centinferior = 0xf6df;
14180 t.centmonospace = 0xffe0;
14181 t.centoldstyle = 0xf7a2;
14182 t.centsuperior = 0xf6e0;
14183 t.chaarmenian = 0x0579;
14184 t.chabengali = 0x099b;
14185 t.chadeva = 0x091b;
14186 t.chagujarati = 0x0a9b;
14187 t.chagurmukhi = 0x0a1b;
14188 t.chbopomofo = 0x3114;
14189 t.cheabkhasiancyrillic = 0x04bd;
14190 t.checkmark = 0x2713;
14191 t.checyrillic = 0x0447;
14192 t.chedescenderabkhasiancyrillic = 0x04bf;
14193 t.chedescendercyrillic = 0x04b7;
14194 t.chedieresiscyrillic = 0x04f5;
14195 t.cheharmenian = 0x0573;
14196 t.chekhakassiancyrillic = 0x04cc;
14197 t.cheverticalstrokecyrillic = 0x04b9;
14198 t.chi = 0x03c7;
14199 t.chieuchacirclekorean = 0x3277;
14200 t.chieuchaparenkorean = 0x3217;
14201 t.chieuchcirclekorean = 0x3269;
14202 t.chieuchkorean = 0x314a;
14203 t.chieuchparenkorean = 0x3209;
14204 t.chochangthai = 0x0e0a;
14205 t.chochanthai = 0x0e08;
14206 t.chochingthai = 0x0e09;
14207 t.chochoethai = 0x0e0c;
14208 t.chook = 0x0188;
14209 t.cieucacirclekorean = 0x3276;
14210 t.cieucaparenkorean = 0x3216;
14211 t.cieuccirclekorean = 0x3268;
14212 t.cieuckorean = 0x3148;
14213 t.cieucparenkorean = 0x3208;
14214 t.cieucuparenkorean = 0x321c;
14215 t.circle = 0x25cb;
14216 t.circlecopyrt = 0x00a9;
14217 t.circlemultiply = 0x2297;
14218 t.circleot = 0x2299;
14219 t.circleplus = 0x2295;
14220 t.circlepostalmark = 0x3036;
14221 t.circlewithlefthalfblack = 0x25d0;
14222 t.circlewithrighthalfblack = 0x25d1;
14223 t.circumflex = 0x02c6;
14224 t.circumflexbelowcmb = 0x032d;
14225 t.circumflexcmb = 0x0302;
14226 t.clear = 0x2327;
14227 t.clickalveolar = 0x01c2;
14228 t.clickdental = 0x01c0;
14229 t.clicklateral = 0x01c1;
14230 t.clickretroflex = 0x01c3;
14231 t.club = 0x2663;
14232 t.clubsuitblack = 0x2663;
14233 t.clubsuitwhite = 0x2667;
14234 t.cmcubedsquare = 0x33a4;
14235 t.cmonospace = 0xff43;
14236 t.cmsquaredsquare = 0x33a0;
14237 t.coarmenian = 0x0581;
14238 t.colon = 0x003a;
14239 t.colonmonetary = 0x20a1;
14240 t.colonmonospace = 0xff1a;
14241 t.colonsign = 0x20a1;
14242 t.colonsmall = 0xfe55;
14243 t.colontriangularhalfmod = 0x02d1;
14244 t.colontriangularmod = 0x02d0;
14245 t.comma = 0x002c;
14246 t.commaabovecmb = 0x0313;
14247 t.commaaboverightcmb = 0x0315;
14248 t.commaaccent = 0xf6c3;
14249 t.commaarabic = 0x060c;
14250 t.commaarmenian = 0x055d;
14251 t.commainferior = 0xf6e1;
14252 t.commamonospace = 0xff0c;
14253 t.commareversedabovecmb = 0x0314;
14254 t.commareversedmod = 0x02bd;
14255 t.commasmall = 0xfe50;
14256 t.commasuperior = 0xf6e2;
14257 t.commaturnedabovecmb = 0x0312;
14258 t.commaturnedmod = 0x02bb;
14259 t.compass = 0x263c;
14260 t.congruent = 0x2245;
14261 t.contourintegral = 0x222e;
14262 t.control = 0x2303;
14263 t.controlACK = 0x0006;
14264 t.controlBEL = 0x0007;
14265 t.controlBS = 0x0008;
14266 t.controlCAN = 0x0018;
14267 t.controlCR = 0x000d;
14268 t.controlDC1 = 0x0011;
14269 t.controlDC2 = 0x0012;
14270 t.controlDC3 = 0x0013;
14271 t.controlDC4 = 0x0014;
14272 t.controlDEL = 0x007f;
14273 t.controlDLE = 0x0010;
14274 t.controlEM = 0x0019;
14275 t.controlENQ = 0x0005;
14276 t.controlEOT = 0x0004;
14277 t.controlESC = 0x001b;
14278 t.controlETB = 0x0017;
14279 t.controlETX = 0x0003;
14280 t.controlFF = 0x000c;
14281 t.controlFS = 0x001c;
14282 t.controlGS = 0x001d;
14283 t.controlHT = 0x0009;
14284 t.controlLF = 0x000a;
14285 t.controlNAK = 0x0015;
14286 t.controlNULL = 0x0000;
14287 t.controlRS = 0x001e;
14288 t.controlSI = 0x000f;
14289 t.controlSO = 0x000e;
14290 t.controlSOT = 0x0002;
14291 t.controlSTX = 0x0001;
14292 t.controlSUB = 0x001a;
14293 t.controlSYN = 0x0016;
14294 t.controlUS = 0x001f;
14295 t.controlVT = 0x000b;
14296 t.copyright = 0x00a9;
14297 t.copyrightsans = 0xf8e9;
14298 t.copyrightserif = 0xf6d9;
14299 t.cornerbracketleft = 0x300c;
14300 t.cornerbracketlefthalfwidth = 0xff62;
14301 t.cornerbracketleftvertical = 0xfe41;
14302 t.cornerbracketright = 0x300d;
14303 t.cornerbracketrighthalfwidth = 0xff63;
14304 t.cornerbracketrightvertical = 0xfe42;
14305 t.corporationsquare = 0x337f;
14306 t.cosquare = 0x33c7;
14307 t.coverkgsquare = 0x33c6;
14308 t.cparen = 0x249e;
14309 t.cruzeiro = 0x20a2;
14310 t.cstretched = 0x0297;
14311 t.curlyand = 0x22cf;
14312 t.curlyor = 0x22ce;
14313 t.currency = 0x00a4;
14314 t.cyrBreve = 0xf6d1;
14315 t.cyrFlex = 0xf6d2;
14316 t.cyrbreve = 0xf6d4;
14317 t.cyrflex = 0xf6d5;
14318 t.d = 0x0064;
14319 t.daarmenian = 0x0564;
14320 t.dabengali = 0x09a6;
14321 t.dadarabic = 0x0636;
14322 t.dadeva = 0x0926;
14323 t.dadfinalarabic = 0xfebe;
14324 t.dadinitialarabic = 0xfebf;
14325 t.dadmedialarabic = 0xfec0;
14326 t.dagesh = 0x05bc;
14327 t.dageshhebrew = 0x05bc;
14328 t.dagger = 0x2020;
14329 t.daggerdbl = 0x2021;
14330 t.dagujarati = 0x0aa6;
14331 t.dagurmukhi = 0x0a26;
14332 t.dahiragana = 0x3060;
14333 t.dakatakana = 0x30c0;
14334 t.dalarabic = 0x062f;
14335 t.dalet = 0x05d3;
14336 t.daletdagesh = 0xfb33;
14337 t.daletdageshhebrew = 0xfb33;
14338 t.dalethebrew = 0x05d3;
14339 t.dalfinalarabic = 0xfeaa;
14340 t.dammaarabic = 0x064f;
14341 t.dammalowarabic = 0x064f;
14342 t.dammatanaltonearabic = 0x064c;
14343 t.dammatanarabic = 0x064c;
14344 t.danda = 0x0964;
14345 t.dargahebrew = 0x05a7;
14346 t.dargalefthebrew = 0x05a7;
14347 t.dasiapneumatacyrilliccmb = 0x0485;
14348 t.dblGrave = 0xf6d3;
14349 t.dblanglebracketleft = 0x300a;
14350 t.dblanglebracketleftvertical = 0xfe3d;
14351 t.dblanglebracketright = 0x300b;
14352 t.dblanglebracketrightvertical = 0xfe3e;
14353 t.dblarchinvertedbelowcmb = 0x032b;
14354 t.dblarrowleft = 0x21d4;
14355 t.dblarrowright = 0x21d2;
14356 t.dbldanda = 0x0965;
14357 t.dblgrave = 0xf6d6;
14358 t.dblgravecmb = 0x030f;
14359 t.dblintegral = 0x222c;
14360 t.dbllowline = 0x2017;
14361 t.dbllowlinecmb = 0x0333;
14362 t.dbloverlinecmb = 0x033f;
14363 t.dblprimemod = 0x02ba;
14364 t.dblverticalbar = 0x2016;
14365 t.dblverticallineabovecmb = 0x030e;
14366 t.dbopomofo = 0x3109;
14367 t.dbsquare = 0x33c8;
14368 t.dcaron = 0x010f;
14369 t.dcedilla = 0x1e11;
14370 t.dcircle = 0x24d3;
14371 t.dcircumflexbelow = 0x1e13;
14372 t.dcroat = 0x0111;
14373 t.ddabengali = 0x09a1;
14374 t.ddadeva = 0x0921;
14375 t.ddagujarati = 0x0aa1;
14376 t.ddagurmukhi = 0x0a21;
14377 t.ddalarabic = 0x0688;
14378 t.ddalfinalarabic = 0xfb89;
14379 t.dddhadeva = 0x095c;
14380 t.ddhabengali = 0x09a2;
14381 t.ddhadeva = 0x0922;
14382 t.ddhagujarati = 0x0aa2;
14383 t.ddhagurmukhi = 0x0a22;
14384 t.ddotaccent = 0x1e0b;
14385 t.ddotbelow = 0x1e0d;
14386 t.decimalseparatorarabic = 0x066b;
14387 t.decimalseparatorpersian = 0x066b;
14388 t.decyrillic = 0x0434;
14389 t.degree = 0x00b0;
14390 t.dehihebrew = 0x05ad;
14391 t.dehiragana = 0x3067;
14392 t.deicoptic = 0x03ef;
14393 t.dekatakana = 0x30c7;
14394 t.deleteleft = 0x232b;
14395 t.deleteright = 0x2326;
14396 t.delta = 0x03b4;
14397 t.deltaturned = 0x018d;
14398 t.denominatorminusonenumeratorbengali = 0x09f8;
14399 t.dezh = 0x02a4;
14400 t.dhabengali = 0x09a7;
14401 t.dhadeva = 0x0927;
14402 t.dhagujarati = 0x0aa7;
14403 t.dhagurmukhi = 0x0a27;
14404 t.dhook = 0x0257;
14405 t.dialytikatonos = 0x0385;
14406 t.dialytikatonoscmb = 0x0344;
14407 t.diamond = 0x2666;
14408 t.diamondsuitwhite = 0x2662;
14409 t.dieresis = 0x00a8;
14410 t.dieresisacute = 0xf6d7;
14411 t.dieresisbelowcmb = 0x0324;
14412 t.dieresiscmb = 0x0308;
14413 t.dieresisgrave = 0xf6d8;
14414 t.dieresistonos = 0x0385;
14415 t.dihiragana = 0x3062;
14416 t.dikatakana = 0x30c2;
14417 t.dittomark = 0x3003;
14418 t.divide = 0x00f7;
14419 t.divides = 0x2223;
14420 t.divisionslash = 0x2215;
14421 t.djecyrillic = 0x0452;
14422 t.dkshade = 0x2593;
14423 t.dlinebelow = 0x1e0f;
14424 t.dlsquare = 0x3397;
14425 t.dmacron = 0x0111;
14426 t.dmonospace = 0xff44;
14427 t.dnblock = 0x2584;
14428 t.dochadathai = 0x0e0e;
14429 t.dodekthai = 0x0e14;
14430 t.dohiragana = 0x3069;
14431 t.dokatakana = 0x30c9;
14432 t.dollar = 0x0024;
14433 t.dollarinferior = 0xf6e3;
14434 t.dollarmonospace = 0xff04;
14435 t.dollaroldstyle = 0xf724;
14436 t.dollarsmall = 0xfe69;
14437 t.dollarsuperior = 0xf6e4;
14438 t.dong = 0x20ab;
14439 t.dorusquare = 0x3326;
14440 t.dotaccent = 0x02d9;
14441 t.dotaccentcmb = 0x0307;
14442 t.dotbelowcmb = 0x0323;
14443 t.dotbelowcomb = 0x0323;
14444 t.dotkatakana = 0x30fb;
14445 t.dotlessi = 0x0131;
14446 t.dotlessj = 0xf6be;
14447 t.dotlessjstrokehook = 0x0284;
14448 t.dotmath = 0x22c5;
14449 t.dottedcircle = 0x25cc;
14450 t.doubleyodpatah = 0xfb1f;
14451 t.doubleyodpatahhebrew = 0xfb1f;
14452 t.downtackbelowcmb = 0x031e;
14453 t.downtackmod = 0x02d5;
14454 t.dparen = 0x249f;
14455 t.dsuperior = 0xf6eb;
14456 t.dtail = 0x0256;
14457 t.dtopbar = 0x018c;
14458 t.duhiragana = 0x3065;
14459 t.dukatakana = 0x30c5;
14460 t.dz = 0x01f3;
14461 t.dzaltone = 0x02a3;
14462 t.dzcaron = 0x01c6;
14463 t.dzcurl = 0x02a5;
14464 t.dzeabkhasiancyrillic = 0x04e1;
14465 t.dzecyrillic = 0x0455;
14466 t.dzhecyrillic = 0x045f;
14467 t.e = 0x0065;
14468 t.eacute = 0x00e9;
14469 t.earth = 0x2641;
14470 t.ebengali = 0x098f;
14471 t.ebopomofo = 0x311c;
14472 t.ebreve = 0x0115;
14473 t.ecandradeva = 0x090d;
14474 t.ecandragujarati = 0x0a8d;
14475 t.ecandravowelsigndeva = 0x0945;
14476 t.ecandravowelsigngujarati = 0x0ac5;
14477 t.ecaron = 0x011b;
14478 t.ecedillabreve = 0x1e1d;
14479 t.echarmenian = 0x0565;
14480 t.echyiwnarmenian = 0x0587;
14481 t.ecircle = 0x24d4;
14482 t.ecircumflex = 0x00ea;
14483 t.ecircumflexacute = 0x1ebf;
14484 t.ecircumflexbelow = 0x1e19;
14485 t.ecircumflexdotbelow = 0x1ec7;
14486 t.ecircumflexgrave = 0x1ec1;
14487 t.ecircumflexhookabove = 0x1ec3;
14488 t.ecircumflextilde = 0x1ec5;
14489 t.ecyrillic = 0x0454;
14490 t.edblgrave = 0x0205;
14491 t.edeva = 0x090f;
14492 t.edieresis = 0x00eb;
14493 t.edot = 0x0117;
14494 t.edotaccent = 0x0117;
14495 t.edotbelow = 0x1eb9;
14496 t.eegurmukhi = 0x0a0f;
14497 t.eematragurmukhi = 0x0a47;
14498 t.efcyrillic = 0x0444;
14499 t.egrave = 0x00e8;
14500 t.egujarati = 0x0a8f;
14501 t.eharmenian = 0x0567;
14502 t.ehbopomofo = 0x311d;
14503 t.ehiragana = 0x3048;
14504 t.ehookabove = 0x1ebb;
14505 t.eibopomofo = 0x311f;
14506 t.eight = 0x0038;
14507 t.eightarabic = 0x0668;
14508 t.eightbengali = 0x09ee;
14509 t.eightcircle = 0x2467;
14510 t.eightcircleinversesansserif = 0x2791;
14511 t.eightdeva = 0x096e;
14512 t.eighteencircle = 0x2471;
14513 t.eighteenparen = 0x2485;
14514 t.eighteenperiod = 0x2499;
14515 t.eightgujarati = 0x0aee;
14516 t.eightgurmukhi = 0x0a6e;
14517 t.eighthackarabic = 0x0668;
14518 t.eighthangzhou = 0x3028;
14519 t.eighthnotebeamed = 0x266b;
14520 t.eightideographicparen = 0x3227;
14521 t.eightinferior = 0x2088;
14522 t.eightmonospace = 0xff18;
14523 t.eightoldstyle = 0xf738;
14524 t.eightparen = 0x247b;
14525 t.eightperiod = 0x248f;
14526 t.eightpersian = 0x06f8;
14527 t.eightroman = 0x2177;
14528 t.eightsuperior = 0x2078;
14529 t.eightthai = 0x0e58;
14530 t.einvertedbreve = 0x0207;
14531 t.eiotifiedcyrillic = 0x0465;
14532 t.ekatakana = 0x30a8;
14533 t.ekatakanahalfwidth = 0xff74;
14534 t.ekonkargurmukhi = 0x0a74;
14535 t.ekorean = 0x3154;
14536 t.elcyrillic = 0x043b;
14537 t.element = 0x2208;
14538 t.elevencircle = 0x246a;
14539 t.elevenparen = 0x247e;
14540 t.elevenperiod = 0x2492;
14541 t.elevenroman = 0x217a;
14542 t.ellipsis = 0x2026;
14543 t.ellipsisvertical = 0x22ee;
14544 t.emacron = 0x0113;
14545 t.emacronacute = 0x1e17;
14546 t.emacrongrave = 0x1e15;
14547 t.emcyrillic = 0x043c;
14548 t.emdash = 0x2014;
14549 t.emdashvertical = 0xfe31;
14550 t.emonospace = 0xff45;
14551 t.emphasismarkarmenian = 0x055b;
14552 t.emptyset = 0x2205;
14553 t.enbopomofo = 0x3123;
14554 t.encyrillic = 0x043d;
14555 t.endash = 0x2013;
14556 t.endashvertical = 0xfe32;
14557 t.endescendercyrillic = 0x04a3;
14558 t.eng = 0x014b;
14559 t.engbopomofo = 0x3125;
14560 t.enghecyrillic = 0x04a5;
14561 t.enhookcyrillic = 0x04c8;
14562 t.enspace = 0x2002;
14563 t.eogonek = 0x0119;
14564 t.eokorean = 0x3153;
14565 t.eopen = 0x025b;
14566 t.eopenclosed = 0x029a;
14567 t.eopenreversed = 0x025c;
14568 t.eopenreversedclosed = 0x025e;
14569 t.eopenreversedhook = 0x025d;
14570 t.eparen = 0x24a0;
14571 t.epsilon = 0x03b5;
14572 t.epsilontonos = 0x03ad;
14573 t.equal = 0x003d;
14574 t.equalmonospace = 0xff1d;
14575 t.equalsmall = 0xfe66;
14576 t.equalsuperior = 0x207c;
14577 t.equivalence = 0x2261;
14578 t.erbopomofo = 0x3126;
14579 t.ercyrillic = 0x0440;
14580 t.ereversed = 0x0258;
14581 t.ereversedcyrillic = 0x044d;
14582 t.escyrillic = 0x0441;
14583 t.esdescendercyrillic = 0x04ab;
14584 t.esh = 0x0283;
14585 t.eshcurl = 0x0286;
14586 t.eshortdeva = 0x090e;
14587 t.eshortvowelsigndeva = 0x0946;
14588 t.eshreversedloop = 0x01aa;
14589 t.eshsquatreversed = 0x0285;
14590 t.esmallhiragana = 0x3047;
14591 t.esmallkatakana = 0x30a7;
14592 t.esmallkatakanahalfwidth = 0xff6a;
14593 t.estimated = 0x212e;
14594 t.esuperior = 0xf6ec;
14595 t.eta = 0x03b7;
14596 t.etarmenian = 0x0568;
14597 t.etatonos = 0x03ae;
14598 t.eth = 0x00f0;
14599 t.etilde = 0x1ebd;
14600 t.etildebelow = 0x1e1b;
14601 t.etnahtafoukhhebrew = 0x0591;
14602 t.etnahtafoukhlefthebrew = 0x0591;
14603 t.etnahtahebrew = 0x0591;
14604 t.etnahtalefthebrew = 0x0591;
14605 t.eturned = 0x01dd;
14606 t.eukorean = 0x3161;
14607 t.euro = 0x20ac;
14608 t.evowelsignbengali = 0x09c7;
14609 t.evowelsigndeva = 0x0947;
14610 t.evowelsigngujarati = 0x0ac7;
14611 t.exclam = 0x0021;
14612 t.exclamarmenian = 0x055c;
14613 t.exclamdbl = 0x203c;
14614 t.exclamdown = 0x00a1;
14615 t.exclamdownsmall = 0xf7a1;
14616 t.exclammonospace = 0xff01;
14617 t.exclamsmall = 0xf721;
14618 t.existential = 0x2203;
14619 t.ezh = 0x0292;
14620 t.ezhcaron = 0x01ef;
14621 t.ezhcurl = 0x0293;
14622 t.ezhreversed = 0x01b9;
14623 t.ezhtail = 0x01ba;
14624 t.f = 0x0066;
14625 t.fadeva = 0x095e;
14626 t.fagurmukhi = 0x0a5e;
14627 t.fahrenheit = 0x2109;
14628 t.fathaarabic = 0x064e;
14629 t.fathalowarabic = 0x064e;
14630 t.fathatanarabic = 0x064b;
14631 t.fbopomofo = 0x3108;
14632 t.fcircle = 0x24d5;
14633 t.fdotaccent = 0x1e1f;
14634 t.feharabic = 0x0641;
14635 t.feharmenian = 0x0586;
14636 t.fehfinalarabic = 0xfed2;
14637 t.fehinitialarabic = 0xfed3;
14638 t.fehmedialarabic = 0xfed4;
14639 t.feicoptic = 0x03e5;
14640 t.female = 0x2640;
14641 t.ff = 0xfb00;
14642 t.f_f = 0xfb00;
14643 t.ffi = 0xfb03;
14644 t.f_f_i = 0xfb03;
14645 t.ffl = 0xfb04;
14646 t.f_f_l = 0xfb04;
14647 t.fi = 0xfb01;
14648 t.f_i = 0xfb01;
14649 t.fifteencircle = 0x246e;
14650 t.fifteenparen = 0x2482;
14651 t.fifteenperiod = 0x2496;
14652 t.figuredash = 0x2012;
14653 t.filledbox = 0x25a0;
14654 t.filledrect = 0x25ac;
14655 t.finalkaf = 0x05da;
14656 t.finalkafdagesh = 0xfb3a;
14657 t.finalkafdageshhebrew = 0xfb3a;
14658 t.finalkafhebrew = 0x05da;
14659 t.finalmem = 0x05dd;
14660 t.finalmemhebrew = 0x05dd;
14661 t.finalnun = 0x05df;
14662 t.finalnunhebrew = 0x05df;
14663 t.finalpe = 0x05e3;
14664 t.finalpehebrew = 0x05e3;
14665 t.finaltsadi = 0x05e5;
14666 t.finaltsadihebrew = 0x05e5;
14667 t.firsttonechinese = 0x02c9;
14668 t.fisheye = 0x25c9;
14669 t.fitacyrillic = 0x0473;
14670 t.five = 0x0035;
14671 t.fivearabic = 0x0665;
14672 t.fivebengali = 0x09eb;
14673 t.fivecircle = 0x2464;
14674 t.fivecircleinversesansserif = 0x278e;
14675 t.fivedeva = 0x096b;
14676 t.fiveeighths = 0x215d;
14677 t.fivegujarati = 0x0aeb;
14678 t.fivegurmukhi = 0x0a6b;
14679 t.fivehackarabic = 0x0665;
14680 t.fivehangzhou = 0x3025;
14681 t.fiveideographicparen = 0x3224;
14682 t.fiveinferior = 0x2085;
14683 t.fivemonospace = 0xff15;
14684 t.fiveoldstyle = 0xf735;
14685 t.fiveparen = 0x2478;
14686 t.fiveperiod = 0x248c;
14687 t.fivepersian = 0x06f5;
14688 t.fiveroman = 0x2174;
14689 t.fivesuperior = 0x2075;
14690 t.fivethai = 0x0e55;
14691 t.fl = 0xfb02;
14692 t.f_l = 0xfb02;
14693 t.florin = 0x0192;
14694 t.fmonospace = 0xff46;
14695 t.fmsquare = 0x3399;
14696 t.fofanthai = 0x0e1f;
14697 t.fofathai = 0x0e1d;
14698 t.fongmanthai = 0x0e4f;
14699 t.forall = 0x2200;
14700 t.four = 0x0034;
14701 t.fourarabic = 0x0664;
14702 t.fourbengali = 0x09ea;
14703 t.fourcircle = 0x2463;
14704 t.fourcircleinversesansserif = 0x278d;
14705 t.fourdeva = 0x096a;
14706 t.fourgujarati = 0x0aea;
14707 t.fourgurmukhi = 0x0a6a;
14708 t.fourhackarabic = 0x0664;
14709 t.fourhangzhou = 0x3024;
14710 t.fourideographicparen = 0x3223;
14711 t.fourinferior = 0x2084;
14712 t.fourmonospace = 0xff14;
14713 t.fournumeratorbengali = 0x09f7;
14714 t.fouroldstyle = 0xf734;
14715 t.fourparen = 0x2477;
14716 t.fourperiod = 0x248b;
14717 t.fourpersian = 0x06f4;
14718 t.fourroman = 0x2173;
14719 t.foursuperior = 0x2074;
14720 t.fourteencircle = 0x246d;
14721 t.fourteenparen = 0x2481;
14722 t.fourteenperiod = 0x2495;
14723 t.fourthai = 0x0e54;
14724 t.fourthtonechinese = 0x02cb;
14725 t.fparen = 0x24a1;
14726 t.fraction = 0x2044;
14727 t.franc = 0x20a3;
14728 t.g = 0x0067;
14729 t.gabengali = 0x0997;
14730 t.gacute = 0x01f5;
14731 t.gadeva = 0x0917;
14732 t.gafarabic = 0x06af;
14733 t.gaffinalarabic = 0xfb93;
14734 t.gafinitialarabic = 0xfb94;
14735 t.gafmedialarabic = 0xfb95;
14736 t.gagujarati = 0x0a97;
14737 t.gagurmukhi = 0x0a17;
14738 t.gahiragana = 0x304c;
14739 t.gakatakana = 0x30ac;
14740 t.gamma = 0x03b3;
14741 t.gammalatinsmall = 0x0263;
14742 t.gammasuperior = 0x02e0;
14743 t.gangiacoptic = 0x03eb;
14744 t.gbopomofo = 0x310d;
14745 t.gbreve = 0x011f;
14746 t.gcaron = 0x01e7;
14747 t.gcedilla = 0x0123;
14748 t.gcircle = 0x24d6;
14749 t.gcircumflex = 0x011d;
14750 t.gcommaaccent = 0x0123;
14751 t.gdot = 0x0121;
14752 t.gdotaccent = 0x0121;
14753 t.gecyrillic = 0x0433;
14754 t.gehiragana = 0x3052;
14755 t.gekatakana = 0x30b2;
14756 t.geometricallyequal = 0x2251;
14757 t.gereshaccenthebrew = 0x059c;
14758 t.gereshhebrew = 0x05f3;
14759 t.gereshmuqdamhebrew = 0x059d;
14760 t.germandbls = 0x00df;
14761 t.gershayimaccenthebrew = 0x059e;
14762 t.gershayimhebrew = 0x05f4;
14763 t.getamark = 0x3013;
14764 t.ghabengali = 0x0998;
14765 t.ghadarmenian = 0x0572;
14766 t.ghadeva = 0x0918;
14767 t.ghagujarati = 0x0a98;
14768 t.ghagurmukhi = 0x0a18;
14769 t.ghainarabic = 0x063a;
14770 t.ghainfinalarabic = 0xfece;
14771 t.ghaininitialarabic = 0xfecf;
14772 t.ghainmedialarabic = 0xfed0;
14773 t.ghemiddlehookcyrillic = 0x0495;
14774 t.ghestrokecyrillic = 0x0493;
14775 t.gheupturncyrillic = 0x0491;
14776 t.ghhadeva = 0x095a;
14777 t.ghhagurmukhi = 0x0a5a;
14778 t.ghook = 0x0260;
14779 t.ghzsquare = 0x3393;
14780 t.gihiragana = 0x304e;
14781 t.gikatakana = 0x30ae;
14782 t.gimarmenian = 0x0563;
14783 t.gimel = 0x05d2;
14784 t.gimeldagesh = 0xfb32;
14785 t.gimeldageshhebrew = 0xfb32;
14786 t.gimelhebrew = 0x05d2;
14787 t.gjecyrillic = 0x0453;
14788 t.glottalinvertedstroke = 0x01be;
14789 t.glottalstop = 0x0294;
14790 t.glottalstopinverted = 0x0296;
14791 t.glottalstopmod = 0x02c0;
14792 t.glottalstopreversed = 0x0295;
14793 t.glottalstopreversedmod = 0x02c1;
14794 t.glottalstopreversedsuperior = 0x02e4;
14795 t.glottalstopstroke = 0x02a1;
14796 t.glottalstopstrokereversed = 0x02a2;
14797 t.gmacron = 0x1e21;
14798 t.gmonospace = 0xff47;
14799 t.gohiragana = 0x3054;
14800 t.gokatakana = 0x30b4;
14801 t.gparen = 0x24a2;
14802 t.gpasquare = 0x33ac;
14803 t.gradient = 0x2207;
14804 t.grave = 0x0060;
14805 t.gravebelowcmb = 0x0316;
14806 t.gravecmb = 0x0300;
14807 t.gravecomb = 0x0300;
14808 t.gravedeva = 0x0953;
14809 t.gravelowmod = 0x02ce;
14810 t.gravemonospace = 0xff40;
14811 t.gravetonecmb = 0x0340;
14812 t.greater = 0x003e;
14813 t.greaterequal = 0x2265;
14814 t.greaterequalorless = 0x22db;
14815 t.greatermonospace = 0xff1e;
14816 t.greaterorequivalent = 0x2273;
14817 t.greaterorless = 0x2277;
14818 t.greateroverequal = 0x2267;
14819 t.greatersmall = 0xfe65;
14820 t.gscript = 0x0261;
14821 t.gstroke = 0x01e5;
14822 t.guhiragana = 0x3050;
14823 t.guillemotleft = 0x00ab;
14824 t.guillemotright = 0x00bb;
14825 t.guilsinglleft = 0x2039;
14826 t.guilsinglright = 0x203a;
14827 t.gukatakana = 0x30b0;
14828 t.guramusquare = 0x3318;
14829 t.gysquare = 0x33c9;
14830 t.h = 0x0068;
14831 t.haabkhasiancyrillic = 0x04a9;
14832 t.haaltonearabic = 0x06c1;
14833 t.habengali = 0x09b9;
14834 t.hadescendercyrillic = 0x04b3;
14835 t.hadeva = 0x0939;
14836 t.hagujarati = 0x0ab9;
14837 t.hagurmukhi = 0x0a39;
14838 t.haharabic = 0x062d;
14839 t.hahfinalarabic = 0xfea2;
14840 t.hahinitialarabic = 0xfea3;
14841 t.hahiragana = 0x306f;
14842 t.hahmedialarabic = 0xfea4;
14843 t.haitusquare = 0x332a;
14844 t.hakatakana = 0x30cf;
14845 t.hakatakanahalfwidth = 0xff8a;
14846 t.halantgurmukhi = 0x0a4d;
14847 t.hamzaarabic = 0x0621;
14848 t.hamzalowarabic = 0x0621;
14849 t.hangulfiller = 0x3164;
14850 t.hardsigncyrillic = 0x044a;
14851 t.harpoonleftbarbup = 0x21bc;
14852 t.harpoonrightbarbup = 0x21c0;
14853 t.hasquare = 0x33ca;
14854 t.hatafpatah = 0x05b2;
14855 t.hatafpatah16 = 0x05b2;
14856 t.hatafpatah23 = 0x05b2;
14857 t.hatafpatah2f = 0x05b2;
14858 t.hatafpatahhebrew = 0x05b2;
14859 t.hatafpatahnarrowhebrew = 0x05b2;
14860 t.hatafpatahquarterhebrew = 0x05b2;
14861 t.hatafpatahwidehebrew = 0x05b2;
14862 t.hatafqamats = 0x05b3;
14863 t.hatafqamats1b = 0x05b3;
14864 t.hatafqamats28 = 0x05b3;
14865 t.hatafqamats34 = 0x05b3;
14866 t.hatafqamatshebrew = 0x05b3;
14867 t.hatafqamatsnarrowhebrew = 0x05b3;
14868 t.hatafqamatsquarterhebrew = 0x05b3;
14869 t.hatafqamatswidehebrew = 0x05b3;
14870 t.hatafsegol = 0x05b1;
14871 t.hatafsegol17 = 0x05b1;
14872 t.hatafsegol24 = 0x05b1;
14873 t.hatafsegol30 = 0x05b1;
14874 t.hatafsegolhebrew = 0x05b1;
14875 t.hatafsegolnarrowhebrew = 0x05b1;
14876 t.hatafsegolquarterhebrew = 0x05b1;
14877 t.hatafsegolwidehebrew = 0x05b1;
14878 t.hbar = 0x0127;
14879 t.hbopomofo = 0x310f;
14880 t.hbrevebelow = 0x1e2b;
14881 t.hcedilla = 0x1e29;
14882 t.hcircle = 0x24d7;
14883 t.hcircumflex = 0x0125;
14884 t.hdieresis = 0x1e27;
14885 t.hdotaccent = 0x1e23;
14886 t.hdotbelow = 0x1e25;
14887 t.he = 0x05d4;
14888 t.heart = 0x2665;
14889 t.heartsuitblack = 0x2665;
14890 t.heartsuitwhite = 0x2661;
14891 t.hedagesh = 0xfb34;
14892 t.hedageshhebrew = 0xfb34;
14893 t.hehaltonearabic = 0x06c1;
14894 t.heharabic = 0x0647;
14895 t.hehebrew = 0x05d4;
14896 t.hehfinalaltonearabic = 0xfba7;
14897 t.hehfinalalttwoarabic = 0xfeea;
14898 t.hehfinalarabic = 0xfeea;
14899 t.hehhamzaabovefinalarabic = 0xfba5;
14900 t.hehhamzaaboveisolatedarabic = 0xfba4;
14901 t.hehinitialaltonearabic = 0xfba8;
14902 t.hehinitialarabic = 0xfeeb;
14903 t.hehiragana = 0x3078;
14904 t.hehmedialaltonearabic = 0xfba9;
14905 t.hehmedialarabic = 0xfeec;
14906 t.heiseierasquare = 0x337b;
14907 t.hekatakana = 0x30d8;
14908 t.hekatakanahalfwidth = 0xff8d;
14909 t.hekutaarusquare = 0x3336;
14910 t.henghook = 0x0267;
14911 t.herutusquare = 0x3339;
14912 t.het = 0x05d7;
14913 t.hethebrew = 0x05d7;
14914 t.hhook = 0x0266;
14915 t.hhooksuperior = 0x02b1;
14916 t.hieuhacirclekorean = 0x327b;
14917 t.hieuhaparenkorean = 0x321b;
14918 t.hieuhcirclekorean = 0x326d;
14919 t.hieuhkorean = 0x314e;
14920 t.hieuhparenkorean = 0x320d;
14921 t.hihiragana = 0x3072;
14922 t.hikatakana = 0x30d2;
14923 t.hikatakanahalfwidth = 0xff8b;
14924 t.hiriq = 0x05b4;
14925 t.hiriq14 = 0x05b4;
14926 t.hiriq21 = 0x05b4;
14927 t.hiriq2d = 0x05b4;
14928 t.hiriqhebrew = 0x05b4;
14929 t.hiriqnarrowhebrew = 0x05b4;
14930 t.hiriqquarterhebrew = 0x05b4;
14931 t.hiriqwidehebrew = 0x05b4;
14932 t.hlinebelow = 0x1e96;
14933 t.hmonospace = 0xff48;
14934 t.hoarmenian = 0x0570;
14935 t.hohipthai = 0x0e2b;
14936 t.hohiragana = 0x307b;
14937 t.hokatakana = 0x30db;
14938 t.hokatakanahalfwidth = 0xff8e;
14939 t.holam = 0x05b9;
14940 t.holam19 = 0x05b9;
14941 t.holam26 = 0x05b9;
14942 t.holam32 = 0x05b9;
14943 t.holamhebrew = 0x05b9;
14944 t.holamnarrowhebrew = 0x05b9;
14945 t.holamquarterhebrew = 0x05b9;
14946 t.holamwidehebrew = 0x05b9;
14947 t.honokhukthai = 0x0e2e;
14948 t.hookabovecomb = 0x0309;
14949 t.hookcmb = 0x0309;
14950 t.hookpalatalizedbelowcmb = 0x0321;
14951 t.hookretroflexbelowcmb = 0x0322;
14952 t.hoonsquare = 0x3342;
14953 t.horicoptic = 0x03e9;
14954 t.horizontalbar = 0x2015;
14955 t.horncmb = 0x031b;
14956 t.hotsprings = 0x2668;
14957 t.house = 0x2302;
14958 t.hparen = 0x24a3;
14959 t.hsuperior = 0x02b0;
14960 t.hturned = 0x0265;
14961 t.huhiragana = 0x3075;
14962 t.huiitosquare = 0x3333;
14963 t.hukatakana = 0x30d5;
14964 t.hukatakanahalfwidth = 0xff8c;
14965 t.hungarumlaut = 0x02dd;
14966 t.hungarumlautcmb = 0x030b;
14967 t.hv = 0x0195;
14968 t.hyphen = 0x002d;
14969 t.hypheninferior = 0xf6e5;
14970 t.hyphenmonospace = 0xff0d;
14971 t.hyphensmall = 0xfe63;
14972 t.hyphensuperior = 0xf6e6;
14973 t.hyphentwo = 0x2010;
14974 t.i = 0x0069;
14975 t.iacute = 0x00ed;
14976 t.iacyrillic = 0x044f;
14977 t.ibengali = 0x0987;
14978 t.ibopomofo = 0x3127;
14979 t.ibreve = 0x012d;
14980 t.icaron = 0x01d0;
14981 t.icircle = 0x24d8;
14982 t.icircumflex = 0x00ee;
14983 t.icyrillic = 0x0456;
14984 t.idblgrave = 0x0209;
14985 t.ideographearthcircle = 0x328f;
14986 t.ideographfirecircle = 0x328b;
14987 t.ideographicallianceparen = 0x323f;
14988 t.ideographiccallparen = 0x323a;
14989 t.ideographiccentrecircle = 0x32a5;
14990 t.ideographicclose = 0x3006;
14991 t.ideographiccomma = 0x3001;
14992 t.ideographiccommaleft = 0xff64;
14993 t.ideographiccongratulationparen = 0x3237;
14994 t.ideographiccorrectcircle = 0x32a3;
14995 t.ideographicearthparen = 0x322f;
14996 t.ideographicenterpriseparen = 0x323d;
14997 t.ideographicexcellentcircle = 0x329d;
14998 t.ideographicfestivalparen = 0x3240;
14999 t.ideographicfinancialcircle = 0x3296;
15000 t.ideographicfinancialparen = 0x3236;
15001 t.ideographicfireparen = 0x322b;
15002 t.ideographichaveparen = 0x3232;
15003 t.ideographichighcircle = 0x32a4;
15004 t.ideographiciterationmark = 0x3005;
15005 t.ideographiclaborcircle = 0x3298;
15006 t.ideographiclaborparen = 0x3238;
15007 t.ideographicleftcircle = 0x32a7;
15008 t.ideographiclowcircle = 0x32a6;
15009 t.ideographicmedicinecircle = 0x32a9;
15010 t.ideographicmetalparen = 0x322e;
15011 t.ideographicmoonparen = 0x322a;
15012 t.ideographicnameparen = 0x3234;
15013 t.ideographicperiod = 0x3002;
15014 t.ideographicprintcircle = 0x329e;
15015 t.ideographicreachparen = 0x3243;
15016 t.ideographicrepresentparen = 0x3239;
15017 t.ideographicresourceparen = 0x323e;
15018 t.ideographicrightcircle = 0x32a8;
15019 t.ideographicsecretcircle = 0x3299;
15020 t.ideographicselfparen = 0x3242;
15021 t.ideographicsocietyparen = 0x3233;
15022 t.ideographicspace = 0x3000;
15023 t.ideographicspecialparen = 0x3235;
15024 t.ideographicstockparen = 0x3231;
15025 t.ideographicstudyparen = 0x323b;
15026 t.ideographicsunparen = 0x3230;
15027 t.ideographicsuperviseparen = 0x323c;
15028 t.ideographicwaterparen = 0x322c;
15029 t.ideographicwoodparen = 0x322d;
15030 t.ideographiczero = 0x3007;
15031 t.ideographmetalcircle = 0x328e;
15032 t.ideographmooncircle = 0x328a;
15033 t.ideographnamecircle = 0x3294;
15034 t.ideographsuncircle = 0x3290;
15035 t.ideographwatercircle = 0x328c;
15036 t.ideographwoodcircle = 0x328d;
15037 t.ideva = 0x0907;
15038 t.idieresis = 0x00ef;
15039 t.idieresisacute = 0x1e2f;
15040 t.idieresiscyrillic = 0x04e5;
15041 t.idotbelow = 0x1ecb;
15042 t.iebrevecyrillic = 0x04d7;
15043 t.iecyrillic = 0x0435;
15044 t.ieungacirclekorean = 0x3275;
15045 t.ieungaparenkorean = 0x3215;
15046 t.ieungcirclekorean = 0x3267;
15047 t.ieungkorean = 0x3147;
15048 t.ieungparenkorean = 0x3207;
15049 t.igrave = 0x00ec;
15050 t.igujarati = 0x0a87;
15051 t.igurmukhi = 0x0a07;
15052 t.ihiragana = 0x3044;
15053 t.ihookabove = 0x1ec9;
15054 t.iibengali = 0x0988;
15055 t.iicyrillic = 0x0438;
15056 t.iideva = 0x0908;
15057 t.iigujarati = 0x0a88;
15058 t.iigurmukhi = 0x0a08;
15059 t.iimatragurmukhi = 0x0a40;
15060 t.iinvertedbreve = 0x020b;
15061 t.iishortcyrillic = 0x0439;
15062 t.iivowelsignbengali = 0x09c0;
15063 t.iivowelsigndeva = 0x0940;
15064 t.iivowelsigngujarati = 0x0ac0;
15065 t.ij = 0x0133;
15066 t.ikatakana = 0x30a4;
15067 t.ikatakanahalfwidth = 0xff72;
15068 t.ikorean = 0x3163;
15069 t.ilde = 0x02dc;
15070 t.iluyhebrew = 0x05ac;
15071 t.imacron = 0x012b;
15072 t.imacroncyrillic = 0x04e3;
15073 t.imageorapproximatelyequal = 0x2253;
15074 t.imatragurmukhi = 0x0a3f;
15075 t.imonospace = 0xff49;
15076 t.increment = 0x2206;
15077 t.infinity = 0x221e;
15078 t.iniarmenian = 0x056b;
15079 t.integral = 0x222b;
15080 t.integralbottom = 0x2321;
15081 t.integralbt = 0x2321;
15082 t.integralex = 0xf8f5;
15083 t.integraltop = 0x2320;
15084 t.integraltp = 0x2320;
15085 t.intersection = 0x2229;
15086 t.intisquare = 0x3305;
15087 t.invbullet = 0x25d8;
15088 t.invcircle = 0x25d9;
15089 t.invsmileface = 0x263b;
15090 t.iocyrillic = 0x0451;
15091 t.iogonek = 0x012f;
15092 t.iota = 0x03b9;
15093 t.iotadieresis = 0x03ca;
15094 t.iotadieresistonos = 0x0390;
15095 t.iotalatin = 0x0269;
15096 t.iotatonos = 0x03af;
15097 t.iparen = 0x24a4;
15098 t.irigurmukhi = 0x0a72;
15099 t.ismallhiragana = 0x3043;
15100 t.ismallkatakana = 0x30a3;
15101 t.ismallkatakanahalfwidth = 0xff68;
15102 t.issharbengali = 0x09fa;
15103 t.istroke = 0x0268;
15104 t.isuperior = 0xf6ed;
15105 t.iterationhiragana = 0x309d;
15106 t.iterationkatakana = 0x30fd;
15107 t.itilde = 0x0129;
15108 t.itildebelow = 0x1e2d;
15109 t.iubopomofo = 0x3129;
15110 t.iucyrillic = 0x044e;
15111 t.ivowelsignbengali = 0x09bf;
15112 t.ivowelsigndeva = 0x093f;
15113 t.ivowelsigngujarati = 0x0abf;
15114 t.izhitsacyrillic = 0x0475;
15115 t.izhitsadblgravecyrillic = 0x0477;
15116 t.j = 0x006a;
15117 t.jaarmenian = 0x0571;
15118 t.jabengali = 0x099c;
15119 t.jadeva = 0x091c;
15120 t.jagujarati = 0x0a9c;
15121 t.jagurmukhi = 0x0a1c;
15122 t.jbopomofo = 0x3110;
15123 t.jcaron = 0x01f0;
15124 t.jcircle = 0x24d9;
15125 t.jcircumflex = 0x0135;
15126 t.jcrossedtail = 0x029d;
15127 t.jdotlessstroke = 0x025f;
15128 t.jecyrillic = 0x0458;
15129 t.jeemarabic = 0x062c;
15130 t.jeemfinalarabic = 0xfe9e;
15131 t.jeeminitialarabic = 0xfe9f;
15132 t.jeemmedialarabic = 0xfea0;
15133 t.jeharabic = 0x0698;
15134 t.jehfinalarabic = 0xfb8b;
15135 t.jhabengali = 0x099d;
15136 t.jhadeva = 0x091d;
15137 t.jhagujarati = 0x0a9d;
15138 t.jhagurmukhi = 0x0a1d;
15139 t.jheharmenian = 0x057b;
15140 t.jis = 0x3004;
15141 t.jmonospace = 0xff4a;
15142 t.jparen = 0x24a5;
15143 t.jsuperior = 0x02b2;
15144 t.k = 0x006b;
15145 t.kabashkircyrillic = 0x04a1;
15146 t.kabengali = 0x0995;
15147 t.kacute = 0x1e31;
15148 t.kacyrillic = 0x043a;
15149 t.kadescendercyrillic = 0x049b;
15150 t.kadeva = 0x0915;
15151 t.kaf = 0x05db;
15152 t.kafarabic = 0x0643;
15153 t.kafdagesh = 0xfb3b;
15154 t.kafdageshhebrew = 0xfb3b;
15155 t.kaffinalarabic = 0xfeda;
15156 t.kafhebrew = 0x05db;
15157 t.kafinitialarabic = 0xfedb;
15158 t.kafmedialarabic = 0xfedc;
15159 t.kafrafehebrew = 0xfb4d;
15160 t.kagujarati = 0x0a95;
15161 t.kagurmukhi = 0x0a15;
15162 t.kahiragana = 0x304b;
15163 t.kahookcyrillic = 0x04c4;
15164 t.kakatakana = 0x30ab;
15165 t.kakatakanahalfwidth = 0xff76;
15166 t.kappa = 0x03ba;
15167 t.kappasymbolgreek = 0x03f0;
15168 t.kapyeounmieumkorean = 0x3171;
15169 t.kapyeounphieuphkorean = 0x3184;
15170 t.kapyeounpieupkorean = 0x3178;
15171 t.kapyeounssangpieupkorean = 0x3179;
15172 t.karoriisquare = 0x330d;
15173 t.kashidaautoarabic = 0x0640;
15174 t.kashidaautonosidebearingarabic = 0x0640;
15175 t.kasmallkatakana = 0x30f5;
15176 t.kasquare = 0x3384;
15177 t.kasraarabic = 0x0650;
15178 t.kasratanarabic = 0x064d;
15179 t.kastrokecyrillic = 0x049f;
15180 t.katahiraprolongmarkhalfwidth = 0xff70;
15181 t.kaverticalstrokecyrillic = 0x049d;
15182 t.kbopomofo = 0x310e;
15183 t.kcalsquare = 0x3389;
15184 t.kcaron = 0x01e9;
15185 t.kcedilla = 0x0137;
15186 t.kcircle = 0x24da;
15187 t.kcommaaccent = 0x0137;
15188 t.kdotbelow = 0x1e33;
15189 t.keharmenian = 0x0584;
15190 t.kehiragana = 0x3051;
15191 t.kekatakana = 0x30b1;
15192 t.kekatakanahalfwidth = 0xff79;
15193 t.kenarmenian = 0x056f;
15194 t.kesmallkatakana = 0x30f6;
15195 t.kgreenlandic = 0x0138;
15196 t.khabengali = 0x0996;
15197 t.khacyrillic = 0x0445;
15198 t.khadeva = 0x0916;
15199 t.khagujarati = 0x0a96;
15200 t.khagurmukhi = 0x0a16;
15201 t.khaharabic = 0x062e;
15202 t.khahfinalarabic = 0xfea6;
15203 t.khahinitialarabic = 0xfea7;
15204 t.khahmedialarabic = 0xfea8;
15205 t.kheicoptic = 0x03e7;
15206 t.khhadeva = 0x0959;
15207 t.khhagurmukhi = 0x0a59;
15208 t.khieukhacirclekorean = 0x3278;
15209 t.khieukhaparenkorean = 0x3218;
15210 t.khieukhcirclekorean = 0x326a;
15211 t.khieukhkorean = 0x314b;
15212 t.khieukhparenkorean = 0x320a;
15213 t.khokhaithai = 0x0e02;
15214 t.khokhonthai = 0x0e05;
15215 t.khokhuatthai = 0x0e03;
15216 t.khokhwaithai = 0x0e04;
15217 t.khomutthai = 0x0e5b;
15218 t.khook = 0x0199;
15219 t.khorakhangthai = 0x0e06;
15220 t.khzsquare = 0x3391;
15221 t.kihiragana = 0x304d;
15222 t.kikatakana = 0x30ad;
15223 t.kikatakanahalfwidth = 0xff77;
15224 t.kiroguramusquare = 0x3315;
15225 t.kiromeetorusquare = 0x3316;
15226 t.kirosquare = 0x3314;
15227 t.kiyeokacirclekorean = 0x326e;
15228 t.kiyeokaparenkorean = 0x320e;
15229 t.kiyeokcirclekorean = 0x3260;
15230 t.kiyeokkorean = 0x3131;
15231 t.kiyeokparenkorean = 0x3200;
15232 t.kiyeoksioskorean = 0x3133;
15233 t.kjecyrillic = 0x045c;
15234 t.klinebelow = 0x1e35;
15235 t.klsquare = 0x3398;
15236 t.kmcubedsquare = 0x33a6;
15237 t.kmonospace = 0xff4b;
15238 t.kmsquaredsquare = 0x33a2;
15239 t.kohiragana = 0x3053;
15240 t.kohmsquare = 0x33c0;
15241 t.kokaithai = 0x0e01;
15242 t.kokatakana = 0x30b3;
15243 t.kokatakanahalfwidth = 0xff7a;
15244 t.kooposquare = 0x331e;
15245 t.koppacyrillic = 0x0481;
15246 t.koreanstandardsymbol = 0x327f;
15247 t.koroniscmb = 0x0343;
15248 t.kparen = 0x24a6;
15249 t.kpasquare = 0x33aa;
15250 t.ksicyrillic = 0x046f;
15251 t.ktsquare = 0x33cf;
15252 t.kturned = 0x029e;
15253 t.kuhiragana = 0x304f;
15254 t.kukatakana = 0x30af;
15255 t.kukatakanahalfwidth = 0xff78;
15256 t.kvsquare = 0x33b8;
15257 t.kwsquare = 0x33be;
15258 t.l = 0x006c;
15259 t.labengali = 0x09b2;
15260 t.lacute = 0x013a;
15261 t.ladeva = 0x0932;
15262 t.lagujarati = 0x0ab2;
15263 t.lagurmukhi = 0x0a32;
15264 t.lakkhangyaothai = 0x0e45;
15265 t.lamaleffinalarabic = 0xfefc;
15266 t.lamalefhamzaabovefinalarabic = 0xfef8;
15267 t.lamalefhamzaaboveisolatedarabic = 0xfef7;
15268 t.lamalefhamzabelowfinalarabic = 0xfefa;
15269 t.lamalefhamzabelowisolatedarabic = 0xfef9;
15270 t.lamalefisolatedarabic = 0xfefb;
15271 t.lamalefmaddaabovefinalarabic = 0xfef6;
15272 t.lamalefmaddaaboveisolatedarabic = 0xfef5;
15273 t.lamarabic = 0x0644;
15274 t.lambda = 0x03bb;
15275 t.lambdastroke = 0x019b;
15276 t.lamed = 0x05dc;
15277 t.lameddagesh = 0xfb3c;
15278 t.lameddageshhebrew = 0xfb3c;
15279 t.lamedhebrew = 0x05dc;
15280 t.lamfinalarabic = 0xfede;
15281 t.lamhahinitialarabic = 0xfcca;
15282 t.laminitialarabic = 0xfedf;
15283 t.lamjeeminitialarabic = 0xfcc9;
15284 t.lamkhahinitialarabic = 0xfccb;
15285 t.lamlamhehisolatedarabic = 0xfdf2;
15286 t.lammedialarabic = 0xfee0;
15287 t.lammeemhahinitialarabic = 0xfd88;
15288 t.lammeeminitialarabic = 0xfccc;
15289 t.largecircle = 0x25ef;
15290 t.lbar = 0x019a;
15291 t.lbelt = 0x026c;
15292 t.lbopomofo = 0x310c;
15293 t.lcaron = 0x013e;
15294 t.lcedilla = 0x013c;
15295 t.lcircle = 0x24db;
15296 t.lcircumflexbelow = 0x1e3d;
15297 t.lcommaaccent = 0x013c;
15298 t.ldot = 0x0140;
15299 t.ldotaccent = 0x0140;
15300 t.ldotbelow = 0x1e37;
15301 t.ldotbelowmacron = 0x1e39;
15302 t.leftangleabovecmb = 0x031a;
15303 t.lefttackbelowcmb = 0x0318;
15304 t.less = 0x003c;
15305 t.lessequal = 0x2264;
15306 t.lessequalorgreater = 0x22da;
15307 t.lessmonospace = 0xff1c;
15308 t.lessorequivalent = 0x2272;
15309 t.lessorgreater = 0x2276;
15310 t.lessoverequal = 0x2266;
15311 t.lesssmall = 0xfe64;
15312 t.lezh = 0x026e;
15313 t.lfblock = 0x258c;
15314 t.lhookretroflex = 0x026d;
15315 t.lira = 0x20a4;
15316 t.liwnarmenian = 0x056c;
15317 t.lj = 0x01c9;
15318 t.ljecyrillic = 0x0459;
15319 t.ll = 0xf6c0;
15320 t.lladeva = 0x0933;
15321 t.llagujarati = 0x0ab3;
15322 t.llinebelow = 0x1e3b;
15323 t.llladeva = 0x0934;
15324 t.llvocalicbengali = 0x09e1;
15325 t.llvocalicdeva = 0x0961;
15326 t.llvocalicvowelsignbengali = 0x09e3;
15327 t.llvocalicvowelsigndeva = 0x0963;
15328 t.lmiddletilde = 0x026b;
15329 t.lmonospace = 0xff4c;
15330 t.lmsquare = 0x33d0;
15331 t.lochulathai = 0x0e2c;
15332 t.logicaland = 0x2227;
15333 t.logicalnot = 0x00ac;
15334 t.logicalnotreversed = 0x2310;
15335 t.logicalor = 0x2228;
15336 t.lolingthai = 0x0e25;
15337 t.longs = 0x017f;
15338 t.lowlinecenterline = 0xfe4e;
15339 t.lowlinecmb = 0x0332;
15340 t.lowlinedashed = 0xfe4d;
15341 t.lozenge = 0x25ca;
15342 t.lparen = 0x24a7;
15343 t.lslash = 0x0142;
15344 t.lsquare = 0x2113;
15345 t.lsuperior = 0xf6ee;
15346 t.ltshade = 0x2591;
15347 t.luthai = 0x0e26;
15348 t.lvocalicbengali = 0x098c;
15349 t.lvocalicdeva = 0x090c;
15350 t.lvocalicvowelsignbengali = 0x09e2;
15351 t.lvocalicvowelsigndeva = 0x0962;
15352 t.lxsquare = 0x33d3;
15353 t.m = 0x006d;
15354 t.mabengali = 0x09ae;
15355 t.macron = 0x00af;
15356 t.macronbelowcmb = 0x0331;
15357 t.macroncmb = 0x0304;
15358 t.macronlowmod = 0x02cd;
15359 t.macronmonospace = 0xffe3;
15360 t.macute = 0x1e3f;
15361 t.madeva = 0x092e;
15362 t.magujarati = 0x0aae;
15363 t.magurmukhi = 0x0a2e;
15364 t.mahapakhhebrew = 0x05a4;
15365 t.mahapakhlefthebrew = 0x05a4;
15366 t.mahiragana = 0x307e;
15367 t.maichattawalowleftthai = 0xf895;
15368 t.maichattawalowrightthai = 0xf894;
15369 t.maichattawathai = 0x0e4b;
15370 t.maichattawaupperleftthai = 0xf893;
15371 t.maieklowleftthai = 0xf88c;
15372 t.maieklowrightthai = 0xf88b;
15373 t.maiekthai = 0x0e48;
15374 t.maiekupperleftthai = 0xf88a;
15375 t.maihanakatleftthai = 0xf884;
15376 t.maihanakatthai = 0x0e31;
15377 t.maitaikhuleftthai = 0xf889;
15378 t.maitaikhuthai = 0x0e47;
15379 t.maitholowleftthai = 0xf88f;
15380 t.maitholowrightthai = 0xf88e;
15381 t.maithothai = 0x0e49;
15382 t.maithoupperleftthai = 0xf88d;
15383 t.maitrilowleftthai = 0xf892;
15384 t.maitrilowrightthai = 0xf891;
15385 t.maitrithai = 0x0e4a;
15386 t.maitriupperleftthai = 0xf890;
15387 t.maiyamokthai = 0x0e46;
15388 t.makatakana = 0x30de;
15389 t.makatakanahalfwidth = 0xff8f;
15390 t.male = 0x2642;
15391 t.mansyonsquare = 0x3347;
15392 t.maqafhebrew = 0x05be;
15393 t.mars = 0x2642;
15394 t.masoracirclehebrew = 0x05af;
15395 t.masquare = 0x3383;
15396 t.mbopomofo = 0x3107;
15397 t.mbsquare = 0x33d4;
15398 t.mcircle = 0x24dc;
15399 t.mcubedsquare = 0x33a5;
15400 t.mdotaccent = 0x1e41;
15401 t.mdotbelow = 0x1e43;
15402 t.meemarabic = 0x0645;
15403 t.meemfinalarabic = 0xfee2;
15404 t.meeminitialarabic = 0xfee3;
15405 t.meemmedialarabic = 0xfee4;
15406 t.meemmeeminitialarabic = 0xfcd1;
15407 t.meemmeemisolatedarabic = 0xfc48;
15408 t.meetorusquare = 0x334d;
15409 t.mehiragana = 0x3081;
15410 t.meizierasquare = 0x337e;
15411 t.mekatakana = 0x30e1;
15412 t.mekatakanahalfwidth = 0xff92;
15413 t.mem = 0x05de;
15414 t.memdagesh = 0xfb3e;
15415 t.memdageshhebrew = 0xfb3e;
15416 t.memhebrew = 0x05de;
15417 t.menarmenian = 0x0574;
15418 t.merkhahebrew = 0x05a5;
15419 t.merkhakefulahebrew = 0x05a6;
15420 t.merkhakefulalefthebrew = 0x05a6;
15421 t.merkhalefthebrew = 0x05a5;
15422 t.mhook = 0x0271;
15423 t.mhzsquare = 0x3392;
15424 t.middledotkatakanahalfwidth = 0xff65;
15425 t.middot = 0x00b7;
15426 t.mieumacirclekorean = 0x3272;
15427 t.mieumaparenkorean = 0x3212;
15428 t.mieumcirclekorean = 0x3264;
15429 t.mieumkorean = 0x3141;
15430 t.mieumpansioskorean = 0x3170;
15431 t.mieumparenkorean = 0x3204;
15432 t.mieumpieupkorean = 0x316e;
15433 t.mieumsioskorean = 0x316f;
15434 t.mihiragana = 0x307f;
15435 t.mikatakana = 0x30df;
15436 t.mikatakanahalfwidth = 0xff90;
15437 t.minus = 0x2212;
15438 t.minusbelowcmb = 0x0320;
15439 t.minuscircle = 0x2296;
15440 t.minusmod = 0x02d7;
15441 t.minusplus = 0x2213;
15442 t.minute = 0x2032;
15443 t.miribaarusquare = 0x334a;
15444 t.mirisquare = 0x3349;
15445 t.mlonglegturned = 0x0270;
15446 t.mlsquare = 0x3396;
15447 t.mmcubedsquare = 0x33a3;
15448 t.mmonospace = 0xff4d;
15449 t.mmsquaredsquare = 0x339f;
15450 t.mohiragana = 0x3082;
15451 t.mohmsquare = 0x33c1;
15452 t.mokatakana = 0x30e2;
15453 t.mokatakanahalfwidth = 0xff93;
15454 t.molsquare = 0x33d6;
15455 t.momathai = 0x0e21;
15456 t.moverssquare = 0x33a7;
15457 t.moverssquaredsquare = 0x33a8;
15458 t.mparen = 0x24a8;
15459 t.mpasquare = 0x33ab;
15460 t.mssquare = 0x33b3;
15461 t.msuperior = 0xf6ef;
15462 t.mturned = 0x026f;
15463 t.mu = 0x00b5;
15464 t.mu1 = 0x00b5;
15465 t.muasquare = 0x3382;
15466 t.muchgreater = 0x226b;
15467 t.muchless = 0x226a;
15468 t.mufsquare = 0x338c;
15469 t.mugreek = 0x03bc;
15470 t.mugsquare = 0x338d;
15471 t.muhiragana = 0x3080;
15472 t.mukatakana = 0x30e0;
15473 t.mukatakanahalfwidth = 0xff91;
15474 t.mulsquare = 0x3395;
15475 t.multiply = 0x00d7;
15476 t.mumsquare = 0x339b;
15477 t.munahhebrew = 0x05a3;
15478 t.munahlefthebrew = 0x05a3;
15479 t.musicalnote = 0x266a;
15480 t.musicalnotedbl = 0x266b;
15481 t.musicflatsign = 0x266d;
15482 t.musicsharpsign = 0x266f;
15483 t.mussquare = 0x33b2;
15484 t.muvsquare = 0x33b6;
15485 t.muwsquare = 0x33bc;
15486 t.mvmegasquare = 0x33b9;
15487 t.mvsquare = 0x33b7;
15488 t.mwmegasquare = 0x33bf;
15489 t.mwsquare = 0x33bd;
15490 t.n = 0x006e;
15491 t.nabengali = 0x09a8;
15492 t.nabla = 0x2207;
15493 t.nacute = 0x0144;
15494 t.nadeva = 0x0928;
15495 t.nagujarati = 0x0aa8;
15496 t.nagurmukhi = 0x0a28;
15497 t.nahiragana = 0x306a;
15498 t.nakatakana = 0x30ca;
15499 t.nakatakanahalfwidth = 0xff85;
15500 t.napostrophe = 0x0149;
15501 t.nasquare = 0x3381;
15502 t.nbopomofo = 0x310b;
15503 t.nbspace = 0x00a0;
15504 t.ncaron = 0x0148;
15505 t.ncedilla = 0x0146;
15506 t.ncircle = 0x24dd;
15507 t.ncircumflexbelow = 0x1e4b;
15508 t.ncommaaccent = 0x0146;
15509 t.ndotaccent = 0x1e45;
15510 t.ndotbelow = 0x1e47;
15511 t.nehiragana = 0x306d;
15512 t.nekatakana = 0x30cd;
15513 t.nekatakanahalfwidth = 0xff88;
15514 t.newsheqelsign = 0x20aa;
15515 t.nfsquare = 0x338b;
15516 t.ngabengali = 0x0999;
15517 t.ngadeva = 0x0919;
15518 t.ngagujarati = 0x0a99;
15519 t.ngagurmukhi = 0x0a19;
15520 t.ngonguthai = 0x0e07;
15521 t.nhiragana = 0x3093;
15522 t.nhookleft = 0x0272;
15523 t.nhookretroflex = 0x0273;
15524 t.nieunacirclekorean = 0x326f;
15525 t.nieunaparenkorean = 0x320f;
15526 t.nieuncieuckorean = 0x3135;
15527 t.nieuncirclekorean = 0x3261;
15528 t.nieunhieuhkorean = 0x3136;
15529 t.nieunkorean = 0x3134;
15530 t.nieunpansioskorean = 0x3168;
15531 t.nieunparenkorean = 0x3201;
15532 t.nieunsioskorean = 0x3167;
15533 t.nieuntikeutkorean = 0x3166;
15534 t.nihiragana = 0x306b;
15535 t.nikatakana = 0x30cb;
15536 t.nikatakanahalfwidth = 0xff86;
15537 t.nikhahitleftthai = 0xf899;
15538 t.nikhahitthai = 0x0e4d;
15539 t.nine = 0x0039;
15540 t.ninearabic = 0x0669;
15541 t.ninebengali = 0x09ef;
15542 t.ninecircle = 0x2468;
15543 t.ninecircleinversesansserif = 0x2792;
15544 t.ninedeva = 0x096f;
15545 t.ninegujarati = 0x0aef;
15546 t.ninegurmukhi = 0x0a6f;
15547 t.ninehackarabic = 0x0669;
15548 t.ninehangzhou = 0x3029;
15549 t.nineideographicparen = 0x3228;
15550 t.nineinferior = 0x2089;
15551 t.ninemonospace = 0xff19;
15552 t.nineoldstyle = 0xf739;
15553 t.nineparen = 0x247c;
15554 t.nineperiod = 0x2490;
15555 t.ninepersian = 0x06f9;
15556 t.nineroman = 0x2178;
15557 t.ninesuperior = 0x2079;
15558 t.nineteencircle = 0x2472;
15559 t.nineteenparen = 0x2486;
15560 t.nineteenperiod = 0x249a;
15561 t.ninethai = 0x0e59;
15562 t.nj = 0x01cc;
15563 t.njecyrillic = 0x045a;
15564 t.nkatakana = 0x30f3;
15565 t.nkatakanahalfwidth = 0xff9d;
15566 t.nlegrightlong = 0x019e;
15567 t.nlinebelow = 0x1e49;
15568 t.nmonospace = 0xff4e;
15569 t.nmsquare = 0x339a;
15570 t.nnabengali = 0x09a3;
15571 t.nnadeva = 0x0923;
15572 t.nnagujarati = 0x0aa3;
15573 t.nnagurmukhi = 0x0a23;
15574 t.nnnadeva = 0x0929;
15575 t.nohiragana = 0x306e;
15576 t.nokatakana = 0x30ce;
15577 t.nokatakanahalfwidth = 0xff89;
15578 t.nonbreakingspace = 0x00a0;
15579 t.nonenthai = 0x0e13;
15580 t.nonuthai = 0x0e19;
15581 t.noonarabic = 0x0646;
15582 t.noonfinalarabic = 0xfee6;
15583 t.noonghunnaarabic = 0x06ba;
15584 t.noonghunnafinalarabic = 0xfb9f;
15585 t.nooninitialarabic = 0xfee7;
15586 t.noonjeeminitialarabic = 0xfcd2;
15587 t.noonjeemisolatedarabic = 0xfc4b;
15588 t.noonmedialarabic = 0xfee8;
15589 t.noonmeeminitialarabic = 0xfcd5;
15590 t.noonmeemisolatedarabic = 0xfc4e;
15591 t.noonnoonfinalarabic = 0xfc8d;
15592 t.notcontains = 0x220c;
15593 t.notelement = 0x2209;
15594 t.notelementof = 0x2209;
15595 t.notequal = 0x2260;
15596 t.notgreater = 0x226f;
15597 t.notgreaternorequal = 0x2271;
15598 t.notgreaternorless = 0x2279;
15599 t.notidentical = 0x2262;
15600 t.notless = 0x226e;
15601 t.notlessnorequal = 0x2270;
15602 t.notparallel = 0x2226;
15603 t.notprecedes = 0x2280;
15604 t.notsubset = 0x2284;
15605 t.notsucceeds = 0x2281;
15606 t.notsuperset = 0x2285;
15607 t.nowarmenian = 0x0576;
15608 t.nparen = 0x24a9;
15609 t.nssquare = 0x33b1;
15610 t.nsuperior = 0x207f;
15611 t.ntilde = 0x00f1;
15612 t.nu = 0x03bd;
15613 t.nuhiragana = 0x306c;
15614 t.nukatakana = 0x30cc;
15615 t.nukatakanahalfwidth = 0xff87;
15616 t.nuktabengali = 0x09bc;
15617 t.nuktadeva = 0x093c;
15618 t.nuktagujarati = 0x0abc;
15619 t.nuktagurmukhi = 0x0a3c;
15620 t.numbersign = 0x0023;
15621 t.numbersignmonospace = 0xff03;
15622 t.numbersignsmall = 0xfe5f;
15623 t.numeralsigngreek = 0x0374;
15624 t.numeralsignlowergreek = 0x0375;
15625 t.numero = 0x2116;
15626 t.nun = 0x05e0;
15627 t.nundagesh = 0xfb40;
15628 t.nundageshhebrew = 0xfb40;
15629 t.nunhebrew = 0x05e0;
15630 t.nvsquare = 0x33b5;
15631 t.nwsquare = 0x33bb;
15632 t.nyabengali = 0x099e;
15633 t.nyadeva = 0x091e;
15634 t.nyagujarati = 0x0a9e;
15635 t.nyagurmukhi = 0x0a1e;
15636 t.o = 0x006f;
15637 t.oacute = 0x00f3;
15638 t.oangthai = 0x0e2d;
15639 t.obarred = 0x0275;
15640 t.obarredcyrillic = 0x04e9;
15641 t.obarreddieresiscyrillic = 0x04eb;
15642 t.obengali = 0x0993;
15643 t.obopomofo = 0x311b;
15644 t.obreve = 0x014f;
15645 t.ocandradeva = 0x0911;
15646 t.ocandragujarati = 0x0a91;
15647 t.ocandravowelsigndeva = 0x0949;
15648 t.ocandravowelsigngujarati = 0x0ac9;
15649 t.ocaron = 0x01d2;
15650 t.ocircle = 0x24de;
15651 t.ocircumflex = 0x00f4;
15652 t.ocircumflexacute = 0x1ed1;
15653 t.ocircumflexdotbelow = 0x1ed9;
15654 t.ocircumflexgrave = 0x1ed3;
15655 t.ocircumflexhookabove = 0x1ed5;
15656 t.ocircumflextilde = 0x1ed7;
15657 t.ocyrillic = 0x043e;
15658 t.odblacute = 0x0151;
15659 t.odblgrave = 0x020d;
15660 t.odeva = 0x0913;
15661 t.odieresis = 0x00f6;
15662 t.odieresiscyrillic = 0x04e7;
15663 t.odotbelow = 0x1ecd;
15664 t.oe = 0x0153;
15665 t.oekorean = 0x315a;
15666 t.ogonek = 0x02db;
15667 t.ogonekcmb = 0x0328;
15668 t.ograve = 0x00f2;
15669 t.ogujarati = 0x0a93;
15670 t.oharmenian = 0x0585;
15671 t.ohiragana = 0x304a;
15672 t.ohookabove = 0x1ecf;
15673 t.ohorn = 0x01a1;
15674 t.ohornacute = 0x1edb;
15675 t.ohorndotbelow = 0x1ee3;
15676 t.ohorngrave = 0x1edd;
15677 t.ohornhookabove = 0x1edf;
15678 t.ohorntilde = 0x1ee1;
15679 t.ohungarumlaut = 0x0151;
15680 t.oi = 0x01a3;
15681 t.oinvertedbreve = 0x020f;
15682 t.okatakana = 0x30aa;
15683 t.okatakanahalfwidth = 0xff75;
15684 t.okorean = 0x3157;
15685 t.olehebrew = 0x05ab;
15686 t.omacron = 0x014d;
15687 t.omacronacute = 0x1e53;
15688 t.omacrongrave = 0x1e51;
15689 t.omdeva = 0x0950;
15690 t.omega = 0x03c9;
15691 t.omega1 = 0x03d6;
15692 t.omegacyrillic = 0x0461;
15693 t.omegalatinclosed = 0x0277;
15694 t.omegaroundcyrillic = 0x047b;
15695 t.omegatitlocyrillic = 0x047d;
15696 t.omegatonos = 0x03ce;
15697 t.omgujarati = 0x0ad0;
15698 t.omicron = 0x03bf;
15699 t.omicrontonos = 0x03cc;
15700 t.omonospace = 0xff4f;
15701 t.one = 0x0031;
15702 t.onearabic = 0x0661;
15703 t.onebengali = 0x09e7;
15704 t.onecircle = 0x2460;
15705 t.onecircleinversesansserif = 0x278a;
15706 t.onedeva = 0x0967;
15707 t.onedotenleader = 0x2024;
15708 t.oneeighth = 0x215b;
15709 t.onefitted = 0xf6dc;
15710 t.onegujarati = 0x0ae7;
15711 t.onegurmukhi = 0x0a67;
15712 t.onehackarabic = 0x0661;
15713 t.onehalf = 0x00bd;
15714 t.onehangzhou = 0x3021;
15715 t.oneideographicparen = 0x3220;
15716 t.oneinferior = 0x2081;
15717 t.onemonospace = 0xff11;
15718 t.onenumeratorbengali = 0x09f4;
15719 t.oneoldstyle = 0xf731;
15720 t.oneparen = 0x2474;
15721 t.oneperiod = 0x2488;
15722 t.onepersian = 0x06f1;
15723 t.onequarter = 0x00bc;
15724 t.oneroman = 0x2170;
15725 t.onesuperior = 0x00b9;
15726 t.onethai = 0x0e51;
15727 t.onethird = 0x2153;
15728 t.oogonek = 0x01eb;
15729 t.oogonekmacron = 0x01ed;
15730 t.oogurmukhi = 0x0a13;
15731 t.oomatragurmukhi = 0x0a4b;
15732 t.oopen = 0x0254;
15733 t.oparen = 0x24aa;
15734 t.openbullet = 0x25e6;
15735 t.option = 0x2325;
15736 t.ordfeminine = 0x00aa;
15737 t.ordmasculine = 0x00ba;
15738 t.orthogonal = 0x221f;
15739 t.oshortdeva = 0x0912;
15740 t.oshortvowelsigndeva = 0x094a;
15741 t.oslash = 0x00f8;
15742 t.oslashacute = 0x01ff;
15743 t.osmallhiragana = 0x3049;
15744 t.osmallkatakana = 0x30a9;
15745 t.osmallkatakanahalfwidth = 0xff6b;
15746 t.ostrokeacute = 0x01ff;
15747 t.osuperior = 0xf6f0;
15748 t.otcyrillic = 0x047f;
15749 t.otilde = 0x00f5;
15750 t.otildeacute = 0x1e4d;
15751 t.otildedieresis = 0x1e4f;
15752 t.oubopomofo = 0x3121;
15753 t.overline = 0x203e;
15754 t.overlinecenterline = 0xfe4a;
15755 t.overlinecmb = 0x0305;
15756 t.overlinedashed = 0xfe49;
15757 t.overlinedblwavy = 0xfe4c;
15758 t.overlinewavy = 0xfe4b;
15759 t.overscore = 0x00af;
15760 t.ovowelsignbengali = 0x09cb;
15761 t.ovowelsigndeva = 0x094b;
15762 t.ovowelsigngujarati = 0x0acb;
15763 t.p = 0x0070;
15764 t.paampssquare = 0x3380;
15765 t.paasentosquare = 0x332b;
15766 t.pabengali = 0x09aa;
15767 t.pacute = 0x1e55;
15768 t.padeva = 0x092a;
15769 t.pagedown = 0x21df;
15770 t.pageup = 0x21de;
15771 t.pagujarati = 0x0aaa;
15772 t.pagurmukhi = 0x0a2a;
15773 t.pahiragana = 0x3071;
15774 t.paiyannoithai = 0x0e2f;
15775 t.pakatakana = 0x30d1;
15776 t.palatalizationcyrilliccmb = 0x0484;
15777 t.palochkacyrillic = 0x04c0;
15778 t.pansioskorean = 0x317f;
15779 t.paragraph = 0x00b6;
15780 t.parallel = 0x2225;
15781 t.parenleft = 0x0028;
15782 t.parenleftaltonearabic = 0xfd3e;
15783 t.parenleftbt = 0xf8ed;
15784 t.parenleftex = 0xf8ec;
15785 t.parenleftinferior = 0x208d;
15786 t.parenleftmonospace = 0xff08;
15787 t.parenleftsmall = 0xfe59;
15788 t.parenleftsuperior = 0x207d;
15789 t.parenlefttp = 0xf8eb;
15790 t.parenleftvertical = 0xfe35;
15791 t.parenright = 0x0029;
15792 t.parenrightaltonearabic = 0xfd3f;
15793 t.parenrightbt = 0xf8f8;
15794 t.parenrightex = 0xf8f7;
15795 t.parenrightinferior = 0x208e;
15796 t.parenrightmonospace = 0xff09;
15797 t.parenrightsmall = 0xfe5a;
15798 t.parenrightsuperior = 0x207e;
15799 t.parenrighttp = 0xf8f6;
15800 t.parenrightvertical = 0xfe36;
15801 t.partialdiff = 0x2202;
15802 t.paseqhebrew = 0x05c0;
15803 t.pashtahebrew = 0x0599;
15804 t.pasquare = 0x33a9;
15805 t.patah = 0x05b7;
15806 t.patah11 = 0x05b7;
15807 t.patah1d = 0x05b7;
15808 t.patah2a = 0x05b7;
15809 t.patahhebrew = 0x05b7;
15810 t.patahnarrowhebrew = 0x05b7;
15811 t.patahquarterhebrew = 0x05b7;
15812 t.patahwidehebrew = 0x05b7;
15813 t.pazerhebrew = 0x05a1;
15814 t.pbopomofo = 0x3106;
15815 t.pcircle = 0x24df;
15816 t.pdotaccent = 0x1e57;
15817 t.pe = 0x05e4;
15818 t.pecyrillic = 0x043f;
15819 t.pedagesh = 0xfb44;
15820 t.pedageshhebrew = 0xfb44;
15821 t.peezisquare = 0x333b;
15822 t.pefinaldageshhebrew = 0xfb43;
15823 t.peharabic = 0x067e;
15824 t.peharmenian = 0x057a;
15825 t.pehebrew = 0x05e4;
15826 t.pehfinalarabic = 0xfb57;
15827 t.pehinitialarabic = 0xfb58;
15828 t.pehiragana = 0x307a;
15829 t.pehmedialarabic = 0xfb59;
15830 t.pekatakana = 0x30da;
15831 t.pemiddlehookcyrillic = 0x04a7;
15832 t.perafehebrew = 0xfb4e;
15833 t.percent = 0x0025;
15834 t.percentarabic = 0x066a;
15835 t.percentmonospace = 0xff05;
15836 t.percentsmall = 0xfe6a;
15837 t.period = 0x002e;
15838 t.periodarmenian = 0x0589;
15839 t.periodcentered = 0x00b7;
15840 t.periodhalfwidth = 0xff61;
15841 t.periodinferior = 0xf6e7;
15842 t.periodmonospace = 0xff0e;
15843 t.periodsmall = 0xfe52;
15844 t.periodsuperior = 0xf6e8;
15845 t.perispomenigreekcmb = 0x0342;
15846 t.perpendicular = 0x22a5;
15847 t.perthousand = 0x2030;
15848 t.peseta = 0x20a7;
15849 t.pfsquare = 0x338a;
15850 t.phabengali = 0x09ab;
15851 t.phadeva = 0x092b;
15852 t.phagujarati = 0x0aab;
15853 t.phagurmukhi = 0x0a2b;
15854 t.phi = 0x03c6;
15855 t.phi1 = 0x03d5;
15856 t.phieuphacirclekorean = 0x327a;
15857 t.phieuphaparenkorean = 0x321a;
15858 t.phieuphcirclekorean = 0x326c;
15859 t.phieuphkorean = 0x314d;
15860 t.phieuphparenkorean = 0x320c;
15861 t.philatin = 0x0278;
15862 t.phinthuthai = 0x0e3a;
15863 t.phisymbolgreek = 0x03d5;
15864 t.phook = 0x01a5;
15865 t.phophanthai = 0x0e1e;
15866 t.phophungthai = 0x0e1c;
15867 t.phosamphaothai = 0x0e20;
15868 t.pi = 0x03c0;
15869 t.pieupacirclekorean = 0x3273;
15870 t.pieupaparenkorean = 0x3213;
15871 t.pieupcieuckorean = 0x3176;
15872 t.pieupcirclekorean = 0x3265;
15873 t.pieupkiyeokkorean = 0x3172;
15874 t.pieupkorean = 0x3142;
15875 t.pieupparenkorean = 0x3205;
15876 t.pieupsioskiyeokkorean = 0x3174;
15877 t.pieupsioskorean = 0x3144;
15878 t.pieupsiostikeutkorean = 0x3175;
15879 t.pieupthieuthkorean = 0x3177;
15880 t.pieuptikeutkorean = 0x3173;
15881 t.pihiragana = 0x3074;
15882 t.pikatakana = 0x30d4;
15883 t.pisymbolgreek = 0x03d6;
15884 t.piwrarmenian = 0x0583;
15885 t.planckover2pi = 0x210f;
15886 t.planckover2pi1 = 0x210f;
15887 t.plus = 0x002b;
15888 t.plusbelowcmb = 0x031f;
15889 t.pluscircle = 0x2295;
15890 t.plusminus = 0x00b1;
15891 t.plusmod = 0x02d6;
15892 t.plusmonospace = 0xff0b;
15893 t.plussmall = 0xfe62;
15894 t.plussuperior = 0x207a;
15895 t.pmonospace = 0xff50;
15896 t.pmsquare = 0x33d8;
15897 t.pohiragana = 0x307d;
15898 t.pointingindexdownwhite = 0x261f;
15899 t.pointingindexleftwhite = 0x261c;
15900 t.pointingindexrightwhite = 0x261e;
15901 t.pointingindexupwhite = 0x261d;
15902 t.pokatakana = 0x30dd;
15903 t.poplathai = 0x0e1b;
15904 t.postalmark = 0x3012;
15905 t.postalmarkface = 0x3020;
15906 t.pparen = 0x24ab;
15907 t.precedes = 0x227a;
15908 t.prescription = 0x211e;
15909 t.primemod = 0x02b9;
15910 t.primereversed = 0x2035;
15911 t.product = 0x220f;
15912 t.projective = 0x2305;
15913 t.prolongedkana = 0x30fc;
15914 t.propellor = 0x2318;
15915 t.propersubset = 0x2282;
15916 t.propersuperset = 0x2283;
15917 t.proportion = 0x2237;
15918 t.proportional = 0x221d;
15919 t.psi = 0x03c8;
15920 t.psicyrillic = 0x0471;
15921 t.psilipneumatacyrilliccmb = 0x0486;
15922 t.pssquare = 0x33b0;
15923 t.puhiragana = 0x3077;
15924 t.pukatakana = 0x30d7;
15925 t.pvsquare = 0x33b4;
15926 t.pwsquare = 0x33ba;
15927 t.q = 0x0071;
15928 t.qadeva = 0x0958;
15929 t.qadmahebrew = 0x05a8;
15930 t.qafarabic = 0x0642;
15931 t.qaffinalarabic = 0xfed6;
15932 t.qafinitialarabic = 0xfed7;
15933 t.qafmedialarabic = 0xfed8;
15934 t.qamats = 0x05b8;
15935 t.qamats10 = 0x05b8;
15936 t.qamats1a = 0x05b8;
15937 t.qamats1c = 0x05b8;
15938 t.qamats27 = 0x05b8;
15939 t.qamats29 = 0x05b8;
15940 t.qamats33 = 0x05b8;
15941 t.qamatsde = 0x05b8;
15942 t.qamatshebrew = 0x05b8;
15943 t.qamatsnarrowhebrew = 0x05b8;
15944 t.qamatsqatanhebrew = 0x05b8;
15945 t.qamatsqatannarrowhebrew = 0x05b8;
15946 t.qamatsqatanquarterhebrew = 0x05b8;
15947 t.qamatsqatanwidehebrew = 0x05b8;
15948 t.qamatsquarterhebrew = 0x05b8;
15949 t.qamatswidehebrew = 0x05b8;
15950 t.qarneyparahebrew = 0x059f;
15951 t.qbopomofo = 0x3111;
15952 t.qcircle = 0x24e0;
15953 t.qhook = 0x02a0;
15954 t.qmonospace = 0xff51;
15955 t.qof = 0x05e7;
15956 t.qofdagesh = 0xfb47;
15957 t.qofdageshhebrew = 0xfb47;
15958 t.qofhebrew = 0x05e7;
15959 t.qparen = 0x24ac;
15960 t.quarternote = 0x2669;
15961 t.qubuts = 0x05bb;
15962 t.qubuts18 = 0x05bb;
15963 t.qubuts25 = 0x05bb;
15964 t.qubuts31 = 0x05bb;
15965 t.qubutshebrew = 0x05bb;
15966 t.qubutsnarrowhebrew = 0x05bb;
15967 t.qubutsquarterhebrew = 0x05bb;
15968 t.qubutswidehebrew = 0x05bb;
15969 t.question = 0x003f;
15970 t.questionarabic = 0x061f;
15971 t.questionarmenian = 0x055e;
15972 t.questiondown = 0x00bf;
15973 t.questiondownsmall = 0xf7bf;
15974 t.questiongreek = 0x037e;
15975 t.questionmonospace = 0xff1f;
15976 t.questionsmall = 0xf73f;
15977 t.quotedbl = 0x0022;
15978 t.quotedblbase = 0x201e;
15979 t.quotedblleft = 0x201c;
15980 t.quotedblmonospace = 0xff02;
15981 t.quotedblprime = 0x301e;
15982 t.quotedblprimereversed = 0x301d;
15983 t.quotedblright = 0x201d;
15984 t.quoteleft = 0x2018;
15985 t.quoteleftreversed = 0x201b;
15986 t.quotereversed = 0x201b;
15987 t.quoteright = 0x2019;
15988 t.quoterightn = 0x0149;
15989 t.quotesinglbase = 0x201a;
15990 t.quotesingle = 0x0027;
15991 t.quotesinglemonospace = 0xff07;
15992 t.r = 0x0072;
15993 t.raarmenian = 0x057c;
15994 t.rabengali = 0x09b0;
15995 t.racute = 0x0155;
15996 t.radeva = 0x0930;
15997 t.radical = 0x221a;
15998 t.radicalex = 0xf8e5;
15999 t.radoverssquare = 0x33ae;
16000 t.radoverssquaredsquare = 0x33af;
16001 t.radsquare = 0x33ad;
16002 t.rafe = 0x05bf;
16003 t.rafehebrew = 0x05bf;
16004 t.ragujarati = 0x0ab0;
16005 t.ragurmukhi = 0x0a30;
16006 t.rahiragana = 0x3089;
16007 t.rakatakana = 0x30e9;
16008 t.rakatakanahalfwidth = 0xff97;
16009 t.ralowerdiagonalbengali = 0x09f1;
16010 t.ramiddlediagonalbengali = 0x09f0;
16011 t.ramshorn = 0x0264;
16012 t.ratio = 0x2236;
16013 t.rbopomofo = 0x3116;
16014 t.rcaron = 0x0159;
16015 t.rcedilla = 0x0157;
16016 t.rcircle = 0x24e1;
16017 t.rcommaaccent = 0x0157;
16018 t.rdblgrave = 0x0211;
16019 t.rdotaccent = 0x1e59;
16020 t.rdotbelow = 0x1e5b;
16021 t.rdotbelowmacron = 0x1e5d;
16022 t.referencemark = 0x203b;
16023 t.reflexsubset = 0x2286;
16024 t.reflexsuperset = 0x2287;
16025 t.registered = 0x00ae;
16026 t.registersans = 0xf8e8;
16027 t.registerserif = 0xf6da;
16028 t.reharabic = 0x0631;
16029 t.reharmenian = 0x0580;
16030 t.rehfinalarabic = 0xfeae;
16031 t.rehiragana = 0x308c;
16032 t.rekatakana = 0x30ec;
16033 t.rekatakanahalfwidth = 0xff9a;
16034 t.resh = 0x05e8;
16035 t.reshdageshhebrew = 0xfb48;
16036 t.reshhebrew = 0x05e8;
16037 t.reversedtilde = 0x223d;
16038 t.reviahebrew = 0x0597;
16039 t.reviamugrashhebrew = 0x0597;
16040 t.revlogicalnot = 0x2310;
16041 t.rfishhook = 0x027e;
16042 t.rfishhookreversed = 0x027f;
16043 t.rhabengali = 0x09dd;
16044 t.rhadeva = 0x095d;
16045 t.rho = 0x03c1;
16046 t.rhook = 0x027d;
16047 t.rhookturned = 0x027b;
16048 t.rhookturnedsuperior = 0x02b5;
16049 t.rhosymbolgreek = 0x03f1;
16050 t.rhotichookmod = 0x02de;
16051 t.rieulacirclekorean = 0x3271;
16052 t.rieulaparenkorean = 0x3211;
16053 t.rieulcirclekorean = 0x3263;
16054 t.rieulhieuhkorean = 0x3140;
16055 t.rieulkiyeokkorean = 0x313a;
16056 t.rieulkiyeoksioskorean = 0x3169;
16057 t.rieulkorean = 0x3139;
16058 t.rieulmieumkorean = 0x313b;
16059 t.rieulpansioskorean = 0x316c;
16060 t.rieulparenkorean = 0x3203;
16061 t.rieulphieuphkorean = 0x313f;
16062 t.rieulpieupkorean = 0x313c;
16063 t.rieulpieupsioskorean = 0x316b;
16064 t.rieulsioskorean = 0x313d;
16065 t.rieulthieuthkorean = 0x313e;
16066 t.rieultikeutkorean = 0x316a;
16067 t.rieulyeorinhieuhkorean = 0x316d;
16068 t.rightangle = 0x221f;
16069 t.righttackbelowcmb = 0x0319;
16070 t.righttriangle = 0x22bf;
16071 t.rihiragana = 0x308a;
16072 t.rikatakana = 0x30ea;
16073 t.rikatakanahalfwidth = 0xff98;
16074 t.ring = 0x02da;
16075 t.ringbelowcmb = 0x0325;
16076 t.ringcmb = 0x030a;
16077 t.ringhalfleft = 0x02bf;
16078 t.ringhalfleftarmenian = 0x0559;
16079 t.ringhalfleftbelowcmb = 0x031c;
16080 t.ringhalfleftcentered = 0x02d3;
16081 t.ringhalfright = 0x02be;
16082 t.ringhalfrightbelowcmb = 0x0339;
16083 t.ringhalfrightcentered = 0x02d2;
16084 t.rinvertedbreve = 0x0213;
16085 t.rittorusquare = 0x3351;
16086 t.rlinebelow = 0x1e5f;
16087 t.rlongleg = 0x027c;
16088 t.rlonglegturned = 0x027a;
16089 t.rmonospace = 0xff52;
16090 t.rohiragana = 0x308d;
16091 t.rokatakana = 0x30ed;
16092 t.rokatakanahalfwidth = 0xff9b;
16093 t.roruathai = 0x0e23;
16094 t.rparen = 0x24ad;
16095 t.rrabengali = 0x09dc;
16096 t.rradeva = 0x0931;
16097 t.rragurmukhi = 0x0a5c;
16098 t.rreharabic = 0x0691;
16099 t.rrehfinalarabic = 0xfb8d;
16100 t.rrvocalicbengali = 0x09e0;
16101 t.rrvocalicdeva = 0x0960;
16102 t.rrvocalicgujarati = 0x0ae0;
16103 t.rrvocalicvowelsignbengali = 0x09c4;
16104 t.rrvocalicvowelsigndeva = 0x0944;
16105 t.rrvocalicvowelsigngujarati = 0x0ac4;
16106 t.rsuperior = 0xf6f1;
16107 t.rtblock = 0x2590;
16108 t.rturned = 0x0279;
16109 t.rturnedsuperior = 0x02b4;
16110 t.ruhiragana = 0x308b;
16111 t.rukatakana = 0x30eb;
16112 t.rukatakanahalfwidth = 0xff99;
16113 t.rupeemarkbengali = 0x09f2;
16114 t.rupeesignbengali = 0x09f3;
16115 t.rupiah = 0xf6dd;
16116 t.ruthai = 0x0e24;
16117 t.rvocalicbengali = 0x098b;
16118 t.rvocalicdeva = 0x090b;
16119 t.rvocalicgujarati = 0x0a8b;
16120 t.rvocalicvowelsignbengali = 0x09c3;
16121 t.rvocalicvowelsigndeva = 0x0943;
16122 t.rvocalicvowelsigngujarati = 0x0ac3;
16123 t.s = 0x0073;
16124 t.sabengali = 0x09b8;
16125 t.sacute = 0x015b;
16126 t.sacutedotaccent = 0x1e65;
16127 t.sadarabic = 0x0635;
16128 t.sadeva = 0x0938;
16129 t.sadfinalarabic = 0xfeba;
16130 t.sadinitialarabic = 0xfebb;
16131 t.sadmedialarabic = 0xfebc;
16132 t.sagujarati = 0x0ab8;
16133 t.sagurmukhi = 0x0a38;
16134 t.sahiragana = 0x3055;
16135 t.sakatakana = 0x30b5;
16136 t.sakatakanahalfwidth = 0xff7b;
16137 t.sallallahoualayhewasallamarabic = 0xfdfa;
16138 t.samekh = 0x05e1;
16139 t.samekhdagesh = 0xfb41;
16140 t.samekhdageshhebrew = 0xfb41;
16141 t.samekhhebrew = 0x05e1;
16142 t.saraaathai = 0x0e32;
16143 t.saraaethai = 0x0e41;
16144 t.saraaimaimalaithai = 0x0e44;
16145 t.saraaimaimuanthai = 0x0e43;
16146 t.saraamthai = 0x0e33;
16147 t.saraathai = 0x0e30;
16148 t.saraethai = 0x0e40;
16149 t.saraiileftthai = 0xf886;
16150 t.saraiithai = 0x0e35;
16151 t.saraileftthai = 0xf885;
16152 t.saraithai = 0x0e34;
16153 t.saraothai = 0x0e42;
16154 t.saraueeleftthai = 0xf888;
16155 t.saraueethai = 0x0e37;
16156 t.saraueleftthai = 0xf887;
16157 t.sarauethai = 0x0e36;
16158 t.sarauthai = 0x0e38;
16159 t.sarauuthai = 0x0e39;
16160 t.sbopomofo = 0x3119;
16161 t.scaron = 0x0161;
16162 t.scarondotaccent = 0x1e67;
16163 t.scedilla = 0x015f;
16164 t.schwa = 0x0259;
16165 t.schwacyrillic = 0x04d9;
16166 t.schwadieresiscyrillic = 0x04db;
16167 t.schwahook = 0x025a;
16168 t.scircle = 0x24e2;
16169 t.scircumflex = 0x015d;
16170 t.scommaaccent = 0x0219;
16171 t.sdotaccent = 0x1e61;
16172 t.sdotbelow = 0x1e63;
16173 t.sdotbelowdotaccent = 0x1e69;
16174 t.seagullbelowcmb = 0x033c;
16175 t.second = 0x2033;
16176 t.secondtonechinese = 0x02ca;
16177 t.section = 0x00a7;
16178 t.seenarabic = 0x0633;
16179 t.seenfinalarabic = 0xfeb2;
16180 t.seeninitialarabic = 0xfeb3;
16181 t.seenmedialarabic = 0xfeb4;
16182 t.segol = 0x05b6;
16183 t.segol13 = 0x05b6;
16184 t.segol1f = 0x05b6;
16185 t.segol2c = 0x05b6;
16186 t.segolhebrew = 0x05b6;
16187 t.segolnarrowhebrew = 0x05b6;
16188 t.segolquarterhebrew = 0x05b6;
16189 t.segoltahebrew = 0x0592;
16190 t.segolwidehebrew = 0x05b6;
16191 t.seharmenian = 0x057d;
16192 t.sehiragana = 0x305b;
16193 t.sekatakana = 0x30bb;
16194 t.sekatakanahalfwidth = 0xff7e;
16195 t.semicolon = 0x003b;
16196 t.semicolonarabic = 0x061b;
16197 t.semicolonmonospace = 0xff1b;
16198 t.semicolonsmall = 0xfe54;
16199 t.semivoicedmarkkana = 0x309c;
16200 t.semivoicedmarkkanahalfwidth = 0xff9f;
16201 t.sentisquare = 0x3322;
16202 t.sentosquare = 0x3323;
16203 t.seven = 0x0037;
16204 t.sevenarabic = 0x0667;
16205 t.sevenbengali = 0x09ed;
16206 t.sevencircle = 0x2466;
16207 t.sevencircleinversesansserif = 0x2790;
16208 t.sevendeva = 0x096d;
16209 t.seveneighths = 0x215e;
16210 t.sevengujarati = 0x0aed;
16211 t.sevengurmukhi = 0x0a6d;
16212 t.sevenhackarabic = 0x0667;
16213 t.sevenhangzhou = 0x3027;
16214 t.sevenideographicparen = 0x3226;
16215 t.seveninferior = 0x2087;
16216 t.sevenmonospace = 0xff17;
16217 t.sevenoldstyle = 0xf737;
16218 t.sevenparen = 0x247a;
16219 t.sevenperiod = 0x248e;
16220 t.sevenpersian = 0x06f7;
16221 t.sevenroman = 0x2176;
16222 t.sevensuperior = 0x2077;
16223 t.seventeencircle = 0x2470;
16224 t.seventeenparen = 0x2484;
16225 t.seventeenperiod = 0x2498;
16226 t.seventhai = 0x0e57;
16227 t.sfthyphen = 0x00ad;
16228 t.shaarmenian = 0x0577;
16229 t.shabengali = 0x09b6;
16230 t.shacyrillic = 0x0448;
16231 t.shaddaarabic = 0x0651;
16232 t.shaddadammaarabic = 0xfc61;
16233 t.shaddadammatanarabic = 0xfc5e;
16234 t.shaddafathaarabic = 0xfc60;
16235 t.shaddakasraarabic = 0xfc62;
16236 t.shaddakasratanarabic = 0xfc5f;
16237 t.shade = 0x2592;
16238 t.shadedark = 0x2593;
16239 t.shadelight = 0x2591;
16240 t.shademedium = 0x2592;
16241 t.shadeva = 0x0936;
16242 t.shagujarati = 0x0ab6;
16243 t.shagurmukhi = 0x0a36;
16244 t.shalshelethebrew = 0x0593;
16245 t.shbopomofo = 0x3115;
16246 t.shchacyrillic = 0x0449;
16247 t.sheenarabic = 0x0634;
16248 t.sheenfinalarabic = 0xfeb6;
16249 t.sheeninitialarabic = 0xfeb7;
16250 t.sheenmedialarabic = 0xfeb8;
16251 t.sheicoptic = 0x03e3;
16252 t.sheqel = 0x20aa;
16253 t.sheqelhebrew = 0x20aa;
16254 t.sheva = 0x05b0;
16255 t.sheva115 = 0x05b0;
16256 t.sheva15 = 0x05b0;
16257 t.sheva22 = 0x05b0;
16258 t.sheva2e = 0x05b0;
16259 t.shevahebrew = 0x05b0;
16260 t.shevanarrowhebrew = 0x05b0;
16261 t.shevaquarterhebrew = 0x05b0;
16262 t.shevawidehebrew = 0x05b0;
16263 t.shhacyrillic = 0x04bb;
16264 t.shimacoptic = 0x03ed;
16265 t.shin = 0x05e9;
16266 t.shindagesh = 0xfb49;
16267 t.shindageshhebrew = 0xfb49;
16268 t.shindageshshindot = 0xfb2c;
16269 t.shindageshshindothebrew = 0xfb2c;
16270 t.shindageshsindot = 0xfb2d;
16271 t.shindageshsindothebrew = 0xfb2d;
16272 t.shindothebrew = 0x05c1;
16273 t.shinhebrew = 0x05e9;
16274 t.shinshindot = 0xfb2a;
16275 t.shinshindothebrew = 0xfb2a;
16276 t.shinsindot = 0xfb2b;
16277 t.shinsindothebrew = 0xfb2b;
16278 t.shook = 0x0282;
16279 t.sigma = 0x03c3;
16280 t.sigma1 = 0x03c2;
16281 t.sigmafinal = 0x03c2;
16282 t.sigmalunatesymbolgreek = 0x03f2;
16283 t.sihiragana = 0x3057;
16284 t.sikatakana = 0x30b7;
16285 t.sikatakanahalfwidth = 0xff7c;
16286 t.siluqhebrew = 0x05bd;
16287 t.siluqlefthebrew = 0x05bd;
16288 t.similar = 0x223c;
16289 t.sindothebrew = 0x05c2;
16290 t.siosacirclekorean = 0x3274;
16291 t.siosaparenkorean = 0x3214;
16292 t.sioscieuckorean = 0x317e;
16293 t.sioscirclekorean = 0x3266;
16294 t.sioskiyeokkorean = 0x317a;
16295 t.sioskorean = 0x3145;
16296 t.siosnieunkorean = 0x317b;
16297 t.siosparenkorean = 0x3206;
16298 t.siospieupkorean = 0x317d;
16299 t.siostikeutkorean = 0x317c;
16300 t.six = 0x0036;
16301 t.sixarabic = 0x0666;
16302 t.sixbengali = 0x09ec;
16303 t.sixcircle = 0x2465;
16304 t.sixcircleinversesansserif = 0x278f;
16305 t.sixdeva = 0x096c;
16306 t.sixgujarati = 0x0aec;
16307 t.sixgurmukhi = 0x0a6c;
16308 t.sixhackarabic = 0x0666;
16309 t.sixhangzhou = 0x3026;
16310 t.sixideographicparen = 0x3225;
16311 t.sixinferior = 0x2086;
16312 t.sixmonospace = 0xff16;
16313 t.sixoldstyle = 0xf736;
16314 t.sixparen = 0x2479;
16315 t.sixperiod = 0x248d;
16316 t.sixpersian = 0x06f6;
16317 t.sixroman = 0x2175;
16318 t.sixsuperior = 0x2076;
16319 t.sixteencircle = 0x246f;
16320 t.sixteencurrencydenominatorbengali = 0x09f9;
16321 t.sixteenparen = 0x2483;
16322 t.sixteenperiod = 0x2497;
16323 t.sixthai = 0x0e56;
16324 t.slash = 0x002f;
16325 t.slashmonospace = 0xff0f;
16326 t.slong = 0x017f;
16327 t.slongdotaccent = 0x1e9b;
16328 t.smileface = 0x263a;
16329 t.smonospace = 0xff53;
16330 t.sofpasuqhebrew = 0x05c3;
16331 t.softhyphen = 0x00ad;
16332 t.softsigncyrillic = 0x044c;
16333 t.sohiragana = 0x305d;
16334 t.sokatakana = 0x30bd;
16335 t.sokatakanahalfwidth = 0xff7f;
16336 t.soliduslongoverlaycmb = 0x0338;
16337 t.solidusshortoverlaycmb = 0x0337;
16338 t.sorusithai = 0x0e29;
16339 t.sosalathai = 0x0e28;
16340 t.sosothai = 0x0e0b;
16341 t.sosuathai = 0x0e2a;
16342 t.space = 0x0020;
16343 t.spacehackarabic = 0x0020;
16344 t.spade = 0x2660;
16345 t.spadesuitblack = 0x2660;
16346 t.spadesuitwhite = 0x2664;
16347 t.sparen = 0x24ae;
16348 t.squarebelowcmb = 0x033b;
16349 t.squarecc = 0x33c4;
16350 t.squarecm = 0x339d;
16351 t.squarediagonalcrosshatchfill = 0x25a9;
16352 t.squarehorizontalfill = 0x25a4;
16353 t.squarekg = 0x338f;
16354 t.squarekm = 0x339e;
16355 t.squarekmcapital = 0x33ce;
16356 t.squareln = 0x33d1;
16357 t.squarelog = 0x33d2;
16358 t.squaremg = 0x338e;
16359 t.squaremil = 0x33d5;
16360 t.squaremm = 0x339c;
16361 t.squaremsquared = 0x33a1;
16362 t.squareorthogonalcrosshatchfill = 0x25a6;
16363 t.squareupperlefttolowerrightfill = 0x25a7;
16364 t.squareupperrighttolowerleftfill = 0x25a8;
16365 t.squareverticalfill = 0x25a5;
16366 t.squarewhitewithsmallblack = 0x25a3;
16367 t.srsquare = 0x33db;
16368 t.ssabengali = 0x09b7;
16369 t.ssadeva = 0x0937;
16370 t.ssagujarati = 0x0ab7;
16371 t.ssangcieuckorean = 0x3149;
16372 t.ssanghieuhkorean = 0x3185;
16373 t.ssangieungkorean = 0x3180;
16374 t.ssangkiyeokkorean = 0x3132;
16375 t.ssangnieunkorean = 0x3165;
16376 t.ssangpieupkorean = 0x3143;
16377 t.ssangsioskorean = 0x3146;
16378 t.ssangtikeutkorean = 0x3138;
16379 t.ssuperior = 0xf6f2;
16380 t.sterling = 0x00a3;
16381 t.sterlingmonospace = 0xffe1;
16382 t.strokelongoverlaycmb = 0x0336;
16383 t.strokeshortoverlaycmb = 0x0335;
16384 t.subset = 0x2282;
16385 t.subsetnotequal = 0x228a;
16386 t.subsetorequal = 0x2286;
16387 t.succeeds = 0x227b;
16388 t.suchthat = 0x220b;
16389 t.suhiragana = 0x3059;
16390 t.sukatakana = 0x30b9;
16391 t.sukatakanahalfwidth = 0xff7d;
16392 t.sukunarabic = 0x0652;
16393 t.summation = 0x2211;
16394 t.sun = 0x263c;
16395 t.superset = 0x2283;
16396 t.supersetnotequal = 0x228b;
16397 t.supersetorequal = 0x2287;
16398 t.svsquare = 0x33dc;
16399 t.syouwaerasquare = 0x337c;
16400 t.t = 0x0074;
16401 t.tabengali = 0x09a4;
16402 t.tackdown = 0x22a4;
16403 t.tackleft = 0x22a3;
16404 t.tadeva = 0x0924;
16405 t.tagujarati = 0x0aa4;
16406 t.tagurmukhi = 0x0a24;
16407 t.taharabic = 0x0637;
16408 t.tahfinalarabic = 0xfec2;
16409 t.tahinitialarabic = 0xfec3;
16410 t.tahiragana = 0x305f;
16411 t.tahmedialarabic = 0xfec4;
16412 t.taisyouerasquare = 0x337d;
16413 t.takatakana = 0x30bf;
16414 t.takatakanahalfwidth = 0xff80;
16415 t.tatweelarabic = 0x0640;
16416 t.tau = 0x03c4;
16417 t.tav = 0x05ea;
16418 t.tavdages = 0xfb4a;
16419 t.tavdagesh = 0xfb4a;
16420 t.tavdageshhebrew = 0xfb4a;
16421 t.tavhebrew = 0x05ea;
16422 t.tbar = 0x0167;
16423 t.tbopomofo = 0x310a;
16424 t.tcaron = 0x0165;
16425 t.tccurl = 0x02a8;
16426 t.tcedilla = 0x0163;
16427 t.tcheharabic = 0x0686;
16428 t.tchehfinalarabic = 0xfb7b;
16429 t.tchehinitialarabic = 0xfb7c;
16430 t.tchehmedialarabic = 0xfb7d;
16431 t.tcircle = 0x24e3;
16432 t.tcircumflexbelow = 0x1e71;
16433 t.tcommaaccent = 0x0163;
16434 t.tdieresis = 0x1e97;
16435 t.tdotaccent = 0x1e6b;
16436 t.tdotbelow = 0x1e6d;
16437 t.tecyrillic = 0x0442;
16438 t.tedescendercyrillic = 0x04ad;
16439 t.teharabic = 0x062a;
16440 t.tehfinalarabic = 0xfe96;
16441 t.tehhahinitialarabic = 0xfca2;
16442 t.tehhahisolatedarabic = 0xfc0c;
16443 t.tehinitialarabic = 0xfe97;
16444 t.tehiragana = 0x3066;
16445 t.tehjeeminitialarabic = 0xfca1;
16446 t.tehjeemisolatedarabic = 0xfc0b;
16447 t.tehmarbutaarabic = 0x0629;
16448 t.tehmarbutafinalarabic = 0xfe94;
16449 t.tehmedialarabic = 0xfe98;
16450 t.tehmeeminitialarabic = 0xfca4;
16451 t.tehmeemisolatedarabic = 0xfc0e;
16452 t.tehnoonfinalarabic = 0xfc73;
16453 t.tekatakana = 0x30c6;
16454 t.tekatakanahalfwidth = 0xff83;
16455 t.telephone = 0x2121;
16456 t.telephoneblack = 0x260e;
16457 t.telishagedolahebrew = 0x05a0;
16458 t.telishaqetanahebrew = 0x05a9;
16459 t.tencircle = 0x2469;
16460 t.tenideographicparen = 0x3229;
16461 t.tenparen = 0x247d;
16462 t.tenperiod = 0x2491;
16463 t.tenroman = 0x2179;
16464 t.tesh = 0x02a7;
16465 t.tet = 0x05d8;
16466 t.tetdagesh = 0xfb38;
16467 t.tetdageshhebrew = 0xfb38;
16468 t.tethebrew = 0x05d8;
16469 t.tetsecyrillic = 0x04b5;
16470 t.tevirhebrew = 0x059b;
16471 t.tevirlefthebrew = 0x059b;
16472 t.thabengali = 0x09a5;
16473 t.thadeva = 0x0925;
16474 t.thagujarati = 0x0aa5;
16475 t.thagurmukhi = 0x0a25;
16476 t.thalarabic = 0x0630;
16477 t.thalfinalarabic = 0xfeac;
16478 t.thanthakhatlowleftthai = 0xf898;
16479 t.thanthakhatlowrightthai = 0xf897;
16480 t.thanthakhatthai = 0x0e4c;
16481 t.thanthakhatupperleftthai = 0xf896;
16482 t.theharabic = 0x062b;
16483 t.thehfinalarabic = 0xfe9a;
16484 t.thehinitialarabic = 0xfe9b;
16485 t.thehmedialarabic = 0xfe9c;
16486 t.thereexists = 0x2203;
16487 t.therefore = 0x2234;
16488 t.theta = 0x03b8;
16489 t.theta1 = 0x03d1;
16490 t.thetasymbolgreek = 0x03d1;
16491 t.thieuthacirclekorean = 0x3279;
16492 t.thieuthaparenkorean = 0x3219;
16493 t.thieuthcirclekorean = 0x326b;
16494 t.thieuthkorean = 0x314c;
16495 t.thieuthparenkorean = 0x320b;
16496 t.thirteencircle = 0x246c;
16497 t.thirteenparen = 0x2480;
16498 t.thirteenperiod = 0x2494;
16499 t.thonangmonthothai = 0x0e11;
16500 t.thook = 0x01ad;
16501 t.thophuthaothai = 0x0e12;
16502 t.thorn = 0x00fe;
16503 t.thothahanthai = 0x0e17;
16504 t.thothanthai = 0x0e10;
16505 t.thothongthai = 0x0e18;
16506 t.thothungthai = 0x0e16;
16507 t.thousandcyrillic = 0x0482;
16508 t.thousandsseparatorarabic = 0x066c;
16509 t.thousandsseparatorpersian = 0x066c;
16510 t.three = 0x0033;
16511 t.threearabic = 0x0663;
16512 t.threebengali = 0x09e9;
16513 t.threecircle = 0x2462;
16514 t.threecircleinversesansserif = 0x278c;
16515 t.threedeva = 0x0969;
16516 t.threeeighths = 0x215c;
16517 t.threegujarati = 0x0ae9;
16518 t.threegurmukhi = 0x0a69;
16519 t.threehackarabic = 0x0663;
16520 t.threehangzhou = 0x3023;
16521 t.threeideographicparen = 0x3222;
16522 t.threeinferior = 0x2083;
16523 t.threemonospace = 0xff13;
16524 t.threenumeratorbengali = 0x09f6;
16525 t.threeoldstyle = 0xf733;
16526 t.threeparen = 0x2476;
16527 t.threeperiod = 0x248a;
16528 t.threepersian = 0x06f3;
16529 t.threequarters = 0x00be;
16530 t.threequartersemdash = 0xf6de;
16531 t.threeroman = 0x2172;
16532 t.threesuperior = 0x00b3;
16533 t.threethai = 0x0e53;
16534 t.thzsquare = 0x3394;
16535 t.tihiragana = 0x3061;
16536 t.tikatakana = 0x30c1;
16537 t.tikatakanahalfwidth = 0xff81;
16538 t.tikeutacirclekorean = 0x3270;
16539 t.tikeutaparenkorean = 0x3210;
16540 t.tikeutcirclekorean = 0x3262;
16541 t.tikeutkorean = 0x3137;
16542 t.tikeutparenkorean = 0x3202;
16543 t.tilde = 0x02dc;
16544 t.tildebelowcmb = 0x0330;
16545 t.tildecmb = 0x0303;
16546 t.tildecomb = 0x0303;
16547 t.tildedoublecmb = 0x0360;
16548 t.tildeoperator = 0x223c;
16549 t.tildeoverlaycmb = 0x0334;
16550 t.tildeverticalcmb = 0x033e;
16551 t.timescircle = 0x2297;
16552 t.tipehahebrew = 0x0596;
16553 t.tipehalefthebrew = 0x0596;
16554 t.tippigurmukhi = 0x0a70;
16555 t.titlocyrilliccmb = 0x0483;
16556 t.tiwnarmenian = 0x057f;
16557 t.tlinebelow = 0x1e6f;
16558 t.tmonospace = 0xff54;
16559 t.toarmenian = 0x0569;
16560 t.tohiragana = 0x3068;
16561 t.tokatakana = 0x30c8;
16562 t.tokatakanahalfwidth = 0xff84;
16563 t.tonebarextrahighmod = 0x02e5;
16564 t.tonebarextralowmod = 0x02e9;
16565 t.tonebarhighmod = 0x02e6;
16566 t.tonebarlowmod = 0x02e8;
16567 t.tonebarmidmod = 0x02e7;
16568 t.tonefive = 0x01bd;
16569 t.tonesix = 0x0185;
16570 t.tonetwo = 0x01a8;
16571 t.tonos = 0x0384;
16572 t.tonsquare = 0x3327;
16573 t.topatakthai = 0x0e0f;
16574 t.tortoiseshellbracketleft = 0x3014;
16575 t.tortoiseshellbracketleftsmall = 0xfe5d;
16576 t.tortoiseshellbracketleftvertical = 0xfe39;
16577 t.tortoiseshellbracketright = 0x3015;
16578 t.tortoiseshellbracketrightsmall = 0xfe5e;
16579 t.tortoiseshellbracketrightvertical = 0xfe3a;
16580 t.totaothai = 0x0e15;
16581 t.tpalatalhook = 0x01ab;
16582 t.tparen = 0x24af;
16583 t.trademark = 0x2122;
16584 t.trademarksans = 0xf8ea;
16585 t.trademarkserif = 0xf6db;
16586 t.tretroflexhook = 0x0288;
16587 t.triagdn = 0x25bc;
16588 t.triaglf = 0x25c4;
16589 t.triagrt = 0x25ba;
16590 t.triagup = 0x25b2;
16591 t.ts = 0x02a6;
16592 t.tsadi = 0x05e6;
16593 t.tsadidagesh = 0xfb46;
16594 t.tsadidageshhebrew = 0xfb46;
16595 t.tsadihebrew = 0x05e6;
16596 t.tsecyrillic = 0x0446;
16597 t.tsere = 0x05b5;
16598 t.tsere12 = 0x05b5;
16599 t.tsere1e = 0x05b5;
16600 t.tsere2b = 0x05b5;
16601 t.tserehebrew = 0x05b5;
16602 t.tserenarrowhebrew = 0x05b5;
16603 t.tserequarterhebrew = 0x05b5;
16604 t.tserewidehebrew = 0x05b5;
16605 t.tshecyrillic = 0x045b;
16606 t.tsuperior = 0xf6f3;
16607 t.ttabengali = 0x099f;
16608 t.ttadeva = 0x091f;
16609 t.ttagujarati = 0x0a9f;
16610 t.ttagurmukhi = 0x0a1f;
16611 t.tteharabic = 0x0679;
16612 t.ttehfinalarabic = 0xfb67;
16613 t.ttehinitialarabic = 0xfb68;
16614 t.ttehmedialarabic = 0xfb69;
16615 t.tthabengali = 0x09a0;
16616 t.tthadeva = 0x0920;
16617 t.tthagujarati = 0x0aa0;
16618 t.tthagurmukhi = 0x0a20;
16619 t.tturned = 0x0287;
16620 t.tuhiragana = 0x3064;
16621 t.tukatakana = 0x30c4;
16622 t.tukatakanahalfwidth = 0xff82;
16623 t.tusmallhiragana = 0x3063;
16624 t.tusmallkatakana = 0x30c3;
16625 t.tusmallkatakanahalfwidth = 0xff6f;
16626 t.twelvecircle = 0x246b;
16627 t.twelveparen = 0x247f;
16628 t.twelveperiod = 0x2493;
16629 t.twelveroman = 0x217b;
16630 t.twentycircle = 0x2473;
16631 t.twentyhangzhou = 0x5344;
16632 t.twentyparen = 0x2487;
16633 t.twentyperiod = 0x249b;
16634 t.two = 0x0032;
16635 t.twoarabic = 0x0662;
16636 t.twobengali = 0x09e8;
16637 t.twocircle = 0x2461;
16638 t.twocircleinversesansserif = 0x278b;
16639 t.twodeva = 0x0968;
16640 t.twodotenleader = 0x2025;
16641 t.twodotleader = 0x2025;
16642 t.twodotleadervertical = 0xfe30;
16643 t.twogujarati = 0x0ae8;
16644 t.twogurmukhi = 0x0a68;
16645 t.twohackarabic = 0x0662;
16646 t.twohangzhou = 0x3022;
16647 t.twoideographicparen = 0x3221;
16648 t.twoinferior = 0x2082;
16649 t.twomonospace = 0xff12;
16650 t.twonumeratorbengali = 0x09f5;
16651 t.twooldstyle = 0xf732;
16652 t.twoparen = 0x2475;
16653 t.twoperiod = 0x2489;
16654 t.twopersian = 0x06f2;
16655 t.tworoman = 0x2171;
16656 t.twostroke = 0x01bb;
16657 t.twosuperior = 0x00b2;
16658 t.twothai = 0x0e52;
16659 t.twothirds = 0x2154;
16660 t.u = 0x0075;
16661 t.uacute = 0x00fa;
16662 t.ubar = 0x0289;
16663 t.ubengali = 0x0989;
16664 t.ubopomofo = 0x3128;
16665 t.ubreve = 0x016d;
16666 t.ucaron = 0x01d4;
16667 t.ucircle = 0x24e4;
16668 t.ucircumflex = 0x00fb;
16669 t.ucircumflexbelow = 0x1e77;
16670 t.ucyrillic = 0x0443;
16671 t.udattadeva = 0x0951;
16672 t.udblacute = 0x0171;
16673 t.udblgrave = 0x0215;
16674 t.udeva = 0x0909;
16675 t.udieresis = 0x00fc;
16676 t.udieresisacute = 0x01d8;
16677 t.udieresisbelow = 0x1e73;
16678 t.udieresiscaron = 0x01da;
16679 t.udieresiscyrillic = 0x04f1;
16680 t.udieresisgrave = 0x01dc;
16681 t.udieresismacron = 0x01d6;
16682 t.udotbelow = 0x1ee5;
16683 t.ugrave = 0x00f9;
16684 t.ugujarati = 0x0a89;
16685 t.ugurmukhi = 0x0a09;
16686 t.uhiragana = 0x3046;
16687 t.uhookabove = 0x1ee7;
16688 t.uhorn = 0x01b0;
16689 t.uhornacute = 0x1ee9;
16690 t.uhorndotbelow = 0x1ef1;
16691 t.uhorngrave = 0x1eeb;
16692 t.uhornhookabove = 0x1eed;
16693 t.uhorntilde = 0x1eef;
16694 t.uhungarumlaut = 0x0171;
16695 t.uhungarumlautcyrillic = 0x04f3;
16696 t.uinvertedbreve = 0x0217;
16697 t.ukatakana = 0x30a6;
16698 t.ukatakanahalfwidth = 0xff73;
16699 t.ukcyrillic = 0x0479;
16700 t.ukorean = 0x315c;
16701 t.umacron = 0x016b;
16702 t.umacroncyrillic = 0x04ef;
16703 t.umacrondieresis = 0x1e7b;
16704 t.umatragurmukhi = 0x0a41;
16705 t.umonospace = 0xff55;
16706 t.underscore = 0x005f;
16707 t.underscoredbl = 0x2017;
16708 t.underscoremonospace = 0xff3f;
16709 t.underscorevertical = 0xfe33;
16710 t.underscorewavy = 0xfe4f;
16711 t.union = 0x222a;
16712 t.universal = 0x2200;
16713 t.uogonek = 0x0173;
16714 t.uparen = 0x24b0;
16715 t.upblock = 0x2580;
16716 t.upperdothebrew = 0x05c4;
16717 t.upsilon = 0x03c5;
16718 t.upsilondieresis = 0x03cb;
16719 t.upsilondieresistonos = 0x03b0;
16720 t.upsilonlatin = 0x028a;
16721 t.upsilontonos = 0x03cd;
16722 t.uptackbelowcmb = 0x031d;
16723 t.uptackmod = 0x02d4;
16724 t.uragurmukhi = 0x0a73;
16725 t.uring = 0x016f;
16726 t.ushortcyrillic = 0x045e;
16727 t.usmallhiragana = 0x3045;
16728 t.usmallkatakana = 0x30a5;
16729 t.usmallkatakanahalfwidth = 0xff69;
16730 t.ustraightcyrillic = 0x04af;
16731 t.ustraightstrokecyrillic = 0x04b1;
16732 t.utilde = 0x0169;
16733 t.utildeacute = 0x1e79;
16734 t.utildebelow = 0x1e75;
16735 t.uubengali = 0x098a;
16736 t.uudeva = 0x090a;
16737 t.uugujarati = 0x0a8a;
16738 t.uugurmukhi = 0x0a0a;
16739 t.uumatragurmukhi = 0x0a42;
16740 t.uuvowelsignbengali = 0x09c2;
16741 t.uuvowelsigndeva = 0x0942;
16742 t.uuvowelsigngujarati = 0x0ac2;
16743 t.uvowelsignbengali = 0x09c1;
16744 t.uvowelsigndeva = 0x0941;
16745 t.uvowelsigngujarati = 0x0ac1;
16746 t.v = 0x0076;
16747 t.vadeva = 0x0935;
16748 t.vagujarati = 0x0ab5;
16749 t.vagurmukhi = 0x0a35;
16750 t.vakatakana = 0x30f7;
16751 t.vav = 0x05d5;
16752 t.vavdagesh = 0xfb35;
16753 t.vavdagesh65 = 0xfb35;
16754 t.vavdageshhebrew = 0xfb35;
16755 t.vavhebrew = 0x05d5;
16756 t.vavholam = 0xfb4b;
16757 t.vavholamhebrew = 0xfb4b;
16758 t.vavvavhebrew = 0x05f0;
16759 t.vavyodhebrew = 0x05f1;
16760 t.vcircle = 0x24e5;
16761 t.vdotbelow = 0x1e7f;
16762 t.vecyrillic = 0x0432;
16763 t.veharabic = 0x06a4;
16764 t.vehfinalarabic = 0xfb6b;
16765 t.vehinitialarabic = 0xfb6c;
16766 t.vehmedialarabic = 0xfb6d;
16767 t.vekatakana = 0x30f9;
16768 t.venus = 0x2640;
16769 t.verticalbar = 0x007c;
16770 t.verticallineabovecmb = 0x030d;
16771 t.verticallinebelowcmb = 0x0329;
16772 t.verticallinelowmod = 0x02cc;
16773 t.verticallinemod = 0x02c8;
16774 t.vewarmenian = 0x057e;
16775 t.vhook = 0x028b;
16776 t.vikatakana = 0x30f8;
16777 t.viramabengali = 0x09cd;
16778 t.viramadeva = 0x094d;
16779 t.viramagujarati = 0x0acd;
16780 t.visargabengali = 0x0983;
16781 t.visargadeva = 0x0903;
16782 t.visargagujarati = 0x0a83;
16783 t.vmonospace = 0xff56;
16784 t.voarmenian = 0x0578;
16785 t.voicediterationhiragana = 0x309e;
16786 t.voicediterationkatakana = 0x30fe;
16787 t.voicedmarkkana = 0x309b;
16788 t.voicedmarkkanahalfwidth = 0xff9e;
16789 t.vokatakana = 0x30fa;
16790 t.vparen = 0x24b1;
16791 t.vtilde = 0x1e7d;
16792 t.vturned = 0x028c;
16793 t.vuhiragana = 0x3094;
16794 t.vukatakana = 0x30f4;
16795 t.w = 0x0077;
16796 t.wacute = 0x1e83;
16797 t.waekorean = 0x3159;
16798 t.wahiragana = 0x308f;
16799 t.wakatakana = 0x30ef;
16800 t.wakatakanahalfwidth = 0xff9c;
16801 t.wakorean = 0x3158;
16802 t.wasmallhiragana = 0x308e;
16803 t.wasmallkatakana = 0x30ee;
16804 t.wattosquare = 0x3357;
16805 t.wavedash = 0x301c;
16806 t.wavyunderscorevertical = 0xfe34;
16807 t.wawarabic = 0x0648;
16808 t.wawfinalarabic = 0xfeee;
16809 t.wawhamzaabovearabic = 0x0624;
16810 t.wawhamzaabovefinalarabic = 0xfe86;
16811 t.wbsquare = 0x33dd;
16812 t.wcircle = 0x24e6;
16813 t.wcircumflex = 0x0175;
16814 t.wdieresis = 0x1e85;
16815 t.wdotaccent = 0x1e87;
16816 t.wdotbelow = 0x1e89;
16817 t.wehiragana = 0x3091;
16818 t.weierstrass = 0x2118;
16819 t.wekatakana = 0x30f1;
16820 t.wekorean = 0x315e;
16821 t.weokorean = 0x315d;
16822 t.wgrave = 0x1e81;
16823 t.whitebullet = 0x25e6;
16824 t.whitecircle = 0x25cb;
16825 t.whitecircleinverse = 0x25d9;
16826 t.whitecornerbracketleft = 0x300e;
16827 t.whitecornerbracketleftvertical = 0xfe43;
16828 t.whitecornerbracketright = 0x300f;
16829 t.whitecornerbracketrightvertical = 0xfe44;
16830 t.whitediamond = 0x25c7;
16831 t.whitediamondcontainingblacksmalldiamond = 0x25c8;
16832 t.whitedownpointingsmalltriangle = 0x25bf;
16833 t.whitedownpointingtriangle = 0x25bd;
16834 t.whiteleftpointingsmalltriangle = 0x25c3;
16835 t.whiteleftpointingtriangle = 0x25c1;
16836 t.whitelenticularbracketleft = 0x3016;
16837 t.whitelenticularbracketright = 0x3017;
16838 t.whiterightpointingsmalltriangle = 0x25b9;
16839 t.whiterightpointingtriangle = 0x25b7;
16840 t.whitesmallsquare = 0x25ab;
16841 t.whitesmilingface = 0x263a;
16842 t.whitesquare = 0x25a1;
16843 t.whitestar = 0x2606;
16844 t.whitetelephone = 0x260f;
16845 t.whitetortoiseshellbracketleft = 0x3018;
16846 t.whitetortoiseshellbracketright = 0x3019;
16847 t.whiteuppointingsmalltriangle = 0x25b5;
16848 t.whiteuppointingtriangle = 0x25b3;
16849 t.wihiragana = 0x3090;
16850 t.wikatakana = 0x30f0;
16851 t.wikorean = 0x315f;
16852 t.wmonospace = 0xff57;
16853 t.wohiragana = 0x3092;
16854 t.wokatakana = 0x30f2;
16855 t.wokatakanahalfwidth = 0xff66;
16856 t.won = 0x20a9;
16857 t.wonmonospace = 0xffe6;
16858 t.wowaenthai = 0x0e27;
16859 t.wparen = 0x24b2;
16860 t.wring = 0x1e98;
16861 t.wsuperior = 0x02b7;
16862 t.wturned = 0x028d;
16863 t.wynn = 0x01bf;
16864 t.x = 0x0078;
16865 t.xabovecmb = 0x033d;
16866 t.xbopomofo = 0x3112;
16867 t.xcircle = 0x24e7;
16868 t.xdieresis = 0x1e8d;
16869 t.xdotaccent = 0x1e8b;
16870 t.xeharmenian = 0x056d;
16871 t.xi = 0x03be;
16872 t.xmonospace = 0xff58;
16873 t.xparen = 0x24b3;
16874 t.xsuperior = 0x02e3;
16875 t.y = 0x0079;
16876 t.yaadosquare = 0x334e;
16877 t.yabengali = 0x09af;
16878 t.yacute = 0x00fd;
16879 t.yadeva = 0x092f;
16880 t.yaekorean = 0x3152;
16881 t.yagujarati = 0x0aaf;
16882 t.yagurmukhi = 0x0a2f;
16883 t.yahiragana = 0x3084;
16884 t.yakatakana = 0x30e4;
16885 t.yakatakanahalfwidth = 0xff94;
16886 t.yakorean = 0x3151;
16887 t.yamakkanthai = 0x0e4e;
16888 t.yasmallhiragana = 0x3083;
16889 t.yasmallkatakana = 0x30e3;
16890 t.yasmallkatakanahalfwidth = 0xff6c;
16891 t.yatcyrillic = 0x0463;
16892 t.ycircle = 0x24e8;
16893 t.ycircumflex = 0x0177;
16894 t.ydieresis = 0x00ff;
16895 t.ydotaccent = 0x1e8f;
16896 t.ydotbelow = 0x1ef5;
16897 t.yeharabic = 0x064a;
16898 t.yehbarreearabic = 0x06d2;
16899 t.yehbarreefinalarabic = 0xfbaf;
16900 t.yehfinalarabic = 0xfef2;
16901 t.yehhamzaabovearabic = 0x0626;
16902 t.yehhamzaabovefinalarabic = 0xfe8a;
16903 t.yehhamzaaboveinitialarabic = 0xfe8b;
16904 t.yehhamzaabovemedialarabic = 0xfe8c;
16905 t.yehinitialarabic = 0xfef3;
16906 t.yehmedialarabic = 0xfef4;
16907 t.yehmeeminitialarabic = 0xfcdd;
16908 t.yehmeemisolatedarabic = 0xfc58;
16909 t.yehnoonfinalarabic = 0xfc94;
16910 t.yehthreedotsbelowarabic = 0x06d1;
16911 t.yekorean = 0x3156;
16912 t.yen = 0x00a5;
16913 t.yenmonospace = 0xffe5;
16914 t.yeokorean = 0x3155;
16915 t.yeorinhieuhkorean = 0x3186;
16916 t.yerahbenyomohebrew = 0x05aa;
16917 t.yerahbenyomolefthebrew = 0x05aa;
16918 t.yericyrillic = 0x044b;
16919 t.yerudieresiscyrillic = 0x04f9;
16920 t.yesieungkorean = 0x3181;
16921 t.yesieungpansioskorean = 0x3183;
16922 t.yesieungsioskorean = 0x3182;
16923 t.yetivhebrew = 0x059a;
16924 t.ygrave = 0x1ef3;
16925 t.yhook = 0x01b4;
16926 t.yhookabove = 0x1ef7;
16927 t.yiarmenian = 0x0575;
16928 t.yicyrillic = 0x0457;
16929 t.yikorean = 0x3162;
16930 t.yinyang = 0x262f;
16931 t.yiwnarmenian = 0x0582;
16932 t.ymonospace = 0xff59;
16933 t.yod = 0x05d9;
16934 t.yoddagesh = 0xfb39;
16935 t.yoddageshhebrew = 0xfb39;
16936 t.yodhebrew = 0x05d9;
16937 t.yodyodhebrew = 0x05f2;
16938 t.yodyodpatahhebrew = 0xfb1f;
16939 t.yohiragana = 0x3088;
16940 t.yoikorean = 0x3189;
16941 t.yokatakana = 0x30e8;
16942 t.yokatakanahalfwidth = 0xff96;
16943 t.yokorean = 0x315b;
16944 t.yosmallhiragana = 0x3087;
16945 t.yosmallkatakana = 0x30e7;
16946 t.yosmallkatakanahalfwidth = 0xff6e;
16947 t.yotgreek = 0x03f3;
16948 t.yoyaekorean = 0x3188;
16949 t.yoyakorean = 0x3187;
16950 t.yoyakthai = 0x0e22;
16951 t.yoyingthai = 0x0e0d;
16952 t.yparen = 0x24b4;
16953 t.ypogegrammeni = 0x037a;
16954 t.ypogegrammenigreekcmb = 0x0345;
16955 t.yr = 0x01a6;
16956 t.yring = 0x1e99;
16957 t.ysuperior = 0x02b8;
16958 t.ytilde = 0x1ef9;
16959 t.yturned = 0x028e;
16960 t.yuhiragana = 0x3086;
16961 t.yuikorean = 0x318c;
16962 t.yukatakana = 0x30e6;
16963 t.yukatakanahalfwidth = 0xff95;
16964 t.yukorean = 0x3160;
16965 t.yusbigcyrillic = 0x046b;
16966 t.yusbigiotifiedcyrillic = 0x046d;
16967 t.yuslittlecyrillic = 0x0467;
16968 t.yuslittleiotifiedcyrillic = 0x0469;
16969 t.yusmallhiragana = 0x3085;
16970 t.yusmallkatakana = 0x30e5;
16971 t.yusmallkatakanahalfwidth = 0xff6d;
16972 t.yuyekorean = 0x318b;
16973 t.yuyeokorean = 0x318a;
16974 t.yyabengali = 0x09df;
16975 t.yyadeva = 0x095f;
16976 t.z = 0x007a;
16977 t.zaarmenian = 0x0566;
16978 t.zacute = 0x017a;
16979 t.zadeva = 0x095b;
16980 t.zagurmukhi = 0x0a5b;
16981 t.zaharabic = 0x0638;
16982 t.zahfinalarabic = 0xfec6;
16983 t.zahinitialarabic = 0xfec7;
16984 t.zahiragana = 0x3056;
16985 t.zahmedialarabic = 0xfec8;
16986 t.zainarabic = 0x0632;
16987 t.zainfinalarabic = 0xfeb0;
16988 t.zakatakana = 0x30b6;
16989 t.zaqefgadolhebrew = 0x0595;
16990 t.zaqefqatanhebrew = 0x0594;
16991 t.zarqahebrew = 0x0598;
16992 t.zayin = 0x05d6;
16993 t.zayindagesh = 0xfb36;
16994 t.zayindageshhebrew = 0xfb36;
16995 t.zayinhebrew = 0x05d6;
16996 t.zbopomofo = 0x3117;
16997 t.zcaron = 0x017e;
16998 t.zcircle = 0x24e9;
16999 t.zcircumflex = 0x1e91;
17000 t.zcurl = 0x0291;
17001 t.zdot = 0x017c;
17002 t.zdotaccent = 0x017c;
17003 t.zdotbelow = 0x1e93;
17004 t.zecyrillic = 0x0437;
17005 t.zedescendercyrillic = 0x0499;
17006 t.zedieresiscyrillic = 0x04df;
17007 t.zehiragana = 0x305c;
17008 t.zekatakana = 0x30bc;
17009 t.zero = 0x0030;
17010 t.zeroarabic = 0x0660;
17011 t.zerobengali = 0x09e6;
17012 t.zerodeva = 0x0966;
17013 t.zerogujarati = 0x0ae6;
17014 t.zerogurmukhi = 0x0a66;
17015 t.zerohackarabic = 0x0660;
17016 t.zeroinferior = 0x2080;
17017 t.zeromonospace = 0xff10;
17018 t.zerooldstyle = 0xf730;
17019 t.zeropersian = 0x06f0;
17020 t.zerosuperior = 0x2070;
17021 t.zerothai = 0x0e50;
17022 t.zerowidthjoiner = 0xfeff;
17023 t.zerowidthnonjoiner = 0x200c;
17024 t.zerowidthspace = 0x200b;
17025 t.zeta = 0x03b6;
17026 t.zhbopomofo = 0x3113;
17027 t.zhearmenian = 0x056a;
17028 t.zhebrevecyrillic = 0x04c2;
17029 t.zhecyrillic = 0x0436;
17030 t.zhedescendercyrillic = 0x0497;
17031 t.zhedieresiscyrillic = 0x04dd;
17032 t.zihiragana = 0x3058;
17033 t.zikatakana = 0x30b8;
17034 t.zinorhebrew = 0x05ae;
17035 t.zlinebelow = 0x1e95;
17036 t.zmonospace = 0xff5a;
17037 t.zohiragana = 0x305e;
17038 t.zokatakana = 0x30be;
17039 t.zparen = 0x24b5;
17040 t.zretroflexhook = 0x0290;
17041 t.zstroke = 0x01b6;
17042 t.zuhiragana = 0x305a;
17043 t.zukatakana = 0x30ba;
17044 t[".notdef"] = 0x0000;
17045 t.angbracketleftbig = 0x2329;
17046 t.angbracketleftBig = 0x2329;
17047 t.angbracketleftbigg = 0x2329;
17048 t.angbracketleftBigg = 0x2329;
17049 t.angbracketrightBig = 0x232a;
17050 t.angbracketrightbig = 0x232a;
17051 t.angbracketrightBigg = 0x232a;
17052 t.angbracketrightbigg = 0x232a;
17053 t.arrowhookleft = 0x21aa;
17054 t.arrowhookright = 0x21a9;
17055 t.arrowlefttophalf = 0x21bc;
17056 t.arrowleftbothalf = 0x21bd;
17057 t.arrownortheast = 0x2197;
17058 t.arrownorthwest = 0x2196;
17059 t.arrowrighttophalf = 0x21c0;
17060 t.arrowrightbothalf = 0x21c1;
17061 t.arrowsoutheast = 0x2198;
17062 t.arrowsouthwest = 0x2199;
17063 t.backslashbig = 0x2216;
17064 t.backslashBig = 0x2216;
17065 t.backslashBigg = 0x2216;
17066 t.backslashbigg = 0x2216;
17067 t.bardbl = 0x2016;
17068 t.bracehtipdownleft = 0xfe37;
17069 t.bracehtipdownright = 0xfe37;
17070 t.bracehtipupleft = 0xfe38;
17071 t.bracehtipupright = 0xfe38;
17072 t.braceleftBig = 0x007b;
17073 t.braceleftbig = 0x007b;
17074 t.braceleftbigg = 0x007b;
17075 t.braceleftBigg = 0x007b;
17076 t.bracerightBig = 0x007d;
17077 t.bracerightbig = 0x007d;
17078 t.bracerightbigg = 0x007d;
17079 t.bracerightBigg = 0x007d;
17080 t.bracketleftbig = 0x005b;
17081 t.bracketleftBig = 0x005b;
17082 t.bracketleftbigg = 0x005b;
17083 t.bracketleftBigg = 0x005b;
17084 t.bracketrightBig = 0x005d;
17085 t.bracketrightbig = 0x005d;
17086 t.bracketrightbigg = 0x005d;
17087 t.bracketrightBigg = 0x005d;
17088 t.ceilingleftbig = 0x2308;
17089 t.ceilingleftBig = 0x2308;
17090 t.ceilingleftBigg = 0x2308;
17091 t.ceilingleftbigg = 0x2308;
17092 t.ceilingrightbig = 0x2309;
17093 t.ceilingrightBig = 0x2309;
17094 t.ceilingrightbigg = 0x2309;
17095 t.ceilingrightBigg = 0x2309;
17096 t.circledotdisplay = 0x2299;
17097 t.circledottext = 0x2299;
17098 t.circlemultiplydisplay = 0x2297;
17099 t.circlemultiplytext = 0x2297;
17100 t.circleplusdisplay = 0x2295;
17101 t.circleplustext = 0x2295;
17102 t.contintegraldisplay = 0x222e;
17103 t.contintegraltext = 0x222e;
17104 t.coproductdisplay = 0x2210;
17105 t.coproducttext = 0x2210;
17106 t.floorleftBig = 0x230a;
17107 t.floorleftbig = 0x230a;
17108 t.floorleftbigg = 0x230a;
17109 t.floorleftBigg = 0x230a;
17110 t.floorrightbig = 0x230b;
17111 t.floorrightBig = 0x230b;
17112 t.floorrightBigg = 0x230b;
17113 t.floorrightbigg = 0x230b;
17114 t.hatwide = 0x0302;
17115 t.hatwider = 0x0302;
17116 t.hatwidest = 0x0302;
17117 t.intercal = 0x1d40;
17118 t.integraldisplay = 0x222b;
17119 t.integraltext = 0x222b;
17120 t.intersectiondisplay = 0x22c2;
17121 t.intersectiontext = 0x22c2;
17122 t.logicalanddisplay = 0x2227;
17123 t.logicalandtext = 0x2227;
17124 t.logicalordisplay = 0x2228;
17125 t.logicalortext = 0x2228;
17126 t.parenleftBig = 0x0028;
17127 t.parenleftbig = 0x0028;
17128 t.parenleftBigg = 0x0028;
17129 t.parenleftbigg = 0x0028;
17130 t.parenrightBig = 0x0029;
17131 t.parenrightbig = 0x0029;
17132 t.parenrightBigg = 0x0029;
17133 t.parenrightbigg = 0x0029;
17134 t.prime = 0x2032;
17135 t.productdisplay = 0x220f;
17136 t.producttext = 0x220f;
17137 t.radicalbig = 0x221a;
17138 t.radicalBig = 0x221a;
17139 t.radicalBigg = 0x221a;
17140 t.radicalbigg = 0x221a;
17141 t.radicalbt = 0x221a;
17142 t.radicaltp = 0x221a;
17143 t.radicalvertex = 0x221a;
17144 t.slashbig = 0x002f;
17145 t.slashBig = 0x002f;
17146 t.slashBigg = 0x002f;
17147 t.slashbigg = 0x002f;
17148 t.summationdisplay = 0x2211;
17149 t.summationtext = 0x2211;
17150 t.tildewide = 0x02dc;
17151 t.tildewider = 0x02dc;
17152 t.tildewidest = 0x02dc;
17153 t.uniondisplay = 0x22c3;
17154 t.unionmultidisplay = 0x228e;
17155 t.unionmultitext = 0x228e;
17156 t.unionsqdisplay = 0x2294;
17157 t.unionsqtext = 0x2294;
17158 t.uniontext = 0x22c3;
17159 t.vextenddouble = 0x2225;
17160 t.vextendsingle = 0x2223;
17161});
17162const getDingbatsGlyphsUnicode = getLookupTableFactory(function (t) {
17163 t.space = 0x0020;
17164 t.a1 = 0x2701;
17165 t.a2 = 0x2702;
17166 t.a202 = 0x2703;
17167 t.a3 = 0x2704;
17168 t.a4 = 0x260e;
17169 t.a5 = 0x2706;
17170 t.a119 = 0x2707;
17171 t.a118 = 0x2708;
17172 t.a117 = 0x2709;
17173 t.a11 = 0x261b;
17174 t.a12 = 0x261e;
17175 t.a13 = 0x270c;
17176 t.a14 = 0x270d;
17177 t.a15 = 0x270e;
17178 t.a16 = 0x270f;
17179 t.a105 = 0x2710;
17180 t.a17 = 0x2711;
17181 t.a18 = 0x2712;
17182 t.a19 = 0x2713;
17183 t.a20 = 0x2714;
17184 t.a21 = 0x2715;
17185 t.a22 = 0x2716;
17186 t.a23 = 0x2717;
17187 t.a24 = 0x2718;
17188 t.a25 = 0x2719;
17189 t.a26 = 0x271a;
17190 t.a27 = 0x271b;
17191 t.a28 = 0x271c;
17192 t.a6 = 0x271d;
17193 t.a7 = 0x271e;
17194 t.a8 = 0x271f;
17195 t.a9 = 0x2720;
17196 t.a10 = 0x2721;
17197 t.a29 = 0x2722;
17198 t.a30 = 0x2723;
17199 t.a31 = 0x2724;
17200 t.a32 = 0x2725;
17201 t.a33 = 0x2726;
17202 t.a34 = 0x2727;
17203 t.a35 = 0x2605;
17204 t.a36 = 0x2729;
17205 t.a37 = 0x272a;
17206 t.a38 = 0x272b;
17207 t.a39 = 0x272c;
17208 t.a40 = 0x272d;
17209 t.a41 = 0x272e;
17210 t.a42 = 0x272f;
17211 t.a43 = 0x2730;
17212 t.a44 = 0x2731;
17213 t.a45 = 0x2732;
17214 t.a46 = 0x2733;
17215 t.a47 = 0x2734;
17216 t.a48 = 0x2735;
17217 t.a49 = 0x2736;
17218 t.a50 = 0x2737;
17219 t.a51 = 0x2738;
17220 t.a52 = 0x2739;
17221 t.a53 = 0x273a;
17222 t.a54 = 0x273b;
17223 t.a55 = 0x273c;
17224 t.a56 = 0x273d;
17225 t.a57 = 0x273e;
17226 t.a58 = 0x273f;
17227 t.a59 = 0x2740;
17228 t.a60 = 0x2741;
17229 t.a61 = 0x2742;
17230 t.a62 = 0x2743;
17231 t.a63 = 0x2744;
17232 t.a64 = 0x2745;
17233 t.a65 = 0x2746;
17234 t.a66 = 0x2747;
17235 t.a67 = 0x2748;
17236 t.a68 = 0x2749;
17237 t.a69 = 0x274a;
17238 t.a70 = 0x274b;
17239 t.a71 = 0x25cf;
17240 t.a72 = 0x274d;
17241 t.a73 = 0x25a0;
17242 t.a74 = 0x274f;
17243 t.a203 = 0x2750;
17244 t.a75 = 0x2751;
17245 t.a204 = 0x2752;
17246 t.a76 = 0x25b2;
17247 t.a77 = 0x25bc;
17248 t.a78 = 0x25c6;
17249 t.a79 = 0x2756;
17250 t.a81 = 0x25d7;
17251 t.a82 = 0x2758;
17252 t.a83 = 0x2759;
17253 t.a84 = 0x275a;
17254 t.a97 = 0x275b;
17255 t.a98 = 0x275c;
17256 t.a99 = 0x275d;
17257 t.a100 = 0x275e;
17258 t.a101 = 0x2761;
17259 t.a102 = 0x2762;
17260 t.a103 = 0x2763;
17261 t.a104 = 0x2764;
17262 t.a106 = 0x2765;
17263 t.a107 = 0x2766;
17264 t.a108 = 0x2767;
17265 t.a112 = 0x2663;
17266 t.a111 = 0x2666;
17267 t.a110 = 0x2665;
17268 t.a109 = 0x2660;
17269 t.a120 = 0x2460;
17270 t.a121 = 0x2461;
17271 t.a122 = 0x2462;
17272 t.a123 = 0x2463;
17273 t.a124 = 0x2464;
17274 t.a125 = 0x2465;
17275 t.a126 = 0x2466;
17276 t.a127 = 0x2467;
17277 t.a128 = 0x2468;
17278 t.a129 = 0x2469;
17279 t.a130 = 0x2776;
17280 t.a131 = 0x2777;
17281 t.a132 = 0x2778;
17282 t.a133 = 0x2779;
17283 t.a134 = 0x277a;
17284 t.a135 = 0x277b;
17285 t.a136 = 0x277c;
17286 t.a137 = 0x277d;
17287 t.a138 = 0x277e;
17288 t.a139 = 0x277f;
17289 t.a140 = 0x2780;
17290 t.a141 = 0x2781;
17291 t.a142 = 0x2782;
17292 t.a143 = 0x2783;
17293 t.a144 = 0x2784;
17294 t.a145 = 0x2785;
17295 t.a146 = 0x2786;
17296 t.a147 = 0x2787;
17297 t.a148 = 0x2788;
17298 t.a149 = 0x2789;
17299 t.a150 = 0x278a;
17300 t.a151 = 0x278b;
17301 t.a152 = 0x278c;
17302 t.a153 = 0x278d;
17303 t.a154 = 0x278e;
17304 t.a155 = 0x278f;
17305 t.a156 = 0x2790;
17306 t.a157 = 0x2791;
17307 t.a158 = 0x2792;
17308 t.a159 = 0x2793;
17309 t.a160 = 0x2794;
17310 t.a161 = 0x2192;
17311 t.a163 = 0x2194;
17312 t.a164 = 0x2195;
17313 t.a196 = 0x2798;
17314 t.a165 = 0x2799;
17315 t.a192 = 0x279a;
17316 t.a166 = 0x279b;
17317 t.a167 = 0x279c;
17318 t.a168 = 0x279d;
17319 t.a169 = 0x279e;
17320 t.a170 = 0x279f;
17321 t.a171 = 0x27a0;
17322 t.a172 = 0x27a1;
17323 t.a173 = 0x27a2;
17324 t.a162 = 0x27a3;
17325 t.a174 = 0x27a4;
17326 t.a175 = 0x27a5;
17327 t.a176 = 0x27a6;
17328 t.a177 = 0x27a7;
17329 t.a178 = 0x27a8;
17330 t.a179 = 0x27a9;
17331 t.a193 = 0x27aa;
17332 t.a180 = 0x27ab;
17333 t.a199 = 0x27ac;
17334 t.a181 = 0x27ad;
17335 t.a200 = 0x27ae;
17336 t.a182 = 0x27af;
17337 t.a201 = 0x27b1;
17338 t.a183 = 0x27b2;
17339 t.a184 = 0x27b3;
17340 t.a197 = 0x27b4;
17341 t.a185 = 0x27b5;
17342 t.a194 = 0x27b6;
17343 t.a198 = 0x27b7;
17344 t.a186 = 0x27b8;
17345 t.a195 = 0x27b9;
17346 t.a187 = 0x27ba;
17347 t.a188 = 0x27bb;
17348 t.a189 = 0x27bc;
17349 t.a190 = 0x27bd;
17350 t.a191 = 0x27be;
17351 t.a89 = 0x2768;
17352 t.a90 = 0x2769;
17353 t.a93 = 0x276a;
17354 t.a94 = 0x276b;
17355 t.a91 = 0x276c;
17356 t.a92 = 0x276d;
17357 t.a205 = 0x276e;
17358 t.a85 = 0x276f;
17359 t.a206 = 0x2770;
17360 t.a86 = 0x2771;
17361 t.a87 = 0x2772;
17362 t.a88 = 0x2773;
17363 t.a95 = 0x2774;
17364 t.a96 = 0x2775;
17365 t[".notdef"] = 0x0000;
17366});
17367
17368;// CONCATENATED MODULE: ./src/core/unicode.js
17369
17370const getSpecialPUASymbols = getLookupTableFactory(function (t) {
17371 t[63721] = 0x00a9;
17372 t[63193] = 0x00a9;
17373 t[63720] = 0x00ae;
17374 t[63194] = 0x00ae;
17375 t[63722] = 0x2122;
17376 t[63195] = 0x2122;
17377 t[63729] = 0x23a7;
17378 t[63730] = 0x23a8;
17379 t[63731] = 0x23a9;
17380 t[63740] = 0x23ab;
17381 t[63741] = 0x23ac;
17382 t[63742] = 0x23ad;
17383 t[63726] = 0x23a1;
17384 t[63727] = 0x23a2;
17385 t[63728] = 0x23a3;
17386 t[63737] = 0x23a4;
17387 t[63738] = 0x23a5;
17388 t[63739] = 0x23a6;
17389 t[63723] = 0x239b;
17390 t[63724] = 0x239c;
17391 t[63725] = 0x239d;
17392 t[63734] = 0x239e;
17393 t[63735] = 0x239f;
17394 t[63736] = 0x23a0;
17395});
17396function mapSpecialUnicodeValues(code) {
17397 if (code >= 0xfff0 && code <= 0xffff) {
17398 return 0;
17399 } else if (code >= 0xf600 && code <= 0xf8ff) {
17400 return getSpecialPUASymbols()[code] || code;
17401 } else if (code === 0x00ad) {
17402 return 0x002d;
17403 }
17404 return code;
17405}
17406function getUnicodeForGlyph(name, glyphsUnicodeMap) {
17407 let unicode = glyphsUnicodeMap[name];
17408 if (unicode !== undefined) {
17409 return unicode;
17410 }
17411 if (!name) {
17412 return -1;
17413 }
17414 if (name[0] === "u") {
17415 const nameLen = name.length;
17416 let hexStr;
17417 if (nameLen === 7 && name[1] === "n" && name[2] === "i") {
17418 hexStr = name.substring(3);
17419 } else if (nameLen >= 5 && nameLen <= 7) {
17420 hexStr = name.substring(1);
17421 } else {
17422 return -1;
17423 }
17424 if (hexStr === hexStr.toUpperCase()) {
17425 unicode = parseInt(hexStr, 16);
17426 if (unicode >= 0) {
17427 return unicode;
17428 }
17429 }
17430 }
17431 return -1;
17432}
17433const 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]];
17434function getUnicodeRangeFor(value, lastPosition = -1) {
17435 if (lastPosition !== -1) {
17436 const range = UnicodeRanges[lastPosition];
17437 for (let i = 0, ii = range.length; i < ii; i += 2) {
17438 if (value >= range[i] && value <= range[i + 1]) {
17439 return lastPosition;
17440 }
17441 }
17442 }
17443 for (let i = 0, ii = UnicodeRanges.length; i < ii; i++) {
17444 const range = UnicodeRanges[i];
17445 for (let j = 0, jj = range.length; j < jj; j += 2) {
17446 if (value >= range[j] && value <= range[j + 1]) {
17447 return i;
17448 }
17449 }
17450 }
17451 return -1;
17452}
17453const SpecialCharRegExp = new RegExp("^(\\s)|(\\p{Mn})|(\\p{Cf})$", "u");
17454const CategoryCache = new Map();
17455function getCharUnicodeCategory(char) {
17456 const cachedCategory = CategoryCache.get(char);
17457 if (cachedCategory) {
17458 return cachedCategory;
17459 }
17460 const groups = char.match(SpecialCharRegExp);
17461 const category = {
17462 isWhitespace: !!groups?.[1],
17463 isZeroWidthDiacritic: !!groups?.[2],
17464 isInvisibleFormatMark: !!groups?.[3]
17465 };
17466 CategoryCache.set(char, category);
17467 return category;
17468}
17469function clearUnicodeCaches() {
17470 CategoryCache.clear();
17471}
17472
17473;// CONCATENATED MODULE: ./src/core/fonts_utils.js
17474
17475
17476
17477
17478const SEAC_ANALYSIS_ENABLED = true;
17479const FontFlags = {
17480 FixedPitch: 1,
17481 Serif: 2,
17482 Symbolic: 4,
17483 Script: 8,
17484 Nonsymbolic: 32,
17485 Italic: 64,
17486 AllCap: 65536,
17487 SmallCap: 131072,
17488 ForceBold: 262144
17489};
17490const 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"];
17491function recoverGlyphName(name, glyphsUnicodeMap) {
17492 if (glyphsUnicodeMap[name] !== undefined) {
17493 return name;
17494 }
17495 const unicode = getUnicodeForGlyph(name, glyphsUnicodeMap);
17496 if (unicode !== -1) {
17497 for (const key in glyphsUnicodeMap) {
17498 if (glyphsUnicodeMap[key] === unicode) {
17499 return key;
17500 }
17501 }
17502 }
17503 info("Unable to recover a standard glyph name for: " + name);
17504 return name;
17505}
17506function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
17507 const charCodeToGlyphId = Object.create(null);
17508 let glyphId, charCode, baseEncoding;
17509 const isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
17510 if (properties.isInternalFont) {
17511 baseEncoding = builtInEncoding;
17512 for (charCode = 0; charCode < baseEncoding.length; charCode++) {
17513 glyphId = glyphNames.indexOf(baseEncoding[charCode]);
17514 charCodeToGlyphId[charCode] = glyphId >= 0 ? glyphId : 0;
17515 }
17516 } else if (properties.baseEncodingName) {
17517 baseEncoding = getEncoding(properties.baseEncodingName);
17518 for (charCode = 0; charCode < baseEncoding.length; charCode++) {
17519 glyphId = glyphNames.indexOf(baseEncoding[charCode]);
17520 charCodeToGlyphId[charCode] = glyphId >= 0 ? glyphId : 0;
17521 }
17522 } else if (isSymbolicFont) {
17523 for (charCode in builtInEncoding) {
17524 charCodeToGlyphId[charCode] = builtInEncoding[charCode];
17525 }
17526 } else {
17527 baseEncoding = StandardEncoding;
17528 for (charCode = 0; charCode < baseEncoding.length; charCode++) {
17529 glyphId = glyphNames.indexOf(baseEncoding[charCode]);
17530 charCodeToGlyphId[charCode] = glyphId >= 0 ? glyphId : 0;
17531 }
17532 }
17533 const differences = properties.differences;
17534 let glyphsUnicodeMap;
17535 if (differences) {
17536 for (charCode in differences) {
17537 const glyphName = differences[charCode];
17538 glyphId = glyphNames.indexOf(glyphName);
17539 if (glyphId === -1) {
17540 if (!glyphsUnicodeMap) {
17541 glyphsUnicodeMap = getGlyphsUnicode();
17542 }
17543 const standardGlyphName = recoverGlyphName(glyphName, glyphsUnicodeMap);
17544 if (standardGlyphName !== glyphName) {
17545 glyphId = glyphNames.indexOf(standardGlyphName);
17546 }
17547 }
17548 charCodeToGlyphId[charCode] = glyphId >= 0 ? glyphId : 0;
17549 }
17550 }
17551 return charCodeToGlyphId;
17552}
17553function normalizeFontName(name) {
17554 return name.replaceAll(/[,_]/g, "-").replaceAll(/\s/g, "");
17555}
17556
17557;// CONCATENATED MODULE: ./src/core/standard_fonts.js
17558
17559
17560const getStdFontMap = getLookupTableFactory(function (t) {
17561 t["Times-Roman"] = "Times-Roman";
17562 t.Helvetica = "Helvetica";
17563 t.Courier = "Courier";
17564 t.Symbol = "Symbol";
17565 t["Times-Bold"] = "Times-Bold";
17566 t["Helvetica-Bold"] = "Helvetica-Bold";
17567 t["Courier-Bold"] = "Courier-Bold";
17568 t.ZapfDingbats = "ZapfDingbats";
17569 t["Times-Italic"] = "Times-Italic";
17570 t["Helvetica-Oblique"] = "Helvetica-Oblique";
17571 t["Courier-Oblique"] = "Courier-Oblique";
17572 t["Times-BoldItalic"] = "Times-BoldItalic";
17573 t["Helvetica-BoldOblique"] = "Helvetica-BoldOblique";
17574 t["Courier-BoldOblique"] = "Courier-BoldOblique";
17575 t.ArialNarrow = "Helvetica";
17576 t["ArialNarrow-Bold"] = "Helvetica-Bold";
17577 t["ArialNarrow-BoldItalic"] = "Helvetica-BoldOblique";
17578 t["ArialNarrow-Italic"] = "Helvetica-Oblique";
17579 t.ArialBlack = "Helvetica";
17580 t["ArialBlack-Bold"] = "Helvetica-Bold";
17581 t["ArialBlack-BoldItalic"] = "Helvetica-BoldOblique";
17582 t["ArialBlack-Italic"] = "Helvetica-Oblique";
17583 t["Arial-Black"] = "Helvetica";
17584 t["Arial-Black-Bold"] = "Helvetica-Bold";
17585 t["Arial-Black-BoldItalic"] = "Helvetica-BoldOblique";
17586 t["Arial-Black-Italic"] = "Helvetica-Oblique";
17587 t.Arial = "Helvetica";
17588 t["Arial-Bold"] = "Helvetica-Bold";
17589 t["Arial-BoldItalic"] = "Helvetica-BoldOblique";
17590 t["Arial-Italic"] = "Helvetica-Oblique";
17591 t.ArialMT = "Helvetica";
17592 t["Arial-BoldItalicMT"] = "Helvetica-BoldOblique";
17593 t["Arial-BoldMT"] = "Helvetica-Bold";
17594 t["Arial-ItalicMT"] = "Helvetica-Oblique";
17595 t["Arial-BoldItalicMT-BoldItalic"] = "Helvetica-BoldOblique";
17596 t["Arial-BoldMT-Bold"] = "Helvetica-Bold";
17597 t["Arial-ItalicMT-Italic"] = "Helvetica-Oblique";
17598 t.ArialUnicodeMS = "Helvetica";
17599 t["ArialUnicodeMS-Bold"] = "Helvetica-Bold";
17600 t["ArialUnicodeMS-BoldItalic"] = "Helvetica-BoldOblique";
17601 t["ArialUnicodeMS-Italic"] = "Helvetica-Oblique";
17602 t["Courier-BoldItalic"] = "Courier-BoldOblique";
17603 t["Courier-Italic"] = "Courier-Oblique";
17604 t.CourierNew = "Courier";
17605 t["CourierNew-Bold"] = "Courier-Bold";
17606 t["CourierNew-BoldItalic"] = "Courier-BoldOblique";
17607 t["CourierNew-Italic"] = "Courier-Oblique";
17608 t["CourierNewPS-BoldItalicMT"] = "Courier-BoldOblique";
17609 t["CourierNewPS-BoldMT"] = "Courier-Bold";
17610 t["CourierNewPS-ItalicMT"] = "Courier-Oblique";
17611 t.CourierNewPSMT = "Courier";
17612 t["Helvetica-BoldItalic"] = "Helvetica-BoldOblique";
17613 t["Helvetica-Italic"] = "Helvetica-Oblique";
17614 t["Symbol-Bold"] = "Symbol";
17615 t["Symbol-BoldItalic"] = "Symbol";
17616 t["Symbol-Italic"] = "Symbol";
17617 t.TimesNewRoman = "Times-Roman";
17618 t["TimesNewRoman-Bold"] = "Times-Bold";
17619 t["TimesNewRoman-BoldItalic"] = "Times-BoldItalic";
17620 t["TimesNewRoman-Italic"] = "Times-Italic";
17621 t.TimesNewRomanPS = "Times-Roman";
17622 t["TimesNewRomanPS-Bold"] = "Times-Bold";
17623 t["TimesNewRomanPS-BoldItalic"] = "Times-BoldItalic";
17624 t["TimesNewRomanPS-BoldItalicMT"] = "Times-BoldItalic";
17625 t["TimesNewRomanPS-BoldMT"] = "Times-Bold";
17626 t["TimesNewRomanPS-Italic"] = "Times-Italic";
17627 t["TimesNewRomanPS-ItalicMT"] = "Times-Italic";
17628 t.TimesNewRomanPSMT = "Times-Roman";
17629 t["TimesNewRomanPSMT-Bold"] = "Times-Bold";
17630 t["TimesNewRomanPSMT-BoldItalic"] = "Times-BoldItalic";
17631 t["TimesNewRomanPSMT-Italic"] = "Times-Italic";
17632});
17633const getFontNameToFileMap = getLookupTableFactory(function (t) {
17634 t.Courier = "FoxitFixed.pfb";
17635 t["Courier-Bold"] = "FoxitFixedBold.pfb";
17636 t["Courier-BoldOblique"] = "FoxitFixedBoldItalic.pfb";
17637 t["Courier-Oblique"] = "FoxitFixedItalic.pfb";
17638 t.Helvetica = "LiberationSans-Regular.ttf";
17639 t["Helvetica-Bold"] = "LiberationSans-Bold.ttf";
17640 t["Helvetica-BoldOblique"] = "LiberationSans-BoldItalic.ttf";
17641 t["Helvetica-Oblique"] = "LiberationSans-Italic.ttf";
17642 t["Times-Roman"] = "FoxitSerif.pfb";
17643 t["Times-Bold"] = "FoxitSerifBold.pfb";
17644 t["Times-BoldItalic"] = "FoxitSerifBoldItalic.pfb";
17645 t["Times-Italic"] = "FoxitSerifItalic.pfb";
17646 t.Symbol = "FoxitSymbol.pfb";
17647 t.ZapfDingbats = "FoxitDingbats.pfb";
17648 t["LiberationSans-Regular"] = "LiberationSans-Regular.ttf";
17649 t["LiberationSans-Bold"] = "LiberationSans-Bold.ttf";
17650 t["LiberationSans-Italic"] = "LiberationSans-Italic.ttf";
17651 t["LiberationSans-BoldItalic"] = "LiberationSans-BoldItalic.ttf";
17652});
17653const getNonStdFontMap = getLookupTableFactory(function (t) {
17654 t.Calibri = "Helvetica";
17655 t["Calibri-Bold"] = "Helvetica-Bold";
17656 t["Calibri-BoldItalic"] = "Helvetica-BoldOblique";
17657 t["Calibri-Italic"] = "Helvetica-Oblique";
17658 t.CenturyGothic = "Helvetica";
17659 t["CenturyGothic-Bold"] = "Helvetica-Bold";
17660 t["CenturyGothic-BoldItalic"] = "Helvetica-BoldOblique";
17661 t["CenturyGothic-Italic"] = "Helvetica-Oblique";
17662 t.ComicSansMS = "Comic Sans MS";
17663 t["ComicSansMS-Bold"] = "Comic Sans MS-Bold";
17664 t["ComicSansMS-BoldItalic"] = "Comic Sans MS-BoldItalic";
17665 t["ComicSansMS-Italic"] = "Comic Sans MS-Italic";
17666 t.Impact = "Helvetica";
17667 t["ItcSymbol-Bold"] = "Helvetica-Bold";
17668 t["ItcSymbol-BoldItalic"] = "Helvetica-BoldOblique";
17669 t["ItcSymbol-Book"] = "Helvetica";
17670 t["ItcSymbol-BookItalic"] = "Helvetica-Oblique";
17671 t["ItcSymbol-Medium"] = "Helvetica";
17672 t["ItcSymbol-MediumItalic"] = "Helvetica-Oblique";
17673 t.LucidaConsole = "Courier";
17674 t["LucidaConsole-Bold"] = "Courier-Bold";
17675 t["LucidaConsole-BoldItalic"] = "Courier-BoldOblique";
17676 t["LucidaConsole-Italic"] = "Courier-Oblique";
17677 t["LucidaSans-Demi"] = "Helvetica-Bold";
17678 t["MS-Gothic"] = "MS Gothic";
17679 t["MS-Gothic-Bold"] = "MS Gothic-Bold";
17680 t["MS-Gothic-BoldItalic"] = "MS Gothic-BoldItalic";
17681 t["MS-Gothic-Italic"] = "MS Gothic-Italic";
17682 t["MS-Mincho"] = "MS Mincho";
17683 t["MS-Mincho-Bold"] = "MS Mincho-Bold";
17684 t["MS-Mincho-BoldItalic"] = "MS Mincho-BoldItalic";
17685 t["MS-Mincho-Italic"] = "MS Mincho-Italic";
17686 t["MS-PGothic"] = "MS PGothic";
17687 t["MS-PGothic-Bold"] = "MS PGothic-Bold";
17688 t["MS-PGothic-BoldItalic"] = "MS PGothic-BoldItalic";
17689 t["MS-PGothic-Italic"] = "MS PGothic-Italic";
17690 t["MS-PMincho"] = "MS PMincho";
17691 t["MS-PMincho-Bold"] = "MS PMincho-Bold";
17692 t["MS-PMincho-BoldItalic"] = "MS PMincho-BoldItalic";
17693 t["MS-PMincho-Italic"] = "MS PMincho-Italic";
17694 t.NuptialScript = "Times-Italic";
17695 t.SegoeUISymbol = "Helvetica";
17696});
17697const getSerifFonts = getLookupTableFactory(function (t) {
17698 t["Adobe Jenson"] = true;
17699 t["Adobe Text"] = true;
17700 t.Albertus = true;
17701 t.Aldus = true;
17702 t.Alexandria = true;
17703 t.Algerian = true;
17704 t["American Typewriter"] = true;
17705 t.Antiqua = true;
17706 t.Apex = true;
17707 t.Arno = true;
17708 t.Aster = true;
17709 t.Aurora = true;
17710 t.Baskerville = true;
17711 t.Bell = true;
17712 t.Bembo = true;
17713 t["Bembo Schoolbook"] = true;
17714 t.Benguiat = true;
17715 t["Berkeley Old Style"] = true;
17716 t["Bernhard Modern"] = true;
17717 t["Berthold City"] = true;
17718 t.Bodoni = true;
17719 t["Bauer Bodoni"] = true;
17720 t["Book Antiqua"] = true;
17721 t.Bookman = true;
17722 t["Bordeaux Roman"] = true;
17723 t["Californian FB"] = true;
17724 t.Calisto = true;
17725 t.Calvert = true;
17726 t.Capitals = true;
17727 t.Cambria = true;
17728 t.Cartier = true;
17729 t.Caslon = true;
17730 t.Catull = true;
17731 t.Centaur = true;
17732 t["Century Old Style"] = true;
17733 t["Century Schoolbook"] = true;
17734 t.Chaparral = true;
17735 t["Charis SIL"] = true;
17736 t.Cheltenham = true;
17737 t["Cholla Slab"] = true;
17738 t.Clarendon = true;
17739 t.Clearface = true;
17740 t.Cochin = true;
17741 t.Colonna = true;
17742 t["Computer Modern"] = true;
17743 t["Concrete Roman"] = true;
17744 t.Constantia = true;
17745 t["Cooper Black"] = true;
17746 t.Corona = true;
17747 t.Ecotype = true;
17748 t.Egyptienne = true;
17749 t.Elephant = true;
17750 t.Excelsior = true;
17751 t.Fairfield = true;
17752 t["FF Scala"] = true;
17753 t.Folkard = true;
17754 t.Footlight = true;
17755 t.FreeSerif = true;
17756 t["Friz Quadrata"] = true;
17757 t.Garamond = true;
17758 t.Gentium = true;
17759 t.Georgia = true;
17760 t.Gloucester = true;
17761 t["Goudy Old Style"] = true;
17762 t["Goudy Schoolbook"] = true;
17763 t["Goudy Pro Font"] = true;
17764 t.Granjon = true;
17765 t["Guardian Egyptian"] = true;
17766 t.Heather = true;
17767 t.Hercules = true;
17768 t["High Tower Text"] = true;
17769 t.Hiroshige = true;
17770 t["Hoefler Text"] = true;
17771 t["Humana Serif"] = true;
17772 t.Imprint = true;
17773 t["Ionic No. 5"] = true;
17774 t.Janson = true;
17775 t.Joanna = true;
17776 t.Korinna = true;
17777 t.Lexicon = true;
17778 t.LiberationSerif = true;
17779 t["Liberation Serif"] = true;
17780 t["Linux Libertine"] = true;
17781 t.Literaturnaya = true;
17782 t.Lucida = true;
17783 t["Lucida Bright"] = true;
17784 t.Melior = true;
17785 t.Memphis = true;
17786 t.Miller = true;
17787 t.Minion = true;
17788 t.Modern = true;
17789 t["Mona Lisa"] = true;
17790 t["Mrs Eaves"] = true;
17791 t["MS Serif"] = true;
17792 t["Museo Slab"] = true;
17793 t["New York"] = true;
17794 t["Nimbus Roman"] = true;
17795 t["NPS Rawlinson Roadway"] = true;
17796 t.NuptialScript = true;
17797 t.Palatino = true;
17798 t.Perpetua = true;
17799 t.Plantin = true;
17800 t["Plantin Schoolbook"] = true;
17801 t.Playbill = true;
17802 t["Poor Richard"] = true;
17803 t["Rawlinson Roadway"] = true;
17804 t.Renault = true;
17805 t.Requiem = true;
17806 t.Rockwell = true;
17807 t.Roman = true;
17808 t["Rotis Serif"] = true;
17809 t.Sabon = true;
17810 t.Scala = true;
17811 t.Seagull = true;
17812 t.Sistina = true;
17813 t.Souvenir = true;
17814 t.STIX = true;
17815 t["Stone Informal"] = true;
17816 t["Stone Serif"] = true;
17817 t.Sylfaen = true;
17818 t.Times = true;
17819 t.Trajan = true;
17820 t["Trinité"] = true;
17821 t["Trump Mediaeval"] = true;
17822 t.Utopia = true;
17823 t["Vale Type"] = true;
17824 t["Bitstream Vera"] = true;
17825 t["Vera Serif"] = true;
17826 t.Versailles = true;
17827 t.Wanted = true;
17828 t.Weiss = true;
17829 t["Wide Latin"] = true;
17830 t.Windsor = true;
17831 t.XITS = true;
17832});
17833const getSymbolsFonts = getLookupTableFactory(function (t) {
17834 t.Dingbats = true;
17835 t.Symbol = true;
17836 t.ZapfDingbats = true;
17837 t.Wingdings = true;
17838 t["Wingdings-Bold"] = true;
17839 t["Wingdings-Regular"] = true;
17840});
17841const getGlyphMapForStandardFonts = getLookupTableFactory(function (t) {
17842 t[2] = 10;
17843 t[3] = 32;
17844 t[4] = 33;
17845 t[5] = 34;
17846 t[6] = 35;
17847 t[7] = 36;
17848 t[8] = 37;
17849 t[9] = 38;
17850 t[10] = 39;
17851 t[11] = 40;
17852 t[12] = 41;
17853 t[13] = 42;
17854 t[14] = 43;
17855 t[15] = 44;
17856 t[16] = 45;
17857 t[17] = 46;
17858 t[18] = 47;
17859 t[19] = 48;
17860 t[20] = 49;
17861 t[21] = 50;
17862 t[22] = 51;
17863 t[23] = 52;
17864 t[24] = 53;
17865 t[25] = 54;
17866 t[26] = 55;
17867 t[27] = 56;
17868 t[28] = 57;
17869 t[29] = 58;
17870 t[30] = 894;
17871 t[31] = 60;
17872 t[32] = 61;
17873 t[33] = 62;
17874 t[34] = 63;
17875 t[35] = 64;
17876 t[36] = 65;
17877 t[37] = 66;
17878 t[38] = 67;
17879 t[39] = 68;
17880 t[40] = 69;
17881 t[41] = 70;
17882 t[42] = 71;
17883 t[43] = 72;
17884 t[44] = 73;
17885 t[45] = 74;
17886 t[46] = 75;
17887 t[47] = 76;
17888 t[48] = 77;
17889 t[49] = 78;
17890 t[50] = 79;
17891 t[51] = 80;
17892 t[52] = 81;
17893 t[53] = 82;
17894 t[54] = 83;
17895 t[55] = 84;
17896 t[56] = 85;
17897 t[57] = 86;
17898 t[58] = 87;
17899 t[59] = 88;
17900 t[60] = 89;
17901 t[61] = 90;
17902 t[62] = 91;
17903 t[63] = 92;
17904 t[64] = 93;
17905 t[65] = 94;
17906 t[66] = 95;
17907 t[67] = 96;
17908 t[68] = 97;
17909 t[69] = 98;
17910 t[70] = 99;
17911 t[71] = 100;
17912 t[72] = 101;
17913 t[73] = 102;
17914 t[74] = 103;
17915 t[75] = 104;
17916 t[76] = 105;
17917 t[77] = 106;
17918 t[78] = 107;
17919 t[79] = 108;
17920 t[80] = 109;
17921 t[81] = 110;
17922 t[82] = 111;
17923 t[83] = 112;
17924 t[84] = 113;
17925 t[85] = 114;
17926 t[86] = 115;
17927 t[87] = 116;
17928 t[88] = 117;
17929 t[89] = 118;
17930 t[90] = 119;
17931 t[91] = 120;
17932 t[92] = 121;
17933 t[93] = 122;
17934 t[94] = 123;
17935 t[95] = 124;
17936 t[96] = 125;
17937 t[97] = 126;
17938 t[98] = 196;
17939 t[99] = 197;
17940 t[100] = 199;
17941 t[101] = 201;
17942 t[102] = 209;
17943 t[103] = 214;
17944 t[104] = 220;
17945 t[105] = 225;
17946 t[106] = 224;
17947 t[107] = 226;
17948 t[108] = 228;
17949 t[109] = 227;
17950 t[110] = 229;
17951 t[111] = 231;
17952 t[112] = 233;
17953 t[113] = 232;
17954 t[114] = 234;
17955 t[115] = 235;
17956 t[116] = 237;
17957 t[117] = 236;
17958 t[118] = 238;
17959 t[119] = 239;
17960 t[120] = 241;
17961 t[121] = 243;
17962 t[122] = 242;
17963 t[123] = 244;
17964 t[124] = 246;
17965 t[125] = 245;
17966 t[126] = 250;
17967 t[127] = 249;
17968 t[128] = 251;
17969 t[129] = 252;
17970 t[130] = 8224;
17971 t[131] = 176;
17972 t[132] = 162;
17973 t[133] = 163;
17974 t[134] = 167;
17975 t[135] = 8226;
17976 t[136] = 182;
17977 t[137] = 223;
17978 t[138] = 174;
17979 t[139] = 169;
17980 t[140] = 8482;
17981 t[141] = 180;
17982 t[142] = 168;
17983 t[143] = 8800;
17984 t[144] = 198;
17985 t[145] = 216;
17986 t[146] = 8734;
17987 t[147] = 177;
17988 t[148] = 8804;
17989 t[149] = 8805;
17990 t[150] = 165;
17991 t[151] = 181;
17992 t[152] = 8706;
17993 t[153] = 8721;
17994 t[154] = 8719;
17995 t[156] = 8747;
17996 t[157] = 170;
17997 t[158] = 186;
17998 t[159] = 8486;
17999 t[160] = 230;
18000 t[161] = 248;
18001 t[162] = 191;
18002 t[163] = 161;
18003 t[164] = 172;
18004 t[165] = 8730;
18005 t[166] = 402;
18006 t[167] = 8776;
18007 t[168] = 8710;
18008 t[169] = 171;
18009 t[170] = 187;
18010 t[171] = 8230;
18011 t[179] = 8220;
18012 t[180] = 8221;
18013 t[181] = 8216;
18014 t[182] = 8217;
18015 t[200] = 193;
18016 t[203] = 205;
18017 t[207] = 211;
18018 t[210] = 218;
18019 t[223] = 711;
18020 t[224] = 321;
18021 t[225] = 322;
18022 t[226] = 352;
18023 t[227] = 353;
18024 t[228] = 381;
18025 t[229] = 382;
18026 t[233] = 221;
18027 t[234] = 253;
18028 t[252] = 263;
18029 t[253] = 268;
18030 t[254] = 269;
18031 t[258] = 258;
18032 t[260] = 260;
18033 t[261] = 261;
18034 t[265] = 280;
18035 t[266] = 281;
18036 t[267] = 282;
18037 t[268] = 283;
18038 t[269] = 313;
18039 t[275] = 323;
18040 t[276] = 324;
18041 t[278] = 328;
18042 t[283] = 344;
18043 t[284] = 345;
18044 t[285] = 346;
18045 t[286] = 347;
18046 t[292] = 367;
18047 t[295] = 377;
18048 t[296] = 378;
18049 t[298] = 380;
18050 t[305] = 963;
18051 t[306] = 964;
18052 t[307] = 966;
18053 t[308] = 8215;
18054 t[309] = 8252;
18055 t[310] = 8319;
18056 t[311] = 8359;
18057 t[312] = 8592;
18058 t[313] = 8593;
18059 t[337] = 9552;
18060 t[493] = 1039;
18061 t[494] = 1040;
18062 t[672] = 1488;
18063 t[673] = 1489;
18064 t[674] = 1490;
18065 t[675] = 1491;
18066 t[676] = 1492;
18067 t[677] = 1493;
18068 t[678] = 1494;
18069 t[679] = 1495;
18070 t[680] = 1496;
18071 t[681] = 1497;
18072 t[682] = 1498;
18073 t[683] = 1499;
18074 t[684] = 1500;
18075 t[685] = 1501;
18076 t[686] = 1502;
18077 t[687] = 1503;
18078 t[688] = 1504;
18079 t[689] = 1505;
18080 t[690] = 1506;
18081 t[691] = 1507;
18082 t[692] = 1508;
18083 t[693] = 1509;
18084 t[694] = 1510;
18085 t[695] = 1511;
18086 t[696] = 1512;
18087 t[697] = 1513;
18088 t[698] = 1514;
18089 t[705] = 1524;
18090 t[706] = 8362;
18091 t[710] = 64288;
18092 t[711] = 64298;
18093 t[759] = 1617;
18094 t[761] = 1776;
18095 t[763] = 1778;
18096 t[775] = 1652;
18097 t[777] = 1764;
18098 t[778] = 1780;
18099 t[779] = 1781;
18100 t[780] = 1782;
18101 t[782] = 771;
18102 t[783] = 64726;
18103 t[786] = 8363;
18104 t[788] = 8532;
18105 t[790] = 768;
18106 t[791] = 769;
18107 t[792] = 768;
18108 t[795] = 803;
18109 t[797] = 64336;
18110 t[798] = 64337;
18111 t[799] = 64342;
18112 t[800] = 64343;
18113 t[801] = 64344;
18114 t[802] = 64345;
18115 t[803] = 64362;
18116 t[804] = 64363;
18117 t[805] = 64364;
18118 t[2424] = 7821;
18119 t[2425] = 7822;
18120 t[2426] = 7823;
18121 t[2427] = 7824;
18122 t[2428] = 7825;
18123 t[2429] = 7826;
18124 t[2430] = 7827;
18125 t[2433] = 7682;
18126 t[2678] = 8045;
18127 t[2679] = 8046;
18128 t[2830] = 1552;
18129 t[2838] = 686;
18130 t[2840] = 751;
18131 t[2842] = 753;
18132 t[2843] = 754;
18133 t[2844] = 755;
18134 t[2846] = 757;
18135 t[2856] = 767;
18136 t[2857] = 848;
18137 t[2858] = 849;
18138 t[2862] = 853;
18139 t[2863] = 854;
18140 t[2864] = 855;
18141 t[2865] = 861;
18142 t[2866] = 862;
18143 t[2906] = 7460;
18144 t[2908] = 7462;
18145 t[2909] = 7463;
18146 t[2910] = 7464;
18147 t[2912] = 7466;
18148 t[2913] = 7467;
18149 t[2914] = 7468;
18150 t[2916] = 7470;
18151 t[2917] = 7471;
18152 t[2918] = 7472;
18153 t[2920] = 7474;
18154 t[2921] = 7475;
18155 t[2922] = 7476;
18156 t[2924] = 7478;
18157 t[2925] = 7479;
18158 t[2926] = 7480;
18159 t[2928] = 7482;
18160 t[2929] = 7483;
18161 t[2930] = 7484;
18162 t[2932] = 7486;
18163 t[2933] = 7487;
18164 t[2934] = 7488;
18165 t[2936] = 7490;
18166 t[2937] = 7491;
18167 t[2938] = 7492;
18168 t[2940] = 7494;
18169 t[2941] = 7495;
18170 t[2942] = 7496;
18171 t[2944] = 7498;
18172 t[2946] = 7500;
18173 t[2948] = 7502;
18174 t[2950] = 7504;
18175 t[2951] = 7505;
18176 t[2952] = 7506;
18177 t[2954] = 7508;
18178 t[2955] = 7509;
18179 t[2956] = 7510;
18180 t[2958] = 7512;
18181 t[2959] = 7513;
18182 t[2960] = 7514;
18183 t[2962] = 7516;
18184 t[2963] = 7517;
18185 t[2964] = 7518;
18186 t[2966] = 7520;
18187 t[2967] = 7521;
18188 t[2968] = 7522;
18189 t[2970] = 7524;
18190 t[2971] = 7525;
18191 t[2972] = 7526;
18192 t[2974] = 7528;
18193 t[2975] = 7529;
18194 t[2976] = 7530;
18195 t[2978] = 1537;
18196 t[2979] = 1538;
18197 t[2980] = 1539;
18198 t[2982] = 1549;
18199 t[2983] = 1551;
18200 t[2984] = 1552;
18201 t[2986] = 1554;
18202 t[2987] = 1555;
18203 t[2988] = 1556;
18204 t[2990] = 1623;
18205 t[2991] = 1624;
18206 t[2995] = 1775;
18207 t[2999] = 1791;
18208 t[3002] = 64290;
18209 t[3003] = 64291;
18210 t[3004] = 64292;
18211 t[3006] = 64294;
18212 t[3007] = 64295;
18213 t[3008] = 64296;
18214 t[3011] = 1900;
18215 t[3014] = 8223;
18216 t[3015] = 8244;
18217 t[3017] = 7532;
18218 t[3018] = 7533;
18219 t[3019] = 7534;
18220 t[3075] = 7590;
18221 t[3076] = 7591;
18222 t[3079] = 7594;
18223 t[3080] = 7595;
18224 t[3083] = 7598;
18225 t[3084] = 7599;
18226 t[3087] = 7602;
18227 t[3088] = 7603;
18228 t[3091] = 7606;
18229 t[3092] = 7607;
18230 t[3095] = 7610;
18231 t[3096] = 7611;
18232 t[3099] = 7614;
18233 t[3100] = 7615;
18234 t[3103] = 7618;
18235 t[3104] = 7619;
18236 t[3107] = 8337;
18237 t[3108] = 8338;
18238 t[3116] = 1884;
18239 t[3119] = 1885;
18240 t[3120] = 1885;
18241 t[3123] = 1886;
18242 t[3124] = 1886;
18243 t[3127] = 1887;
18244 t[3128] = 1887;
18245 t[3131] = 1888;
18246 t[3132] = 1888;
18247 t[3135] = 1889;
18248 t[3136] = 1889;
18249 t[3139] = 1890;
18250 t[3140] = 1890;
18251 t[3143] = 1891;
18252 t[3144] = 1891;
18253 t[3147] = 1892;
18254 t[3148] = 1892;
18255 t[3153] = 580;
18256 t[3154] = 581;
18257 t[3157] = 584;
18258 t[3158] = 585;
18259 t[3161] = 588;
18260 t[3162] = 589;
18261 t[3165] = 891;
18262 t[3166] = 892;
18263 t[3169] = 1274;
18264 t[3170] = 1275;
18265 t[3173] = 1278;
18266 t[3174] = 1279;
18267 t[3181] = 7622;
18268 t[3182] = 7623;
18269 t[3282] = 11799;
18270 t[3316] = 578;
18271 t[3379] = 42785;
18272 t[3393] = 1159;
18273 t[3416] = 8377;
18274});
18275const getSupplementalGlyphMapForArialBlack = getLookupTableFactory(function (t) {
18276 t[227] = 322;
18277 t[264] = 261;
18278 t[291] = 346;
18279});
18280const getSupplementalGlyphMapForCalibri = getLookupTableFactory(function (t) {
18281 t[1] = 32;
18282 t[4] = 65;
18283 t[5] = 192;
18284 t[6] = 193;
18285 t[9] = 196;
18286 t[17] = 66;
18287 t[18] = 67;
18288 t[21] = 268;
18289 t[24] = 68;
18290 t[28] = 69;
18291 t[29] = 200;
18292 t[30] = 201;
18293 t[32] = 282;
18294 t[38] = 70;
18295 t[39] = 71;
18296 t[44] = 72;
18297 t[47] = 73;
18298 t[48] = 204;
18299 t[49] = 205;
18300 t[58] = 74;
18301 t[60] = 75;
18302 t[62] = 76;
18303 t[68] = 77;
18304 t[69] = 78;
18305 t[75] = 79;
18306 t[76] = 210;
18307 t[80] = 214;
18308 t[87] = 80;
18309 t[89] = 81;
18310 t[90] = 82;
18311 t[92] = 344;
18312 t[94] = 83;
18313 t[97] = 352;
18314 t[100] = 84;
18315 t[104] = 85;
18316 t[109] = 220;
18317 t[115] = 86;
18318 t[116] = 87;
18319 t[121] = 88;
18320 t[122] = 89;
18321 t[124] = 221;
18322 t[127] = 90;
18323 t[129] = 381;
18324 t[258] = 97;
18325 t[259] = 224;
18326 t[260] = 225;
18327 t[263] = 228;
18328 t[268] = 261;
18329 t[271] = 98;
18330 t[272] = 99;
18331 t[273] = 263;
18332 t[275] = 269;
18333 t[282] = 100;
18334 t[286] = 101;
18335 t[287] = 232;
18336 t[288] = 233;
18337 t[290] = 283;
18338 t[295] = 281;
18339 t[296] = 102;
18340 t[336] = 103;
18341 t[346] = 104;
18342 t[349] = 105;
18343 t[350] = 236;
18344 t[351] = 237;
18345 t[361] = 106;
18346 t[364] = 107;
18347 t[367] = 108;
18348 t[371] = 322;
18349 t[373] = 109;
18350 t[374] = 110;
18351 t[381] = 111;
18352 t[382] = 242;
18353 t[383] = 243;
18354 t[386] = 246;
18355 t[393] = 112;
18356 t[395] = 113;
18357 t[396] = 114;
18358 t[398] = 345;
18359 t[400] = 115;
18360 t[401] = 347;
18361 t[403] = 353;
18362 t[410] = 116;
18363 t[437] = 117;
18364 t[442] = 252;
18365 t[448] = 118;
18366 t[449] = 119;
18367 t[454] = 120;
18368 t[455] = 121;
18369 t[457] = 253;
18370 t[460] = 122;
18371 t[462] = 382;
18372 t[463] = 380;
18373 t[853] = 44;
18374 t[855] = 58;
18375 t[856] = 46;
18376 t[876] = 47;
18377 t[878] = 45;
18378 t[882] = 45;
18379 t[894] = 40;
18380 t[895] = 41;
18381 t[896] = 91;
18382 t[897] = 93;
18383 t[923] = 64;
18384 t[1004] = 48;
18385 t[1005] = 49;
18386 t[1006] = 50;
18387 t[1007] = 51;
18388 t[1008] = 52;
18389 t[1009] = 53;
18390 t[1010] = 54;
18391 t[1011] = 55;
18392 t[1012] = 56;
18393 t[1013] = 57;
18394 t[1081] = 37;
18395 t[1085] = 43;
18396 t[1086] = 45;
18397});
18398function getStandardFontName(name) {
18399 const fontName = normalizeFontName(name);
18400 const stdFontMap = getStdFontMap();
18401 return stdFontMap[fontName];
18402}
18403function isKnownFontName(name) {
18404 const fontName = normalizeFontName(name);
18405 return !!(getStdFontMap()[fontName] || getNonStdFontMap()[fontName] || getSerifFonts()[fontName] || getSymbolsFonts()[fontName]);
18406}
18407
18408;// CONCATENATED MODULE: ./src/core/to_unicode_map.js
18409
18410class ToUnicodeMap {
18411 constructor(cmap = []) {
18412 this._map = cmap;
18413 }
18414 get length() {
18415 return this._map.length;
18416 }
18417 forEach(callback) {
18418 for (const charCode in this._map) {
18419 callback(charCode, this._map[charCode].charCodeAt(0));
18420 }
18421 }
18422 has(i) {
18423 return this._map[i] !== undefined;
18424 }
18425 get(i) {
18426 return this._map[i];
18427 }
18428 charCodeOf(value) {
18429 const map = this._map;
18430 if (map.length <= 0x10000) {
18431 return map.indexOf(value);
18432 }
18433 for (const charCode in map) {
18434 if (map[charCode] === value) {
18435 return charCode | 0;
18436 }
18437 }
18438 return -1;
18439 }
18440 amend(map) {
18441 for (const charCode in map) {
18442 this._map[charCode] = map[charCode];
18443 }
18444 }
18445}
18446class IdentityToUnicodeMap {
18447 constructor(firstChar, lastChar) {
18448 this.firstChar = firstChar;
18449 this.lastChar = lastChar;
18450 }
18451 get length() {
18452 return this.lastChar + 1 - this.firstChar;
18453 }
18454 forEach(callback) {
18455 for (let i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
18456 callback(i, i);
18457 }
18458 }
18459 has(i) {
18460 return this.firstChar <= i && i <= this.lastChar;
18461 }
18462 get(i) {
18463 if (this.firstChar <= i && i <= this.lastChar) {
18464 return String.fromCharCode(i);
18465 }
18466 return undefined;
18467 }
18468 charCodeOf(v) {
18469 return Number.isInteger(v) && v >= this.firstChar && v <= this.lastChar ? v : -1;
18470 }
18471 amend(map) {
18472 unreachable("Should not call amend()");
18473 }
18474}
18475
18476;// CONCATENATED MODULE: ./src/core/cff_font.js
18477
18478
18479
18480class CFFFont {
18481 constructor(file, properties) {
18482 this.properties = properties;
18483 const parser = new CFFParser(file, properties, SEAC_ANALYSIS_ENABLED);
18484 this.cff = parser.parse();
18485 this.cff.duplicateFirstGlyph();
18486 const compiler = new CFFCompiler(this.cff);
18487 this.seacs = this.cff.seacs;
18488 try {
18489 this.data = compiler.compile();
18490 } catch {
18491 warn("Failed to compile font " + properties.loadedName);
18492 this.data = file;
18493 }
18494 this._createBuiltInEncoding();
18495 }
18496 get numGlyphs() {
18497 return this.cff.charStrings.count;
18498 }
18499 getCharset() {
18500 return this.cff.charset.charset;
18501 }
18502 getGlyphMapping() {
18503 const cff = this.cff;
18504 const properties = this.properties;
18505 const {
18506 cidToGidMap,
18507 cMap
18508 } = properties;
18509 const charsets = cff.charset.charset;
18510 let charCodeToGlyphId;
18511 let glyphId;
18512 if (properties.composite) {
18513 let invCidToGidMap;
18514 if (cidToGidMap?.length > 0) {
18515 invCidToGidMap = Object.create(null);
18516 for (let i = 0, ii = cidToGidMap.length; i < ii; i++) {
18517 const gid = cidToGidMap[i];
18518 if (gid !== undefined) {
18519 invCidToGidMap[gid] = i;
18520 }
18521 }
18522 }
18523 charCodeToGlyphId = Object.create(null);
18524 let charCode;
18525 if (cff.isCIDFont) {
18526 for (glyphId = 0; glyphId < charsets.length; glyphId++) {
18527 const cid = charsets[glyphId];
18528 charCode = cMap.charCodeOf(cid);
18529 if (invCidToGidMap?.[charCode] !== undefined) {
18530 charCode = invCidToGidMap[charCode];
18531 }
18532 charCodeToGlyphId[charCode] = glyphId;
18533 }
18534 } else {
18535 for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
18536 charCode = cMap.charCodeOf(glyphId);
18537 charCodeToGlyphId[charCode] = glyphId;
18538 }
18539 }
18540 return charCodeToGlyphId;
18541 }
18542 let encoding = cff.encoding ? cff.encoding.encoding : null;
18543 if (properties.isInternalFont) {
18544 encoding = properties.defaultEncoding;
18545 }
18546 charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
18547 return charCodeToGlyphId;
18548 }
18549 hasGlyphId(id) {
18550 return this.cff.hasGlyphId(id);
18551 }
18552 _createBuiltInEncoding() {
18553 const {
18554 charset,
18555 encoding
18556 } = this.cff;
18557 if (!charset || !encoding) {
18558 return;
18559 }
18560 const charsets = charset.charset,
18561 encodings = encoding.encoding;
18562 const map = [];
18563 for (const charCode in encodings) {
18564 const glyphId = encodings[charCode];
18565 if (glyphId >= 0) {
18566 const glyphName = charsets[glyphId];
18567 if (glyphName) {
18568 map[charCode] = glyphName;
18569 }
18570 }
18571 }
18572 if (map.length > 0) {
18573 this.properties.builtInEncoding = map;
18574 }
18575 }
18576}
18577
18578;// CONCATENATED MODULE: ./src/core/font_renderer.js
18579
18580
18581
18582
18583
18584function getUint32(data, offset) {
18585 return (data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3]) >>> 0;
18586}
18587function getUint16(data, offset) {
18588 return data[offset] << 8 | data[offset + 1];
18589}
18590function getInt16(data, offset) {
18591 return (data[offset] << 24 | data[offset + 1] << 16) >> 16;
18592}
18593function getInt8(data, offset) {
18594 return data[offset] << 24 >> 24;
18595}
18596function getFloat214(data, offset) {
18597 return getInt16(data, offset) / 16384;
18598}
18599function getSubroutineBias(subrs) {
18600 const numSubrs = subrs.length;
18601 let bias = 32768;
18602 if (numSubrs < 1240) {
18603 bias = 107;
18604 } else if (numSubrs < 33900) {
18605 bias = 1131;
18606 }
18607 return bias;
18608}
18609function parseCmap(data, start, end) {
18610 const offset = getUint16(data, start + 2) === 1 ? getUint32(data, start + 8) : getUint32(data, start + 16);
18611 const format = getUint16(data, start + offset);
18612 let ranges, p, i;
18613 if (format === 4) {
18614 getUint16(data, start + offset + 2);
18615 const segCount = getUint16(data, start + offset + 6) >> 1;
18616 p = start + offset + 14;
18617 ranges = [];
18618 for (i = 0; i < segCount; i++, p += 2) {
18619 ranges[i] = {
18620 end: getUint16(data, p)
18621 };
18622 }
18623 p += 2;
18624 for (i = 0; i < segCount; i++, p += 2) {
18625 ranges[i].start = getUint16(data, p);
18626 }
18627 for (i = 0; i < segCount; i++, p += 2) {
18628 ranges[i].idDelta = getUint16(data, p);
18629 }
18630 for (i = 0; i < segCount; i++, p += 2) {
18631 let idOffset = getUint16(data, p);
18632 if (idOffset === 0) {
18633 continue;
18634 }
18635 ranges[i].ids = [];
18636 for (let j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
18637 ranges[i].ids[j] = getUint16(data, p + idOffset);
18638 idOffset += 2;
18639 }
18640 }
18641 return ranges;
18642 } else if (format === 12) {
18643 const groups = getUint32(data, start + offset + 12);
18644 p = start + offset + 16;
18645 ranges = [];
18646 for (i = 0; i < groups; i++) {
18647 start = getUint32(data, p);
18648 ranges.push({
18649 start,
18650 end: getUint32(data, p + 4),
18651 idDelta: getUint32(data, p + 8) - start
18652 });
18653 p += 12;
18654 }
18655 return ranges;
18656 }
18657 throw new FormatError(`unsupported cmap: ${format}`);
18658}
18659function parseCff(data, start, end, seacAnalysisEnabled) {
18660 const properties = {};
18661 const parser = new CFFParser(new Stream(data, start, end - start), properties, seacAnalysisEnabled);
18662 const cff = parser.parse();
18663 return {
18664 glyphs: cff.charStrings.objects,
18665 subrs: cff.topDict.privateDict?.subrsIndex?.objects,
18666 gsubrs: cff.globalSubrIndex?.objects,
18667 isCFFCIDFont: cff.isCIDFont,
18668 fdSelect: cff.fdSelect,
18669 fdArray: cff.fdArray
18670 };
18671}
18672function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
18673 let itemSize, itemDecode;
18674 if (isGlyphLocationsLong) {
18675 itemSize = 4;
18676 itemDecode = getUint32;
18677 } else {
18678 itemSize = 2;
18679 itemDecode = (data, offset) => 2 * getUint16(data, offset);
18680 }
18681 const glyphs = [];
18682 let startOffset = itemDecode(loca, 0);
18683 for (let j = itemSize; j < loca.length; j += itemSize) {
18684 const endOffset = itemDecode(loca, j);
18685 glyphs.push(glyf.subarray(startOffset, endOffset));
18686 startOffset = endOffset;
18687 }
18688 return glyphs;
18689}
18690function lookupCmap(ranges, unicode) {
18691 const code = unicode.codePointAt(0);
18692 let gid = 0,
18693 l = 0,
18694 r = ranges.length - 1;
18695 while (l < r) {
18696 const c = l + r + 1 >> 1;
18697 if (code < ranges[c].start) {
18698 r = c - 1;
18699 } else {
18700 l = c;
18701 }
18702 }
18703 if (ranges[l].start <= code && code <= ranges[l].end) {
18704 gid = ranges[l].idDelta + (ranges[l].ids ? ranges[l].ids[code - ranges[l].start] : code) & 0xffff;
18705 }
18706 return {
18707 charCode: code,
18708 glyphId: gid
18709 };
18710}
18711function compileGlyf(code, cmds, font) {
18712 function moveTo(x, y) {
18713 cmds.push({
18714 cmd: "moveTo",
18715 args: [x, y]
18716 });
18717 }
18718 function lineTo(x, y) {
18719 cmds.push({
18720 cmd: "lineTo",
18721 args: [x, y]
18722 });
18723 }
18724 function quadraticCurveTo(xa, ya, x, y) {
18725 cmds.push({
18726 cmd: "quadraticCurveTo",
18727 args: [xa, ya, x, y]
18728 });
18729 }
18730 let i = 0;
18731 const numberOfContours = getInt16(code, i);
18732 let flags;
18733 let x = 0,
18734 y = 0;
18735 i += 10;
18736 if (numberOfContours < 0) {
18737 do {
18738 flags = getUint16(code, i);
18739 const glyphIndex = getUint16(code, i + 2);
18740 i += 4;
18741 let arg1, arg2;
18742 if (flags & 0x01) {
18743 if (flags & 0x02) {
18744 arg1 = getInt16(code, i);
18745 arg2 = getInt16(code, i + 2);
18746 } else {
18747 arg1 = getUint16(code, i);
18748 arg2 = getUint16(code, i + 2);
18749 }
18750 i += 4;
18751 } else if (flags & 0x02) {
18752 arg1 = getInt8(code, i++);
18753 arg2 = getInt8(code, i++);
18754 } else {
18755 arg1 = code[i++];
18756 arg2 = code[i++];
18757 }
18758 if (flags & 0x02) {
18759 x = arg1;
18760 y = arg2;
18761 } else {
18762 x = 0;
18763 y = 0;
18764 }
18765 let scaleX = 1,
18766 scaleY = 1,
18767 scale01 = 0,
18768 scale10 = 0;
18769 if (flags & 0x08) {
18770 scaleX = scaleY = getFloat214(code, i);
18771 i += 2;
18772 } else if (flags & 0x40) {
18773 scaleX = getFloat214(code, i);
18774 scaleY = getFloat214(code, i + 2);
18775 i += 4;
18776 } else if (flags & 0x80) {
18777 scaleX = getFloat214(code, i);
18778 scale01 = getFloat214(code, i + 2);
18779 scale10 = getFloat214(code, i + 4);
18780 scaleY = getFloat214(code, i + 6);
18781 i += 8;
18782 }
18783 const subglyph = font.glyphs[glyphIndex];
18784 if (subglyph) {
18785 cmds.push({
18786 cmd: "save"
18787 }, {
18788 cmd: "transform",
18789 args: [scaleX, scale01, scale10, scaleY, x, y]
18790 });
18791 if (!(flags & 0x02)) {}
18792 compileGlyf(subglyph, cmds, font);
18793 cmds.push({
18794 cmd: "restore"
18795 });
18796 }
18797 } while (flags & 0x20);
18798 } else {
18799 const endPtsOfContours = [];
18800 let j, jj;
18801 for (j = 0; j < numberOfContours; j++) {
18802 endPtsOfContours.push(getUint16(code, i));
18803 i += 2;
18804 }
18805 const instructionLength = getUint16(code, i);
18806 i += 2 + instructionLength;
18807 const numberOfPoints = endPtsOfContours.at(-1) + 1;
18808 const points = [];
18809 while (points.length < numberOfPoints) {
18810 flags = code[i++];
18811 let repeat = 1;
18812 if (flags & 0x08) {
18813 repeat += code[i++];
18814 }
18815 while (repeat-- > 0) {
18816 points.push({
18817 flags
18818 });
18819 }
18820 }
18821 for (j = 0; j < numberOfPoints; j++) {
18822 switch (points[j].flags & 0x12) {
18823 case 0x00:
18824 x += getInt16(code, i);
18825 i += 2;
18826 break;
18827 case 0x02:
18828 x -= code[i++];
18829 break;
18830 case 0x12:
18831 x += code[i++];
18832 break;
18833 }
18834 points[j].x = x;
18835 }
18836 for (j = 0; j < numberOfPoints; j++) {
18837 switch (points[j].flags & 0x24) {
18838 case 0x00:
18839 y += getInt16(code, i);
18840 i += 2;
18841 break;
18842 case 0x04:
18843 y -= code[i++];
18844 break;
18845 case 0x24:
18846 y += code[i++];
18847 break;
18848 }
18849 points[j].y = y;
18850 }
18851 let startPoint = 0;
18852 for (i = 0; i < numberOfContours; i++) {
18853 const endPoint = endPtsOfContours[i];
18854 const contour = points.slice(startPoint, endPoint + 1);
18855 if (contour[0].flags & 1) {
18856 contour.push(contour[0]);
18857 } else if (contour.at(-1).flags & 1) {
18858 contour.unshift(contour.at(-1));
18859 } else {
18860 const p = {
18861 flags: 1,
18862 x: (contour[0].x + contour.at(-1).x) / 2,
18863 y: (contour[0].y + contour.at(-1).y) / 2
18864 };
18865 contour.unshift(p);
18866 contour.push(p);
18867 }
18868 moveTo(contour[0].x, contour[0].y);
18869 for (j = 1, jj = contour.length; j < jj; j++) {
18870 if (contour[j].flags & 1) {
18871 lineTo(contour[j].x, contour[j].y);
18872 } else if (contour[j + 1].flags & 1) {
18873 quadraticCurveTo(contour[j].x, contour[j].y, contour[j + 1].x, contour[j + 1].y);
18874 j++;
18875 } else {
18876 quadraticCurveTo(contour[j].x, contour[j].y, (contour[j].x + contour[j + 1].x) / 2, (contour[j].y + contour[j + 1].y) / 2);
18877 }
18878 }
18879 startPoint = endPoint + 1;
18880 }
18881 }
18882}
18883function compileCharString(charStringCode, cmds, font, glyphId) {
18884 function moveTo(x, y) {
18885 cmds.push({
18886 cmd: "moveTo",
18887 args: [x, y]
18888 });
18889 }
18890 function lineTo(x, y) {
18891 cmds.push({
18892 cmd: "lineTo",
18893 args: [x, y]
18894 });
18895 }
18896 function bezierCurveTo(x1, y1, x2, y2, x, y) {
18897 cmds.push({
18898 cmd: "bezierCurveTo",
18899 args: [x1, y1, x2, y2, x, y]
18900 });
18901 }
18902 const stack = [];
18903 let x = 0,
18904 y = 0;
18905 let stems = 0;
18906 function parse(code) {
18907 let i = 0;
18908 while (i < code.length) {
18909 let stackClean = false;
18910 let v = code[i++];
18911 let xa, xb, ya, yb, y1, y2, y3, n, subrCode;
18912 switch (v) {
18913 case 1:
18914 stems += stack.length >> 1;
18915 stackClean = true;
18916 break;
18917 case 3:
18918 stems += stack.length >> 1;
18919 stackClean = true;
18920 break;
18921 case 4:
18922 y += stack.pop();
18923 moveTo(x, y);
18924 stackClean = true;
18925 break;
18926 case 5:
18927 while (stack.length > 0) {
18928 x += stack.shift();
18929 y += stack.shift();
18930 lineTo(x, y);
18931 }
18932 break;
18933 case 6:
18934 while (stack.length > 0) {
18935 x += stack.shift();
18936 lineTo(x, y);
18937 if (stack.length === 0) {
18938 break;
18939 }
18940 y += stack.shift();
18941 lineTo(x, y);
18942 }
18943 break;
18944 case 7:
18945 while (stack.length > 0) {
18946 y += stack.shift();
18947 lineTo(x, y);
18948 if (stack.length === 0) {
18949 break;
18950 }
18951 x += stack.shift();
18952 lineTo(x, y);
18953 }
18954 break;
18955 case 8:
18956 while (stack.length > 0) {
18957 xa = x + stack.shift();
18958 ya = y + stack.shift();
18959 xb = xa + stack.shift();
18960 yb = ya + stack.shift();
18961 x = xb + stack.shift();
18962 y = yb + stack.shift();
18963 bezierCurveTo(xa, ya, xb, yb, x, y);
18964 }
18965 break;
18966 case 10:
18967 n = stack.pop();
18968 subrCode = null;
18969 if (font.isCFFCIDFont) {
18970 const fdIndex = font.fdSelect.getFDIndex(glyphId);
18971 if (fdIndex >= 0 && fdIndex < font.fdArray.length) {
18972 const fontDict = font.fdArray[fdIndex];
18973 let subrs;
18974 if (fontDict.privateDict?.subrsIndex) {
18975 subrs = fontDict.privateDict.subrsIndex.objects;
18976 }
18977 if (subrs) {
18978 n += getSubroutineBias(subrs);
18979 subrCode = subrs[n];
18980 }
18981 } else {
18982 warn("Invalid fd index for glyph index.");
18983 }
18984 } else {
18985 subrCode = font.subrs[n + font.subrsBias];
18986 }
18987 if (subrCode) {
18988 parse(subrCode);
18989 }
18990 break;
18991 case 11:
18992 return;
18993 case 12:
18994 v = code[i++];
18995 switch (v) {
18996 case 34:
18997 xa = x + stack.shift();
18998 xb = xa + stack.shift();
18999 y1 = y + stack.shift();
19000 x = xb + stack.shift();
19001 bezierCurveTo(xa, y, xb, y1, x, y1);
19002 xa = x + stack.shift();
19003 xb = xa + stack.shift();
19004 x = xb + stack.shift();
19005 bezierCurveTo(xa, y1, xb, y, x, y);
19006 break;
19007 case 35:
19008 xa = x + stack.shift();
19009 ya = y + stack.shift();
19010 xb = xa + stack.shift();
19011 yb = ya + stack.shift();
19012 x = xb + stack.shift();
19013 y = yb + stack.shift();
19014 bezierCurveTo(xa, ya, xb, yb, x, y);
19015 xa = x + stack.shift();
19016 ya = y + stack.shift();
19017 xb = xa + stack.shift();
19018 yb = ya + stack.shift();
19019 x = xb + stack.shift();
19020 y = yb + stack.shift();
19021 bezierCurveTo(xa, ya, xb, yb, x, y);
19022 stack.pop();
19023 break;
19024 case 36:
19025 xa = x + stack.shift();
19026 y1 = y + stack.shift();
19027 xb = xa + stack.shift();
19028 y2 = y1 + stack.shift();
19029 x = xb + stack.shift();
19030 bezierCurveTo(xa, y1, xb, y2, x, y2);
19031 xa = x + stack.shift();
19032 xb = xa + stack.shift();
19033 y3 = y2 + stack.shift();
19034 x = xb + stack.shift();
19035 bezierCurveTo(xa, y2, xb, y3, x, y);
19036 break;
19037 case 37:
19038 const x0 = x,
19039 y0 = y;
19040 xa = x + stack.shift();
19041 ya = y + stack.shift();
19042 xb = xa + stack.shift();
19043 yb = ya + stack.shift();
19044 x = xb + stack.shift();
19045 y = yb + stack.shift();
19046 bezierCurveTo(xa, ya, xb, yb, x, y);
19047 xa = x + stack.shift();
19048 ya = y + stack.shift();
19049 xb = xa + stack.shift();
19050 yb = ya + stack.shift();
19051 x = xb;
19052 y = yb;
19053 if (Math.abs(x - x0) > Math.abs(y - y0)) {
19054 x += stack.shift();
19055 } else {
19056 y += stack.shift();
19057 }
19058 bezierCurveTo(xa, ya, xb, yb, x, y);
19059 break;
19060 default:
19061 throw new FormatError(`unknown operator: 12 ${v}`);
19062 }
19063 break;
19064 case 14:
19065 if (stack.length >= 4) {
19066 const achar = stack.pop();
19067 const bchar = stack.pop();
19068 y = stack.pop();
19069 x = stack.pop();
19070 cmds.push({
19071 cmd: "save"
19072 }, {
19073 cmd: "translate",
19074 args: [x, y]
19075 });
19076 let cmap = lookupCmap(font.cmap, String.fromCharCode(font.glyphNameMap[StandardEncoding[achar]]));
19077 compileCharString(font.glyphs[cmap.glyphId], cmds, font, cmap.glyphId);
19078 cmds.push({
19079 cmd: "restore"
19080 });
19081 cmap = lookupCmap(font.cmap, String.fromCharCode(font.glyphNameMap[StandardEncoding[bchar]]));
19082 compileCharString(font.glyphs[cmap.glyphId], cmds, font, cmap.glyphId);
19083 }
19084 return;
19085 case 18:
19086 stems += stack.length >> 1;
19087 stackClean = true;
19088 break;
19089 case 19:
19090 stems += stack.length >> 1;
19091 i += stems + 7 >> 3;
19092 stackClean = true;
19093 break;
19094 case 20:
19095 stems += stack.length >> 1;
19096 i += stems + 7 >> 3;
19097 stackClean = true;
19098 break;
19099 case 21:
19100 y += stack.pop();
19101 x += stack.pop();
19102 moveTo(x, y);
19103 stackClean = true;
19104 break;
19105 case 22:
19106 x += stack.pop();
19107 moveTo(x, y);
19108 stackClean = true;
19109 break;
19110 case 23:
19111 stems += stack.length >> 1;
19112 stackClean = true;
19113 break;
19114 case 24:
19115 while (stack.length > 2) {
19116 xa = x + stack.shift();
19117 ya = y + stack.shift();
19118 xb = xa + stack.shift();
19119 yb = ya + stack.shift();
19120 x = xb + stack.shift();
19121 y = yb + stack.shift();
19122 bezierCurveTo(xa, ya, xb, yb, x, y);
19123 }
19124 x += stack.shift();
19125 y += stack.shift();
19126 lineTo(x, y);
19127 break;
19128 case 25:
19129 while (stack.length > 6) {
19130 x += stack.shift();
19131 y += stack.shift();
19132 lineTo(x, y);
19133 }
19134 xa = x + stack.shift();
19135 ya = y + stack.shift();
19136 xb = xa + stack.shift();
19137 yb = ya + stack.shift();
19138 x = xb + stack.shift();
19139 y = yb + stack.shift();
19140 bezierCurveTo(xa, ya, xb, yb, x, y);
19141 break;
19142 case 26:
19143 if (stack.length % 2) {
19144 x += stack.shift();
19145 }
19146 while (stack.length > 0) {
19147 xa = x;
19148 ya = y + stack.shift();
19149 xb = xa + stack.shift();
19150 yb = ya + stack.shift();
19151 x = xb;
19152 y = yb + stack.shift();
19153 bezierCurveTo(xa, ya, xb, yb, x, y);
19154 }
19155 break;
19156 case 27:
19157 if (stack.length % 2) {
19158 y += stack.shift();
19159 }
19160 while (stack.length > 0) {
19161 xa = x + stack.shift();
19162 ya = y;
19163 xb = xa + stack.shift();
19164 yb = ya + stack.shift();
19165 x = xb + stack.shift();
19166 y = yb;
19167 bezierCurveTo(xa, ya, xb, yb, x, y);
19168 }
19169 break;
19170 case 28:
19171 stack.push((code[i] << 24 | code[i + 1] << 16) >> 16);
19172 i += 2;
19173 break;
19174 case 29:
19175 n = stack.pop() + font.gsubrsBias;
19176 subrCode = font.gsubrs[n];
19177 if (subrCode) {
19178 parse(subrCode);
19179 }
19180 break;
19181 case 30:
19182 while (stack.length > 0) {
19183 xa = x;
19184 ya = y + stack.shift();
19185 xb = xa + stack.shift();
19186 yb = ya + stack.shift();
19187 x = xb + stack.shift();
19188 y = yb + (stack.length === 1 ? stack.shift() : 0);
19189 bezierCurveTo(xa, ya, xb, yb, x, y);
19190 if (stack.length === 0) {
19191 break;
19192 }
19193 xa = x + stack.shift();
19194 ya = y;
19195 xb = xa + stack.shift();
19196 yb = ya + stack.shift();
19197 y = yb + stack.shift();
19198 x = xb + (stack.length === 1 ? stack.shift() : 0);
19199 bezierCurveTo(xa, ya, xb, yb, x, y);
19200 }
19201 break;
19202 case 31:
19203 while (stack.length > 0) {
19204 xa = x + stack.shift();
19205 ya = y;
19206 xb = xa + stack.shift();
19207 yb = ya + stack.shift();
19208 y = yb + stack.shift();
19209 x = xb + (stack.length === 1 ? stack.shift() : 0);
19210 bezierCurveTo(xa, ya, xb, yb, x, y);
19211 if (stack.length === 0) {
19212 break;
19213 }
19214 xa = x;
19215 ya = y + stack.shift();
19216 xb = xa + stack.shift();
19217 yb = ya + stack.shift();
19218 x = xb + stack.shift();
19219 y = yb + (stack.length === 1 ? stack.shift() : 0);
19220 bezierCurveTo(xa, ya, xb, yb, x, y);
19221 }
19222 break;
19223 default:
19224 if (v < 32) {
19225 throw new FormatError(`unknown operator: ${v}`);
19226 }
19227 if (v < 247) {
19228 stack.push(v - 139);
19229 } else if (v < 251) {
19230 stack.push((v - 247) * 256 + code[i++] + 108);
19231 } else if (v < 255) {
19232 stack.push(-(v - 251) * 256 - code[i++] - 108);
19233 } else {
19234 stack.push((code[i] << 24 | code[i + 1] << 16 | code[i + 2] << 8 | code[i + 3]) / 65536);
19235 i += 4;
19236 }
19237 break;
19238 }
19239 if (stackClean) {
19240 stack.length = 0;
19241 }
19242 }
19243 }
19244 parse(charStringCode);
19245}
19246const NOOP = [];
19247class CompiledFont {
19248 constructor(fontMatrix) {
19249 if (this.constructor === CompiledFont) {
19250 unreachable("Cannot initialize CompiledFont.");
19251 }
19252 this.fontMatrix = fontMatrix;
19253 this.compiledGlyphs = Object.create(null);
19254 this.compiledCharCodeToGlyphId = Object.create(null);
19255 }
19256 getPathJs(unicode) {
19257 const {
19258 charCode,
19259 glyphId
19260 } = lookupCmap(this.cmap, unicode);
19261 let fn = this.compiledGlyphs[glyphId];
19262 if (!fn) {
19263 try {
19264 fn = this.compileGlyph(this.glyphs[glyphId], glyphId);
19265 this.compiledGlyphs[glyphId] = fn;
19266 } catch (ex) {
19267 this.compiledGlyphs[glyphId] = NOOP;
19268 if (this.compiledCharCodeToGlyphId[charCode] === undefined) {
19269 this.compiledCharCodeToGlyphId[charCode] = glyphId;
19270 }
19271 throw ex;
19272 }
19273 }
19274 if (this.compiledCharCodeToGlyphId[charCode] === undefined) {
19275 this.compiledCharCodeToGlyphId[charCode] = glyphId;
19276 }
19277 return fn;
19278 }
19279 compileGlyph(code, glyphId) {
19280 if (!code || code.length === 0 || code[0] === 14) {
19281 return NOOP;
19282 }
19283 let fontMatrix = this.fontMatrix;
19284 if (this.isCFFCIDFont) {
19285 const fdIndex = this.fdSelect.getFDIndex(glyphId);
19286 if (fdIndex >= 0 && fdIndex < this.fdArray.length) {
19287 const fontDict = this.fdArray[fdIndex];
19288 fontMatrix = fontDict.getByName("FontMatrix") || FONT_IDENTITY_MATRIX;
19289 } else {
19290 warn("Invalid fd index for glyph index.");
19291 }
19292 }
19293 const cmds = [{
19294 cmd: "save"
19295 }, {
19296 cmd: "transform",
19297 args: fontMatrix.slice()
19298 }, {
19299 cmd: "scale",
19300 args: ["size", "-size"]
19301 }];
19302 this.compileGlyphImpl(code, cmds, glyphId);
19303 cmds.push({
19304 cmd: "restore"
19305 });
19306 return cmds;
19307 }
19308 compileGlyphImpl() {
19309 unreachable("Children classes should implement this.");
19310 }
19311 hasBuiltPath(unicode) {
19312 const {
19313 charCode,
19314 glyphId
19315 } = lookupCmap(this.cmap, unicode);
19316 return this.compiledGlyphs[glyphId] !== undefined && this.compiledCharCodeToGlyphId[charCode] !== undefined;
19317 }
19318}
19319class TrueTypeCompiled extends CompiledFont {
19320 constructor(glyphs, cmap, fontMatrix) {
19321 super(fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0]);
19322 this.glyphs = glyphs;
19323 this.cmap = cmap;
19324 }
19325 compileGlyphImpl(code, cmds) {
19326 compileGlyf(code, cmds, this);
19327 }
19328}
19329class Type2Compiled extends CompiledFont {
19330 constructor(cffInfo, cmap, fontMatrix, glyphNameMap) {
19331 super(fontMatrix || [0.001, 0, 0, 0.001, 0, 0]);
19332 this.glyphs = cffInfo.glyphs;
19333 this.gsubrs = cffInfo.gsubrs || [];
19334 this.subrs = cffInfo.subrs || [];
19335 this.cmap = cmap;
19336 this.glyphNameMap = glyphNameMap || getGlyphsUnicode();
19337 this.gsubrsBias = getSubroutineBias(this.gsubrs);
19338 this.subrsBias = getSubroutineBias(this.subrs);
19339 this.isCFFCIDFont = cffInfo.isCFFCIDFont;
19340 this.fdSelect = cffInfo.fdSelect;
19341 this.fdArray = cffInfo.fdArray;
19342 }
19343 compileGlyphImpl(code, cmds, glyphId) {
19344 compileCharString(code, cmds, this, glyphId);
19345 }
19346}
19347class FontRendererFactory {
19348 static create(font, seacAnalysisEnabled) {
19349 const data = new Uint8Array(font.data);
19350 let cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
19351 const numTables = getUint16(data, 4);
19352 for (let i = 0, p = 12; i < numTables; i++, p += 16) {
19353 const tag = bytesToString(data.subarray(p, p + 4));
19354 const offset = getUint32(data, p + 8);
19355 const length = getUint32(data, p + 12);
19356 switch (tag) {
19357 case "cmap":
19358 cmap = parseCmap(data, offset, offset + length);
19359 break;
19360 case "glyf":
19361 glyf = data.subarray(offset, offset + length);
19362 break;
19363 case "loca":
19364 loca = data.subarray(offset, offset + length);
19365 break;
19366 case "head":
19367 unitsPerEm = getUint16(data, offset + 18);
19368 indexToLocFormat = getUint16(data, offset + 50);
19369 break;
19370 case "CFF ":
19371 cff = parseCff(data, offset, offset + length, seacAnalysisEnabled);
19372 break;
19373 }
19374 }
19375 if (glyf) {
19376 const fontMatrix = !unitsPerEm ? font.fontMatrix : [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0];
19377 return new TrueTypeCompiled(parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
19378 }
19379 return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
19380 }
19381}
19382
19383;// CONCATENATED MODULE: ./src/core/metrics.js
19384
19385const getMetrics = getLookupTableFactory(function (t) {
19386 t.Courier = 600;
19387 t["Courier-Bold"] = 600;
19388 t["Courier-BoldOblique"] = 600;
19389 t["Courier-Oblique"] = 600;
19390 t.Helvetica = getLookupTableFactory(function (t) {
19391 t.space = 278;
19392 t.exclam = 278;
19393 t.quotedbl = 355;
19394 t.numbersign = 556;
19395 t.dollar = 556;
19396 t.percent = 889;
19397 t.ampersand = 667;
19398 t.quoteright = 222;
19399 t.parenleft = 333;
19400 t.parenright = 333;
19401 t.asterisk = 389;
19402 t.plus = 584;
19403 t.comma = 278;
19404 t.hyphen = 333;
19405 t.period = 278;
19406 t.slash = 278;
19407 t.zero = 556;
19408 t.one = 556;
19409 t.two = 556;
19410 t.three = 556;
19411 t.four = 556;
19412 t.five = 556;
19413 t.six = 556;
19414 t.seven = 556;
19415 t.eight = 556;
19416 t.nine = 556;
19417 t.colon = 278;
19418 t.semicolon = 278;
19419 t.less = 584;
19420 t.equal = 584;
19421 t.greater = 584;
19422 t.question = 556;
19423 t.at = 1015;
19424 t.A = 667;
19425 t.B = 667;
19426 t.C = 722;
19427 t.D = 722;
19428 t.E = 667;
19429 t.F = 611;
19430 t.G = 778;
19431 t.H = 722;
19432 t.I = 278;
19433 t.J = 500;
19434 t.K = 667;
19435 t.L = 556;
19436 t.M = 833;
19437 t.N = 722;
19438 t.O = 778;
19439 t.P = 667;
19440 t.Q = 778;
19441 t.R = 722;
19442 t.S = 667;
19443 t.T = 611;
19444 t.U = 722;
19445 t.V = 667;
19446 t.W = 944;
19447 t.X = 667;
19448 t.Y = 667;
19449 t.Z = 611;
19450 t.bracketleft = 278;
19451 t.backslash = 278;
19452 t.bracketright = 278;
19453 t.asciicircum = 469;
19454 t.underscore = 556;
19455 t.quoteleft = 222;
19456 t.a = 556;
19457 t.b = 556;
19458 t.c = 500;
19459 t.d = 556;
19460 t.e = 556;
19461 t.f = 278;
19462 t.g = 556;
19463 t.h = 556;
19464 t.i = 222;
19465 t.j = 222;
19466 t.k = 500;
19467 t.l = 222;
19468 t.m = 833;
19469 t.n = 556;
19470 t.o = 556;
19471 t.p = 556;
19472 t.q = 556;
19473 t.r = 333;
19474 t.s = 500;
19475 t.t = 278;
19476 t.u = 556;
19477 t.v = 500;
19478 t.w = 722;
19479 t.x = 500;
19480 t.y = 500;
19481 t.z = 500;
19482 t.braceleft = 334;
19483 t.bar = 260;
19484 t.braceright = 334;
19485 t.asciitilde = 584;
19486 t.exclamdown = 333;
19487 t.cent = 556;
19488 t.sterling = 556;
19489 t.fraction = 167;
19490 t.yen = 556;
19491 t.florin = 556;
19492 t.section = 556;
19493 t.currency = 556;
19494 t.quotesingle = 191;
19495 t.quotedblleft = 333;
19496 t.guillemotleft = 556;
19497 t.guilsinglleft = 333;
19498 t.guilsinglright = 333;
19499 t.fi = 500;
19500 t.fl = 500;
19501 t.endash = 556;
19502 t.dagger = 556;
19503 t.daggerdbl = 556;
19504 t.periodcentered = 278;
19505 t.paragraph = 537;
19506 t.bullet = 350;
19507 t.quotesinglbase = 222;
19508 t.quotedblbase = 333;
19509 t.quotedblright = 333;
19510 t.guillemotright = 556;
19511 t.ellipsis = 1000;
19512 t.perthousand = 1000;
19513 t.questiondown = 611;
19514 t.grave = 333;
19515 t.acute = 333;
19516 t.circumflex = 333;
19517 t.tilde = 333;
19518 t.macron = 333;
19519 t.breve = 333;
19520 t.dotaccent = 333;
19521 t.dieresis = 333;
19522 t.ring = 333;
19523 t.cedilla = 333;
19524 t.hungarumlaut = 333;
19525 t.ogonek = 333;
19526 t.caron = 333;
19527 t.emdash = 1000;
19528 t.AE = 1000;
19529 t.ordfeminine = 370;
19530 t.Lslash = 556;
19531 t.Oslash = 778;
19532 t.OE = 1000;
19533 t.ordmasculine = 365;
19534 t.ae = 889;
19535 t.dotlessi = 278;
19536 t.lslash = 222;
19537 t.oslash = 611;
19538 t.oe = 944;
19539 t.germandbls = 611;
19540 t.Idieresis = 278;
19541 t.eacute = 556;
19542 t.abreve = 556;
19543 t.uhungarumlaut = 556;
19544 t.ecaron = 556;
19545 t.Ydieresis = 667;
19546 t.divide = 584;
19547 t.Yacute = 667;
19548 t.Acircumflex = 667;
19549 t.aacute = 556;
19550 t.Ucircumflex = 722;
19551 t.yacute = 500;
19552 t.scommaaccent = 500;
19553 t.ecircumflex = 556;
19554 t.Uring = 722;
19555 t.Udieresis = 722;
19556 t.aogonek = 556;
19557 t.Uacute = 722;
19558 t.uogonek = 556;
19559 t.Edieresis = 667;
19560 t.Dcroat = 722;
19561 t.commaaccent = 250;
19562 t.copyright = 737;
19563 t.Emacron = 667;
19564 t.ccaron = 500;
19565 t.aring = 556;
19566 t.Ncommaaccent = 722;
19567 t.lacute = 222;
19568 t.agrave = 556;
19569 t.Tcommaaccent = 611;
19570 t.Cacute = 722;
19571 t.atilde = 556;
19572 t.Edotaccent = 667;
19573 t.scaron = 500;
19574 t.scedilla = 500;
19575 t.iacute = 278;
19576 t.lozenge = 471;
19577 t.Rcaron = 722;
19578 t.Gcommaaccent = 778;
19579 t.ucircumflex = 556;
19580 t.acircumflex = 556;
19581 t.Amacron = 667;
19582 t.rcaron = 333;
19583 t.ccedilla = 500;
19584 t.Zdotaccent = 611;
19585 t.Thorn = 667;
19586 t.Omacron = 778;
19587 t.Racute = 722;
19588 t.Sacute = 667;
19589 t.dcaron = 643;
19590 t.Umacron = 722;
19591 t.uring = 556;
19592 t.threesuperior = 333;
19593 t.Ograve = 778;
19594 t.Agrave = 667;
19595 t.Abreve = 667;
19596 t.multiply = 584;
19597 t.uacute = 556;
19598 t.Tcaron = 611;
19599 t.partialdiff = 476;
19600 t.ydieresis = 500;
19601 t.Nacute = 722;
19602 t.icircumflex = 278;
19603 t.Ecircumflex = 667;
19604 t.adieresis = 556;
19605 t.edieresis = 556;
19606 t.cacute = 500;
19607 t.nacute = 556;
19608 t.umacron = 556;
19609 t.Ncaron = 722;
19610 t.Iacute = 278;
19611 t.plusminus = 584;
19612 t.brokenbar = 260;
19613 t.registered = 737;
19614 t.Gbreve = 778;
19615 t.Idotaccent = 278;
19616 t.summation = 600;
19617 t.Egrave = 667;
19618 t.racute = 333;
19619 t.omacron = 556;
19620 t.Zacute = 611;
19621 t.Zcaron = 611;
19622 t.greaterequal = 549;
19623 t.Eth = 722;
19624 t.Ccedilla = 722;
19625 t.lcommaaccent = 222;
19626 t.tcaron = 317;
19627 t.eogonek = 556;
19628 t.Uogonek = 722;
19629 t.Aacute = 667;
19630 t.Adieresis = 667;
19631 t.egrave = 556;
19632 t.zacute = 500;
19633 t.iogonek = 222;
19634 t.Oacute = 778;
19635 t.oacute = 556;
19636 t.amacron = 556;
19637 t.sacute = 500;
19638 t.idieresis = 278;
19639 t.Ocircumflex = 778;
19640 t.Ugrave = 722;
19641 t.Delta = 612;
19642 t.thorn = 556;
19643 t.twosuperior = 333;
19644 t.Odieresis = 778;
19645 t.mu = 556;
19646 t.igrave = 278;
19647 t.ohungarumlaut = 556;
19648 t.Eogonek = 667;
19649 t.dcroat = 556;
19650 t.threequarters = 834;
19651 t.Scedilla = 667;
19652 t.lcaron = 299;
19653 t.Kcommaaccent = 667;
19654 t.Lacute = 556;
19655 t.trademark = 1000;
19656 t.edotaccent = 556;
19657 t.Igrave = 278;
19658 t.Imacron = 278;
19659 t.Lcaron = 556;
19660 t.onehalf = 834;
19661 t.lessequal = 549;
19662 t.ocircumflex = 556;
19663 t.ntilde = 556;
19664 t.Uhungarumlaut = 722;
19665 t.Eacute = 667;
19666 t.emacron = 556;
19667 t.gbreve = 556;
19668 t.onequarter = 834;
19669 t.Scaron = 667;
19670 t.Scommaaccent = 667;
19671 t.Ohungarumlaut = 778;
19672 t.degree = 400;
19673 t.ograve = 556;
19674 t.Ccaron = 722;
19675 t.ugrave = 556;
19676 t.radical = 453;
19677 t.Dcaron = 722;
19678 t.rcommaaccent = 333;
19679 t.Ntilde = 722;
19680 t.otilde = 556;
19681 t.Rcommaaccent = 722;
19682 t.Lcommaaccent = 556;
19683 t.Atilde = 667;
19684 t.Aogonek = 667;
19685 t.Aring = 667;
19686 t.Otilde = 778;
19687 t.zdotaccent = 500;
19688 t.Ecaron = 667;
19689 t.Iogonek = 278;
19690 t.kcommaaccent = 500;
19691 t.minus = 584;
19692 t.Icircumflex = 278;
19693 t.ncaron = 556;
19694 t.tcommaaccent = 278;
19695 t.logicalnot = 584;
19696 t.odieresis = 556;
19697 t.udieresis = 556;
19698 t.notequal = 549;
19699 t.gcommaaccent = 556;
19700 t.eth = 556;
19701 t.zcaron = 500;
19702 t.ncommaaccent = 556;
19703 t.onesuperior = 333;
19704 t.imacron = 278;
19705 t.Euro = 556;
19706 });
19707 t["Helvetica-Bold"] = getLookupTableFactory(function (t) {
19708 t.space = 278;
19709 t.exclam = 333;
19710 t.quotedbl = 474;
19711 t.numbersign = 556;
19712 t.dollar = 556;
19713 t.percent = 889;
19714 t.ampersand = 722;
19715 t.quoteright = 278;
19716 t.parenleft = 333;
19717 t.parenright = 333;
19718 t.asterisk = 389;
19719 t.plus = 584;
19720 t.comma = 278;
19721 t.hyphen = 333;
19722 t.period = 278;
19723 t.slash = 278;
19724 t.zero = 556;
19725 t.one = 556;
19726 t.two = 556;
19727 t.three = 556;
19728 t.four = 556;
19729 t.five = 556;
19730 t.six = 556;
19731 t.seven = 556;
19732 t.eight = 556;
19733 t.nine = 556;
19734 t.colon = 333;
19735 t.semicolon = 333;
19736 t.less = 584;
19737 t.equal = 584;
19738 t.greater = 584;
19739 t.question = 611;
19740 t.at = 975;
19741 t.A = 722;
19742 t.B = 722;
19743 t.C = 722;
19744 t.D = 722;
19745 t.E = 667;
19746 t.F = 611;
19747 t.G = 778;
19748 t.H = 722;
19749 t.I = 278;
19750 t.J = 556;
19751 t.K = 722;
19752 t.L = 611;
19753 t.M = 833;
19754 t.N = 722;
19755 t.O = 778;
19756 t.P = 667;
19757 t.Q = 778;
19758 t.R = 722;
19759 t.S = 667;
19760 t.T = 611;
19761 t.U = 722;
19762 t.V = 667;
19763 t.W = 944;
19764 t.X = 667;
19765 t.Y = 667;
19766 t.Z = 611;
19767 t.bracketleft = 333;
19768 t.backslash = 278;
19769 t.bracketright = 333;
19770 t.asciicircum = 584;
19771 t.underscore = 556;
19772 t.quoteleft = 278;
19773 t.a = 556;
19774 t.b = 611;
19775 t.c = 556;
19776 t.d = 611;
19777 t.e = 556;
19778 t.f = 333;
19779 t.g = 611;
19780 t.h = 611;
19781 t.i = 278;
19782 t.j = 278;
19783 t.k = 556;
19784 t.l = 278;
19785 t.m = 889;
19786 t.n = 611;
19787 t.o = 611;
19788 t.p = 611;
19789 t.q = 611;
19790 t.r = 389;
19791 t.s = 556;
19792 t.t = 333;
19793 t.u = 611;
19794 t.v = 556;
19795 t.w = 778;
19796 t.x = 556;
19797 t.y = 556;
19798 t.z = 500;
19799 t.braceleft = 389;
19800 t.bar = 280;
19801 t.braceright = 389;
19802 t.asciitilde = 584;
19803 t.exclamdown = 333;
19804 t.cent = 556;
19805 t.sterling = 556;
19806 t.fraction = 167;
19807 t.yen = 556;
19808 t.florin = 556;
19809 t.section = 556;
19810 t.currency = 556;
19811 t.quotesingle = 238;
19812 t.quotedblleft = 500;
19813 t.guillemotleft = 556;
19814 t.guilsinglleft = 333;
19815 t.guilsinglright = 333;
19816 t.fi = 611;
19817 t.fl = 611;
19818 t.endash = 556;
19819 t.dagger = 556;
19820 t.daggerdbl = 556;
19821 t.periodcentered = 278;
19822 t.paragraph = 556;
19823 t.bullet = 350;
19824 t.quotesinglbase = 278;
19825 t.quotedblbase = 500;
19826 t.quotedblright = 500;
19827 t.guillemotright = 556;
19828 t.ellipsis = 1000;
19829 t.perthousand = 1000;
19830 t.questiondown = 611;
19831 t.grave = 333;
19832 t.acute = 333;
19833 t.circumflex = 333;
19834 t.tilde = 333;
19835 t.macron = 333;
19836 t.breve = 333;
19837 t.dotaccent = 333;
19838 t.dieresis = 333;
19839 t.ring = 333;
19840 t.cedilla = 333;
19841 t.hungarumlaut = 333;
19842 t.ogonek = 333;
19843 t.caron = 333;
19844 t.emdash = 1000;
19845 t.AE = 1000;
19846 t.ordfeminine = 370;
19847 t.Lslash = 611;
19848 t.Oslash = 778;
19849 t.OE = 1000;
19850 t.ordmasculine = 365;
19851 t.ae = 889;
19852 t.dotlessi = 278;
19853 t.lslash = 278;
19854 t.oslash = 611;
19855 t.oe = 944;
19856 t.germandbls = 611;
19857 t.Idieresis = 278;
19858 t.eacute = 556;
19859 t.abreve = 556;
19860 t.uhungarumlaut = 611;
19861 t.ecaron = 556;
19862 t.Ydieresis = 667;
19863 t.divide = 584;
19864 t.Yacute = 667;
19865 t.Acircumflex = 722;
19866 t.aacute = 556;
19867 t.Ucircumflex = 722;
19868 t.yacute = 556;
19869 t.scommaaccent = 556;
19870 t.ecircumflex = 556;
19871 t.Uring = 722;
19872 t.Udieresis = 722;
19873 t.aogonek = 556;
19874 t.Uacute = 722;
19875 t.uogonek = 611;
19876 t.Edieresis = 667;
19877 t.Dcroat = 722;
19878 t.commaaccent = 250;
19879 t.copyright = 737;
19880 t.Emacron = 667;
19881 t.ccaron = 556;
19882 t.aring = 556;
19883 t.Ncommaaccent = 722;
19884 t.lacute = 278;
19885 t.agrave = 556;
19886 t.Tcommaaccent = 611;
19887 t.Cacute = 722;
19888 t.atilde = 556;
19889 t.Edotaccent = 667;
19890 t.scaron = 556;
19891 t.scedilla = 556;
19892 t.iacute = 278;
19893 t.lozenge = 494;
19894 t.Rcaron = 722;
19895 t.Gcommaaccent = 778;
19896 t.ucircumflex = 611;
19897 t.acircumflex = 556;
19898 t.Amacron = 722;
19899 t.rcaron = 389;
19900 t.ccedilla = 556;
19901 t.Zdotaccent = 611;
19902 t.Thorn = 667;
19903 t.Omacron = 778;
19904 t.Racute = 722;
19905 t.Sacute = 667;
19906 t.dcaron = 743;
19907 t.Umacron = 722;
19908 t.uring = 611;
19909 t.threesuperior = 333;
19910 t.Ograve = 778;
19911 t.Agrave = 722;
19912 t.Abreve = 722;
19913 t.multiply = 584;
19914 t.uacute = 611;
19915 t.Tcaron = 611;
19916 t.partialdiff = 494;
19917 t.ydieresis = 556;
19918 t.Nacute = 722;
19919 t.icircumflex = 278;
19920 t.Ecircumflex = 667;
19921 t.adieresis = 556;
19922 t.edieresis = 556;
19923 t.cacute = 556;
19924 t.nacute = 611;
19925 t.umacron = 611;
19926 t.Ncaron = 722;
19927 t.Iacute = 278;
19928 t.plusminus = 584;
19929 t.brokenbar = 280;
19930 t.registered = 737;
19931 t.Gbreve = 778;
19932 t.Idotaccent = 278;
19933 t.summation = 600;
19934 t.Egrave = 667;
19935 t.racute = 389;
19936 t.omacron = 611;
19937 t.Zacute = 611;
19938 t.Zcaron = 611;
19939 t.greaterequal = 549;
19940 t.Eth = 722;
19941 t.Ccedilla = 722;
19942 t.lcommaaccent = 278;
19943 t.tcaron = 389;
19944 t.eogonek = 556;
19945 t.Uogonek = 722;
19946 t.Aacute = 722;
19947 t.Adieresis = 722;
19948 t.egrave = 556;
19949 t.zacute = 500;
19950 t.iogonek = 278;
19951 t.Oacute = 778;
19952 t.oacute = 611;
19953 t.amacron = 556;
19954 t.sacute = 556;
19955 t.idieresis = 278;
19956 t.Ocircumflex = 778;
19957 t.Ugrave = 722;
19958 t.Delta = 612;
19959 t.thorn = 611;
19960 t.twosuperior = 333;
19961 t.Odieresis = 778;
19962 t.mu = 611;
19963 t.igrave = 278;
19964 t.ohungarumlaut = 611;
19965 t.Eogonek = 667;
19966 t.dcroat = 611;
19967 t.threequarters = 834;
19968 t.Scedilla = 667;
19969 t.lcaron = 400;
19970 t.Kcommaaccent = 722;
19971 t.Lacute = 611;
19972 t.trademark = 1000;
19973 t.edotaccent = 556;
19974 t.Igrave = 278;
19975 t.Imacron = 278;
19976 t.Lcaron = 611;
19977 t.onehalf = 834;
19978 t.lessequal = 549;
19979 t.ocircumflex = 611;
19980 t.ntilde = 611;
19981 t.Uhungarumlaut = 722;
19982 t.Eacute = 667;
19983 t.emacron = 556;
19984 t.gbreve = 611;
19985 t.onequarter = 834;
19986 t.Scaron = 667;
19987 t.Scommaaccent = 667;
19988 t.Ohungarumlaut = 778;
19989 t.degree = 400;
19990 t.ograve = 611;
19991 t.Ccaron = 722;
19992 t.ugrave = 611;
19993 t.radical = 549;
19994 t.Dcaron = 722;
19995 t.rcommaaccent = 389;
19996 t.Ntilde = 722;
19997 t.otilde = 611;
19998 t.Rcommaaccent = 722;
19999 t.Lcommaaccent = 611;
20000 t.Atilde = 722;
20001 t.Aogonek = 722;
20002 t.Aring = 722;
20003 t.Otilde = 778;
20004 t.zdotaccent = 500;
20005 t.Ecaron = 667;
20006 t.Iogonek = 278;
20007 t.kcommaaccent = 556;
20008 t.minus = 584;
20009 t.Icircumflex = 278;
20010 t.ncaron = 611;
20011 t.tcommaaccent = 333;
20012 t.logicalnot = 584;
20013 t.odieresis = 611;
20014 t.udieresis = 611;
20015 t.notequal = 549;
20016 t.gcommaaccent = 611;
20017 t.eth = 611;
20018 t.zcaron = 500;
20019 t.ncommaaccent = 611;
20020 t.onesuperior = 333;
20021 t.imacron = 278;
20022 t.Euro = 556;
20023 });
20024 t["Helvetica-BoldOblique"] = getLookupTableFactory(function (t) {
20025 t.space = 278;
20026 t.exclam = 333;
20027 t.quotedbl = 474;
20028 t.numbersign = 556;
20029 t.dollar = 556;
20030 t.percent = 889;
20031 t.ampersand = 722;
20032 t.quoteright = 278;
20033 t.parenleft = 333;
20034 t.parenright = 333;
20035 t.asterisk = 389;
20036 t.plus = 584;
20037 t.comma = 278;
20038 t.hyphen = 333;
20039 t.period = 278;
20040 t.slash = 278;
20041 t.zero = 556;
20042 t.one = 556;
20043 t.two = 556;
20044 t.three = 556;
20045 t.four = 556;
20046 t.five = 556;
20047 t.six = 556;
20048 t.seven = 556;
20049 t.eight = 556;
20050 t.nine = 556;
20051 t.colon = 333;
20052 t.semicolon = 333;
20053 t.less = 584;
20054 t.equal = 584;
20055 t.greater = 584;
20056 t.question = 611;
20057 t.at = 975;
20058 t.A = 722;
20059 t.B = 722;
20060 t.C = 722;
20061 t.D = 722;
20062 t.E = 667;
20063 t.F = 611;
20064 t.G = 778;
20065 t.H = 722;
20066 t.I = 278;
20067 t.J = 556;
20068 t.K = 722;
20069 t.L = 611;
20070 t.M = 833;
20071 t.N = 722;
20072 t.O = 778;
20073 t.P = 667;
20074 t.Q = 778;
20075 t.R = 722;
20076 t.S = 667;
20077 t.T = 611;
20078 t.U = 722;
20079 t.V = 667;
20080 t.W = 944;
20081 t.X = 667;
20082 t.Y = 667;
20083 t.Z = 611;
20084 t.bracketleft = 333;
20085 t.backslash = 278;
20086 t.bracketright = 333;
20087 t.asciicircum = 584;
20088 t.underscore = 556;
20089 t.quoteleft = 278;
20090 t.a = 556;
20091 t.b = 611;
20092 t.c = 556;
20093 t.d = 611;
20094 t.e = 556;
20095 t.f = 333;
20096 t.g = 611;
20097 t.h = 611;
20098 t.i = 278;
20099 t.j = 278;
20100 t.k = 556;
20101 t.l = 278;
20102 t.m = 889;
20103 t.n = 611;
20104 t.o = 611;
20105 t.p = 611;
20106 t.q = 611;
20107 t.r = 389;
20108 t.s = 556;
20109 t.t = 333;
20110 t.u = 611;
20111 t.v = 556;
20112 t.w = 778;
20113 t.x = 556;
20114 t.y = 556;
20115 t.z = 500;
20116 t.braceleft = 389;
20117 t.bar = 280;
20118 t.braceright = 389;
20119 t.asciitilde = 584;
20120 t.exclamdown = 333;
20121 t.cent = 556;
20122 t.sterling = 556;
20123 t.fraction = 167;
20124 t.yen = 556;
20125 t.florin = 556;
20126 t.section = 556;
20127 t.currency = 556;
20128 t.quotesingle = 238;
20129 t.quotedblleft = 500;
20130 t.guillemotleft = 556;
20131 t.guilsinglleft = 333;
20132 t.guilsinglright = 333;
20133 t.fi = 611;
20134 t.fl = 611;
20135 t.endash = 556;
20136 t.dagger = 556;
20137 t.daggerdbl = 556;
20138 t.periodcentered = 278;
20139 t.paragraph = 556;
20140 t.bullet = 350;
20141 t.quotesinglbase = 278;
20142 t.quotedblbase = 500;
20143 t.quotedblright = 500;
20144 t.guillemotright = 556;
20145 t.ellipsis = 1000;
20146 t.perthousand = 1000;
20147 t.questiondown = 611;
20148 t.grave = 333;
20149 t.acute = 333;
20150 t.circumflex = 333;
20151 t.tilde = 333;
20152 t.macron = 333;
20153 t.breve = 333;
20154 t.dotaccent = 333;
20155 t.dieresis = 333;
20156 t.ring = 333;
20157 t.cedilla = 333;
20158 t.hungarumlaut = 333;
20159 t.ogonek = 333;
20160 t.caron = 333;
20161 t.emdash = 1000;
20162 t.AE = 1000;
20163 t.ordfeminine = 370;
20164 t.Lslash = 611;
20165 t.Oslash = 778;
20166 t.OE = 1000;
20167 t.ordmasculine = 365;
20168 t.ae = 889;
20169 t.dotlessi = 278;
20170 t.lslash = 278;
20171 t.oslash = 611;
20172 t.oe = 944;
20173 t.germandbls = 611;
20174 t.Idieresis = 278;
20175 t.eacute = 556;
20176 t.abreve = 556;
20177 t.uhungarumlaut = 611;
20178 t.ecaron = 556;
20179 t.Ydieresis = 667;
20180 t.divide = 584;
20181 t.Yacute = 667;
20182 t.Acircumflex = 722;
20183 t.aacute = 556;
20184 t.Ucircumflex = 722;
20185 t.yacute = 556;
20186 t.scommaaccent = 556;
20187 t.ecircumflex = 556;
20188 t.Uring = 722;
20189 t.Udieresis = 722;
20190 t.aogonek = 556;
20191 t.Uacute = 722;
20192 t.uogonek = 611;
20193 t.Edieresis = 667;
20194 t.Dcroat = 722;
20195 t.commaaccent = 250;
20196 t.copyright = 737;
20197 t.Emacron = 667;
20198 t.ccaron = 556;
20199 t.aring = 556;
20200 t.Ncommaaccent = 722;
20201 t.lacute = 278;
20202 t.agrave = 556;
20203 t.Tcommaaccent = 611;
20204 t.Cacute = 722;
20205 t.atilde = 556;
20206 t.Edotaccent = 667;
20207 t.scaron = 556;
20208 t.scedilla = 556;
20209 t.iacute = 278;
20210 t.lozenge = 494;
20211 t.Rcaron = 722;
20212 t.Gcommaaccent = 778;
20213 t.ucircumflex = 611;
20214 t.acircumflex = 556;
20215 t.Amacron = 722;
20216 t.rcaron = 389;
20217 t.ccedilla = 556;
20218 t.Zdotaccent = 611;
20219 t.Thorn = 667;
20220 t.Omacron = 778;
20221 t.Racute = 722;
20222 t.Sacute = 667;
20223 t.dcaron = 743;
20224 t.Umacron = 722;
20225 t.uring = 611;
20226 t.threesuperior = 333;
20227 t.Ograve = 778;
20228 t.Agrave = 722;
20229 t.Abreve = 722;
20230 t.multiply = 584;
20231 t.uacute = 611;
20232 t.Tcaron = 611;
20233 t.partialdiff = 494;
20234 t.ydieresis = 556;
20235 t.Nacute = 722;
20236 t.icircumflex = 278;
20237 t.Ecircumflex = 667;
20238 t.adieresis = 556;
20239 t.edieresis = 556;
20240 t.cacute = 556;
20241 t.nacute = 611;
20242 t.umacron = 611;
20243 t.Ncaron = 722;
20244 t.Iacute = 278;
20245 t.plusminus = 584;
20246 t.brokenbar = 280;
20247 t.registered = 737;
20248 t.Gbreve = 778;
20249 t.Idotaccent = 278;
20250 t.summation = 600;
20251 t.Egrave = 667;
20252 t.racute = 389;
20253 t.omacron = 611;
20254 t.Zacute = 611;
20255 t.Zcaron = 611;
20256 t.greaterequal = 549;
20257 t.Eth = 722;
20258 t.Ccedilla = 722;
20259 t.lcommaaccent = 278;
20260 t.tcaron = 389;
20261 t.eogonek = 556;
20262 t.Uogonek = 722;
20263 t.Aacute = 722;
20264 t.Adieresis = 722;
20265 t.egrave = 556;
20266 t.zacute = 500;
20267 t.iogonek = 278;
20268 t.Oacute = 778;
20269 t.oacute = 611;
20270 t.amacron = 556;
20271 t.sacute = 556;
20272 t.idieresis = 278;
20273 t.Ocircumflex = 778;
20274 t.Ugrave = 722;
20275 t.Delta = 612;
20276 t.thorn = 611;
20277 t.twosuperior = 333;
20278 t.Odieresis = 778;
20279 t.mu = 611;
20280 t.igrave = 278;
20281 t.ohungarumlaut = 611;
20282 t.Eogonek = 667;
20283 t.dcroat = 611;
20284 t.threequarters = 834;
20285 t.Scedilla = 667;
20286 t.lcaron = 400;
20287 t.Kcommaaccent = 722;
20288 t.Lacute = 611;
20289 t.trademark = 1000;
20290 t.edotaccent = 556;
20291 t.Igrave = 278;
20292 t.Imacron = 278;
20293 t.Lcaron = 611;
20294 t.onehalf = 834;
20295 t.lessequal = 549;
20296 t.ocircumflex = 611;
20297 t.ntilde = 611;
20298 t.Uhungarumlaut = 722;
20299 t.Eacute = 667;
20300 t.emacron = 556;
20301 t.gbreve = 611;
20302 t.onequarter = 834;
20303 t.Scaron = 667;
20304 t.Scommaaccent = 667;
20305 t.Ohungarumlaut = 778;
20306 t.degree = 400;
20307 t.ograve = 611;
20308 t.Ccaron = 722;
20309 t.ugrave = 611;
20310 t.radical = 549;
20311 t.Dcaron = 722;
20312 t.rcommaaccent = 389;
20313 t.Ntilde = 722;
20314 t.otilde = 611;
20315 t.Rcommaaccent = 722;
20316 t.Lcommaaccent = 611;
20317 t.Atilde = 722;
20318 t.Aogonek = 722;
20319 t.Aring = 722;
20320 t.Otilde = 778;
20321 t.zdotaccent = 500;
20322 t.Ecaron = 667;
20323 t.Iogonek = 278;
20324 t.kcommaaccent = 556;
20325 t.minus = 584;
20326 t.Icircumflex = 278;
20327 t.ncaron = 611;
20328 t.tcommaaccent = 333;
20329 t.logicalnot = 584;
20330 t.odieresis = 611;
20331 t.udieresis = 611;
20332 t.notequal = 549;
20333 t.gcommaaccent = 611;
20334 t.eth = 611;
20335 t.zcaron = 500;
20336 t.ncommaaccent = 611;
20337 t.onesuperior = 333;
20338 t.imacron = 278;
20339 t.Euro = 556;
20340 });
20341 t["Helvetica-Oblique"] = getLookupTableFactory(function (t) {
20342 t.space = 278;
20343 t.exclam = 278;
20344 t.quotedbl = 355;
20345 t.numbersign = 556;
20346 t.dollar = 556;
20347 t.percent = 889;
20348 t.ampersand = 667;
20349 t.quoteright = 222;
20350 t.parenleft = 333;
20351 t.parenright = 333;
20352 t.asterisk = 389;
20353 t.plus = 584;
20354 t.comma = 278;
20355 t.hyphen = 333;
20356 t.period = 278;
20357 t.slash = 278;
20358 t.zero = 556;
20359 t.one = 556;
20360 t.two = 556;
20361 t.three = 556;
20362 t.four = 556;
20363 t.five = 556;
20364 t.six = 556;
20365 t.seven = 556;
20366 t.eight = 556;
20367 t.nine = 556;
20368 t.colon = 278;
20369 t.semicolon = 278;
20370 t.less = 584;
20371 t.equal = 584;
20372 t.greater = 584;
20373 t.question = 556;
20374 t.at = 1015;
20375 t.A = 667;
20376 t.B = 667;
20377 t.C = 722;
20378 t.D = 722;
20379 t.E = 667;
20380 t.F = 611;
20381 t.G = 778;
20382 t.H = 722;
20383 t.I = 278;
20384 t.J = 500;
20385 t.K = 667;
20386 t.L = 556;
20387 t.M = 833;
20388 t.N = 722;
20389 t.O = 778;
20390 t.P = 667;
20391 t.Q = 778;
20392 t.R = 722;
20393 t.S = 667;
20394 t.T = 611;
20395 t.U = 722;
20396 t.V = 667;
20397 t.W = 944;
20398 t.X = 667;
20399 t.Y = 667;
20400 t.Z = 611;
20401 t.bracketleft = 278;
20402 t.backslash = 278;
20403 t.bracketright = 278;
20404 t.asciicircum = 469;
20405 t.underscore = 556;
20406 t.quoteleft = 222;
20407 t.a = 556;
20408 t.b = 556;
20409 t.c = 500;
20410 t.d = 556;
20411 t.e = 556;
20412 t.f = 278;
20413 t.g = 556;
20414 t.h = 556;
20415 t.i = 222;
20416 t.j = 222;
20417 t.k = 500;
20418 t.l = 222;
20419 t.m = 833;
20420 t.n = 556;
20421 t.o = 556;
20422 t.p = 556;
20423 t.q = 556;
20424 t.r = 333;
20425 t.s = 500;
20426 t.t = 278;
20427 t.u = 556;
20428 t.v = 500;
20429 t.w = 722;
20430 t.x = 500;
20431 t.y = 500;
20432 t.z = 500;
20433 t.braceleft = 334;
20434 t.bar = 260;
20435 t.braceright = 334;
20436 t.asciitilde = 584;
20437 t.exclamdown = 333;
20438 t.cent = 556;
20439 t.sterling = 556;
20440 t.fraction = 167;
20441 t.yen = 556;
20442 t.florin = 556;
20443 t.section = 556;
20444 t.currency = 556;
20445 t.quotesingle = 191;
20446 t.quotedblleft = 333;
20447 t.guillemotleft = 556;
20448 t.guilsinglleft = 333;
20449 t.guilsinglright = 333;
20450 t.fi = 500;
20451 t.fl = 500;
20452 t.endash = 556;
20453 t.dagger = 556;
20454 t.daggerdbl = 556;
20455 t.periodcentered = 278;
20456 t.paragraph = 537;
20457 t.bullet = 350;
20458 t.quotesinglbase = 222;
20459 t.quotedblbase = 333;
20460 t.quotedblright = 333;
20461 t.guillemotright = 556;
20462 t.ellipsis = 1000;
20463 t.perthousand = 1000;
20464 t.questiondown = 611;
20465 t.grave = 333;
20466 t.acute = 333;
20467 t.circumflex = 333;
20468 t.tilde = 333;
20469 t.macron = 333;
20470 t.breve = 333;
20471 t.dotaccent = 333;
20472 t.dieresis = 333;
20473 t.ring = 333;
20474 t.cedilla = 333;
20475 t.hungarumlaut = 333;
20476 t.ogonek = 333;
20477 t.caron = 333;
20478 t.emdash = 1000;
20479 t.AE = 1000;
20480 t.ordfeminine = 370;
20481 t.Lslash = 556;
20482 t.Oslash = 778;
20483 t.OE = 1000;
20484 t.ordmasculine = 365;
20485 t.ae = 889;
20486 t.dotlessi = 278;
20487 t.lslash = 222;
20488 t.oslash = 611;
20489 t.oe = 944;
20490 t.germandbls = 611;
20491 t.Idieresis = 278;
20492 t.eacute = 556;
20493 t.abreve = 556;
20494 t.uhungarumlaut = 556;
20495 t.ecaron = 556;
20496 t.Ydieresis = 667;
20497 t.divide = 584;
20498 t.Yacute = 667;
20499 t.Acircumflex = 667;
20500 t.aacute = 556;
20501 t.Ucircumflex = 722;
20502 t.yacute = 500;
20503 t.scommaaccent = 500;
20504 t.ecircumflex = 556;
20505 t.Uring = 722;
20506 t.Udieresis = 722;
20507 t.aogonek = 556;
20508 t.Uacute = 722;
20509 t.uogonek = 556;
20510 t.Edieresis = 667;
20511 t.Dcroat = 722;
20512 t.commaaccent = 250;
20513 t.copyright = 737;
20514 t.Emacron = 667;
20515 t.ccaron = 500;
20516 t.aring = 556;
20517 t.Ncommaaccent = 722;
20518 t.lacute = 222;
20519 t.agrave = 556;
20520 t.Tcommaaccent = 611;
20521 t.Cacute = 722;
20522 t.atilde = 556;
20523 t.Edotaccent = 667;
20524 t.scaron = 500;
20525 t.scedilla = 500;
20526 t.iacute = 278;
20527 t.lozenge = 471;
20528 t.Rcaron = 722;
20529 t.Gcommaaccent = 778;
20530 t.ucircumflex = 556;
20531 t.acircumflex = 556;
20532 t.Amacron = 667;
20533 t.rcaron = 333;
20534 t.ccedilla = 500;
20535 t.Zdotaccent = 611;
20536 t.Thorn = 667;
20537 t.Omacron = 778;
20538 t.Racute = 722;
20539 t.Sacute = 667;
20540 t.dcaron = 643;
20541 t.Umacron = 722;
20542 t.uring = 556;
20543 t.threesuperior = 333;
20544 t.Ograve = 778;
20545 t.Agrave = 667;
20546 t.Abreve = 667;
20547 t.multiply = 584;
20548 t.uacute = 556;
20549 t.Tcaron = 611;
20550 t.partialdiff = 476;
20551 t.ydieresis = 500;
20552 t.Nacute = 722;
20553 t.icircumflex = 278;
20554 t.Ecircumflex = 667;
20555 t.adieresis = 556;
20556 t.edieresis = 556;
20557 t.cacute = 500;
20558 t.nacute = 556;
20559 t.umacron = 556;
20560 t.Ncaron = 722;
20561 t.Iacute = 278;
20562 t.plusminus = 584;
20563 t.brokenbar = 260;
20564 t.registered = 737;
20565 t.Gbreve = 778;
20566 t.Idotaccent = 278;
20567 t.summation = 600;
20568 t.Egrave = 667;
20569 t.racute = 333;
20570 t.omacron = 556;
20571 t.Zacute = 611;
20572 t.Zcaron = 611;
20573 t.greaterequal = 549;
20574 t.Eth = 722;
20575 t.Ccedilla = 722;
20576 t.lcommaaccent = 222;
20577 t.tcaron = 317;
20578 t.eogonek = 556;
20579 t.Uogonek = 722;
20580 t.Aacute = 667;
20581 t.Adieresis = 667;
20582 t.egrave = 556;
20583 t.zacute = 500;
20584 t.iogonek = 222;
20585 t.Oacute = 778;
20586 t.oacute = 556;
20587 t.amacron = 556;
20588 t.sacute = 500;
20589 t.idieresis = 278;
20590 t.Ocircumflex = 778;
20591 t.Ugrave = 722;
20592 t.Delta = 612;
20593 t.thorn = 556;
20594 t.twosuperior = 333;
20595 t.Odieresis = 778;
20596 t.mu = 556;
20597 t.igrave = 278;
20598 t.ohungarumlaut = 556;
20599 t.Eogonek = 667;
20600 t.dcroat = 556;
20601 t.threequarters = 834;
20602 t.Scedilla = 667;
20603 t.lcaron = 299;
20604 t.Kcommaaccent = 667;
20605 t.Lacute = 556;
20606 t.trademark = 1000;
20607 t.edotaccent = 556;
20608 t.Igrave = 278;
20609 t.Imacron = 278;
20610 t.Lcaron = 556;
20611 t.onehalf = 834;
20612 t.lessequal = 549;
20613 t.ocircumflex = 556;
20614 t.ntilde = 556;
20615 t.Uhungarumlaut = 722;
20616 t.Eacute = 667;
20617 t.emacron = 556;
20618 t.gbreve = 556;
20619 t.onequarter = 834;
20620 t.Scaron = 667;
20621 t.Scommaaccent = 667;
20622 t.Ohungarumlaut = 778;
20623 t.degree = 400;
20624 t.ograve = 556;
20625 t.Ccaron = 722;
20626 t.ugrave = 556;
20627 t.radical = 453;
20628 t.Dcaron = 722;
20629 t.rcommaaccent = 333;
20630 t.Ntilde = 722;
20631 t.otilde = 556;
20632 t.Rcommaaccent = 722;
20633 t.Lcommaaccent = 556;
20634 t.Atilde = 667;
20635 t.Aogonek = 667;
20636 t.Aring = 667;
20637 t.Otilde = 778;
20638 t.zdotaccent = 500;
20639 t.Ecaron = 667;
20640 t.Iogonek = 278;
20641 t.kcommaaccent = 500;
20642 t.minus = 584;
20643 t.Icircumflex = 278;
20644 t.ncaron = 556;
20645 t.tcommaaccent = 278;
20646 t.logicalnot = 584;
20647 t.odieresis = 556;
20648 t.udieresis = 556;
20649 t.notequal = 549;
20650 t.gcommaaccent = 556;
20651 t.eth = 556;
20652 t.zcaron = 500;
20653 t.ncommaaccent = 556;
20654 t.onesuperior = 333;
20655 t.imacron = 278;
20656 t.Euro = 556;
20657 });
20658 t.Symbol = getLookupTableFactory(function (t) {
20659 t.space = 250;
20660 t.exclam = 333;
20661 t.universal = 713;
20662 t.numbersign = 500;
20663 t.existential = 549;
20664 t.percent = 833;
20665 t.ampersand = 778;
20666 t.suchthat = 439;
20667 t.parenleft = 333;
20668 t.parenright = 333;
20669 t.asteriskmath = 500;
20670 t.plus = 549;
20671 t.comma = 250;
20672 t.minus = 549;
20673 t.period = 250;
20674 t.slash = 278;
20675 t.zero = 500;
20676 t.one = 500;
20677 t.two = 500;
20678 t.three = 500;
20679 t.four = 500;
20680 t.five = 500;
20681 t.six = 500;
20682 t.seven = 500;
20683 t.eight = 500;
20684 t.nine = 500;
20685 t.colon = 278;
20686 t.semicolon = 278;
20687 t.less = 549;
20688 t.equal = 549;
20689 t.greater = 549;
20690 t.question = 444;
20691 t.congruent = 549;
20692 t.Alpha = 722;
20693 t.Beta = 667;
20694 t.Chi = 722;
20695 t.Delta = 612;
20696 t.Epsilon = 611;
20697 t.Phi = 763;
20698 t.Gamma = 603;
20699 t.Eta = 722;
20700 t.Iota = 333;
20701 t.theta1 = 631;
20702 t.Kappa = 722;
20703 t.Lambda = 686;
20704 t.Mu = 889;
20705 t.Nu = 722;
20706 t.Omicron = 722;
20707 t.Pi = 768;
20708 t.Theta = 741;
20709 t.Rho = 556;
20710 t.Sigma = 592;
20711 t.Tau = 611;
20712 t.Upsilon = 690;
20713 t.sigma1 = 439;
20714 t.Omega = 768;
20715 t.Xi = 645;
20716 t.Psi = 795;
20717 t.Zeta = 611;
20718 t.bracketleft = 333;
20719 t.therefore = 863;
20720 t.bracketright = 333;
20721 t.perpendicular = 658;
20722 t.underscore = 500;
20723 t.radicalex = 500;
20724 t.alpha = 631;
20725 t.beta = 549;
20726 t.chi = 549;
20727 t.delta = 494;
20728 t.epsilon = 439;
20729 t.phi = 521;
20730 t.gamma = 411;
20731 t.eta = 603;
20732 t.iota = 329;
20733 t.phi1 = 603;
20734 t.kappa = 549;
20735 t.lambda = 549;
20736 t.mu = 576;
20737 t.nu = 521;
20738 t.omicron = 549;
20739 t.pi = 549;
20740 t.theta = 521;
20741 t.rho = 549;
20742 t.sigma = 603;
20743 t.tau = 439;
20744 t.upsilon = 576;
20745 t.omega1 = 713;
20746 t.omega = 686;
20747 t.xi = 493;
20748 t.psi = 686;
20749 t.zeta = 494;
20750 t.braceleft = 480;
20751 t.bar = 200;
20752 t.braceright = 480;
20753 t.similar = 549;
20754 t.Euro = 750;
20755 t.Upsilon1 = 620;
20756 t.minute = 247;
20757 t.lessequal = 549;
20758 t.fraction = 167;
20759 t.infinity = 713;
20760 t.florin = 500;
20761 t.club = 753;
20762 t.diamond = 753;
20763 t.heart = 753;
20764 t.spade = 753;
20765 t.arrowboth = 1042;
20766 t.arrowleft = 987;
20767 t.arrowup = 603;
20768 t.arrowright = 987;
20769 t.arrowdown = 603;
20770 t.degree = 400;
20771 t.plusminus = 549;
20772 t.second = 411;
20773 t.greaterequal = 549;
20774 t.multiply = 549;
20775 t.proportional = 713;
20776 t.partialdiff = 494;
20777 t.bullet = 460;
20778 t.divide = 549;
20779 t.notequal = 549;
20780 t.equivalence = 549;
20781 t.approxequal = 549;
20782 t.ellipsis = 1000;
20783 t.arrowvertex = 603;
20784 t.arrowhorizex = 1000;
20785 t.carriagereturn = 658;
20786 t.aleph = 823;
20787 t.Ifraktur = 686;
20788 t.Rfraktur = 795;
20789 t.weierstrass = 987;
20790 t.circlemultiply = 768;
20791 t.circleplus = 768;
20792 t.emptyset = 823;
20793 t.intersection = 768;
20794 t.union = 768;
20795 t.propersuperset = 713;
20796 t.reflexsuperset = 713;
20797 t.notsubset = 713;
20798 t.propersubset = 713;
20799 t.reflexsubset = 713;
20800 t.element = 713;
20801 t.notelement = 713;
20802 t.angle = 768;
20803 t.gradient = 713;
20804 t.registerserif = 790;
20805 t.copyrightserif = 790;
20806 t.trademarkserif = 890;
20807 t.product = 823;
20808 t.radical = 549;
20809 t.dotmath = 250;
20810 t.logicalnot = 713;
20811 t.logicaland = 603;
20812 t.logicalor = 603;
20813 t.arrowdblboth = 1042;
20814 t.arrowdblleft = 987;
20815 t.arrowdblup = 603;
20816 t.arrowdblright = 987;
20817 t.arrowdbldown = 603;
20818 t.lozenge = 494;
20819 t.angleleft = 329;
20820 t.registersans = 790;
20821 t.copyrightsans = 790;
20822 t.trademarksans = 786;
20823 t.summation = 713;
20824 t.parenlefttp = 384;
20825 t.parenleftex = 384;
20826 t.parenleftbt = 384;
20827 t.bracketlefttp = 384;
20828 t.bracketleftex = 384;
20829 t.bracketleftbt = 384;
20830 t.bracelefttp = 494;
20831 t.braceleftmid = 494;
20832 t.braceleftbt = 494;
20833 t.braceex = 494;
20834 t.angleright = 329;
20835 t.integral = 274;
20836 t.integraltp = 686;
20837 t.integralex = 686;
20838 t.integralbt = 686;
20839 t.parenrighttp = 384;
20840 t.parenrightex = 384;
20841 t.parenrightbt = 384;
20842 t.bracketrighttp = 384;
20843 t.bracketrightex = 384;
20844 t.bracketrightbt = 384;
20845 t.bracerighttp = 494;
20846 t.bracerightmid = 494;
20847 t.bracerightbt = 494;
20848 t.apple = 790;
20849 });
20850 t["Times-Roman"] = getLookupTableFactory(function (t) {
20851 t.space = 250;
20852 t.exclam = 333;
20853 t.quotedbl = 408;
20854 t.numbersign = 500;
20855 t.dollar = 500;
20856 t.percent = 833;
20857 t.ampersand = 778;
20858 t.quoteright = 333;
20859 t.parenleft = 333;
20860 t.parenright = 333;
20861 t.asterisk = 500;
20862 t.plus = 564;
20863 t.comma = 250;
20864 t.hyphen = 333;
20865 t.period = 250;
20866 t.slash = 278;
20867 t.zero = 500;
20868 t.one = 500;
20869 t.two = 500;
20870 t.three = 500;
20871 t.four = 500;
20872 t.five = 500;
20873 t.six = 500;
20874 t.seven = 500;
20875 t.eight = 500;
20876 t.nine = 500;
20877 t.colon = 278;
20878 t.semicolon = 278;
20879 t.less = 564;
20880 t.equal = 564;
20881 t.greater = 564;
20882 t.question = 444;
20883 t.at = 921;
20884 t.A = 722;
20885 t.B = 667;
20886 t.C = 667;
20887 t.D = 722;
20888 t.E = 611;
20889 t.F = 556;
20890 t.G = 722;
20891 t.H = 722;
20892 t.I = 333;
20893 t.J = 389;
20894 t.K = 722;
20895 t.L = 611;
20896 t.M = 889;
20897 t.N = 722;
20898 t.O = 722;
20899 t.P = 556;
20900 t.Q = 722;
20901 t.R = 667;
20902 t.S = 556;
20903 t.T = 611;
20904 t.U = 722;
20905 t.V = 722;
20906 t.W = 944;
20907 t.X = 722;
20908 t.Y = 722;
20909 t.Z = 611;
20910 t.bracketleft = 333;
20911 t.backslash = 278;
20912 t.bracketright = 333;
20913 t.asciicircum = 469;
20914 t.underscore = 500;
20915 t.quoteleft = 333;
20916 t.a = 444;
20917 t.b = 500;
20918 t.c = 444;
20919 t.d = 500;
20920 t.e = 444;
20921 t.f = 333;
20922 t.g = 500;
20923 t.h = 500;
20924 t.i = 278;
20925 t.j = 278;
20926 t.k = 500;
20927 t.l = 278;
20928 t.m = 778;
20929 t.n = 500;
20930 t.o = 500;
20931 t.p = 500;
20932 t.q = 500;
20933 t.r = 333;
20934 t.s = 389;
20935 t.t = 278;
20936 t.u = 500;
20937 t.v = 500;
20938 t.w = 722;
20939 t.x = 500;
20940 t.y = 500;
20941 t.z = 444;
20942 t.braceleft = 480;
20943 t.bar = 200;
20944 t.braceright = 480;
20945 t.asciitilde = 541;
20946 t.exclamdown = 333;
20947 t.cent = 500;
20948 t.sterling = 500;
20949 t.fraction = 167;
20950 t.yen = 500;
20951 t.florin = 500;
20952 t.section = 500;
20953 t.currency = 500;
20954 t.quotesingle = 180;
20955 t.quotedblleft = 444;
20956 t.guillemotleft = 500;
20957 t.guilsinglleft = 333;
20958 t.guilsinglright = 333;
20959 t.fi = 556;
20960 t.fl = 556;
20961 t.endash = 500;
20962 t.dagger = 500;
20963 t.daggerdbl = 500;
20964 t.periodcentered = 250;
20965 t.paragraph = 453;
20966 t.bullet = 350;
20967 t.quotesinglbase = 333;
20968 t.quotedblbase = 444;
20969 t.quotedblright = 444;
20970 t.guillemotright = 500;
20971 t.ellipsis = 1000;
20972 t.perthousand = 1000;
20973 t.questiondown = 444;
20974 t.grave = 333;
20975 t.acute = 333;
20976 t.circumflex = 333;
20977 t.tilde = 333;
20978 t.macron = 333;
20979 t.breve = 333;
20980 t.dotaccent = 333;
20981 t.dieresis = 333;
20982 t.ring = 333;
20983 t.cedilla = 333;
20984 t.hungarumlaut = 333;
20985 t.ogonek = 333;
20986 t.caron = 333;
20987 t.emdash = 1000;
20988 t.AE = 889;
20989 t.ordfeminine = 276;
20990 t.Lslash = 611;
20991 t.Oslash = 722;
20992 t.OE = 889;
20993 t.ordmasculine = 310;
20994 t.ae = 667;
20995 t.dotlessi = 278;
20996 t.lslash = 278;
20997 t.oslash = 500;
20998 t.oe = 722;
20999 t.germandbls = 500;
21000 t.Idieresis = 333;
21001 t.eacute = 444;
21002 t.abreve = 444;
21003 t.uhungarumlaut = 500;
21004 t.ecaron = 444;
21005 t.Ydieresis = 722;
21006 t.divide = 564;
21007 t.Yacute = 722;
21008 t.Acircumflex = 722;
21009 t.aacute = 444;
21010 t.Ucircumflex = 722;
21011 t.yacute = 500;
21012 t.scommaaccent = 389;
21013 t.ecircumflex = 444;
21014 t.Uring = 722;
21015 t.Udieresis = 722;
21016 t.aogonek = 444;
21017 t.Uacute = 722;
21018 t.uogonek = 500;
21019 t.Edieresis = 611;
21020 t.Dcroat = 722;
21021 t.commaaccent = 250;
21022 t.copyright = 760;
21023 t.Emacron = 611;
21024 t.ccaron = 444;
21025 t.aring = 444;
21026 t.Ncommaaccent = 722;
21027 t.lacute = 278;
21028 t.agrave = 444;
21029 t.Tcommaaccent = 611;
21030 t.Cacute = 667;
21031 t.atilde = 444;
21032 t.Edotaccent = 611;
21033 t.scaron = 389;
21034 t.scedilla = 389;
21035 t.iacute = 278;
21036 t.lozenge = 471;
21037 t.Rcaron = 667;
21038 t.Gcommaaccent = 722;
21039 t.ucircumflex = 500;
21040 t.acircumflex = 444;
21041 t.Amacron = 722;
21042 t.rcaron = 333;
21043 t.ccedilla = 444;
21044 t.Zdotaccent = 611;
21045 t.Thorn = 556;
21046 t.Omacron = 722;
21047 t.Racute = 667;
21048 t.Sacute = 556;
21049 t.dcaron = 588;
21050 t.Umacron = 722;
21051 t.uring = 500;
21052 t.threesuperior = 300;
21053 t.Ograve = 722;
21054 t.Agrave = 722;
21055 t.Abreve = 722;
21056 t.multiply = 564;
21057 t.uacute = 500;
21058 t.Tcaron = 611;
21059 t.partialdiff = 476;
21060 t.ydieresis = 500;
21061 t.Nacute = 722;
21062 t.icircumflex = 278;
21063 t.Ecircumflex = 611;
21064 t.adieresis = 444;
21065 t.edieresis = 444;
21066 t.cacute = 444;
21067 t.nacute = 500;
21068 t.umacron = 500;
21069 t.Ncaron = 722;
21070 t.Iacute = 333;
21071 t.plusminus = 564;
21072 t.brokenbar = 200;
21073 t.registered = 760;
21074 t.Gbreve = 722;
21075 t.Idotaccent = 333;
21076 t.summation = 600;
21077 t.Egrave = 611;
21078 t.racute = 333;
21079 t.omacron = 500;
21080 t.Zacute = 611;
21081 t.Zcaron = 611;
21082 t.greaterequal = 549;
21083 t.Eth = 722;
21084 t.Ccedilla = 667;
21085 t.lcommaaccent = 278;
21086 t.tcaron = 326;
21087 t.eogonek = 444;
21088 t.Uogonek = 722;
21089 t.Aacute = 722;
21090 t.Adieresis = 722;
21091 t.egrave = 444;
21092 t.zacute = 444;
21093 t.iogonek = 278;
21094 t.Oacute = 722;
21095 t.oacute = 500;
21096 t.amacron = 444;
21097 t.sacute = 389;
21098 t.idieresis = 278;
21099 t.Ocircumflex = 722;
21100 t.Ugrave = 722;
21101 t.Delta = 612;
21102 t.thorn = 500;
21103 t.twosuperior = 300;
21104 t.Odieresis = 722;
21105 t.mu = 500;
21106 t.igrave = 278;
21107 t.ohungarumlaut = 500;
21108 t.Eogonek = 611;
21109 t.dcroat = 500;
21110 t.threequarters = 750;
21111 t.Scedilla = 556;
21112 t.lcaron = 344;
21113 t.Kcommaaccent = 722;
21114 t.Lacute = 611;
21115 t.trademark = 980;
21116 t.edotaccent = 444;
21117 t.Igrave = 333;
21118 t.Imacron = 333;
21119 t.Lcaron = 611;
21120 t.onehalf = 750;
21121 t.lessequal = 549;
21122 t.ocircumflex = 500;
21123 t.ntilde = 500;
21124 t.Uhungarumlaut = 722;
21125 t.Eacute = 611;
21126 t.emacron = 444;
21127 t.gbreve = 500;
21128 t.onequarter = 750;
21129 t.Scaron = 556;
21130 t.Scommaaccent = 556;
21131 t.Ohungarumlaut = 722;
21132 t.degree = 400;
21133 t.ograve = 500;
21134 t.Ccaron = 667;
21135 t.ugrave = 500;
21136 t.radical = 453;
21137 t.Dcaron = 722;
21138 t.rcommaaccent = 333;
21139 t.Ntilde = 722;
21140 t.otilde = 500;
21141 t.Rcommaaccent = 667;
21142 t.Lcommaaccent = 611;
21143 t.Atilde = 722;
21144 t.Aogonek = 722;
21145 t.Aring = 722;
21146 t.Otilde = 722;
21147 t.zdotaccent = 444;
21148 t.Ecaron = 611;
21149 t.Iogonek = 333;
21150 t.kcommaaccent = 500;
21151 t.minus = 564;
21152 t.Icircumflex = 333;
21153 t.ncaron = 500;
21154 t.tcommaaccent = 278;
21155 t.logicalnot = 564;
21156 t.odieresis = 500;
21157 t.udieresis = 500;
21158 t.notequal = 549;
21159 t.gcommaaccent = 500;
21160 t.eth = 500;
21161 t.zcaron = 444;
21162 t.ncommaaccent = 500;
21163 t.onesuperior = 300;
21164 t.imacron = 278;
21165 t.Euro = 500;
21166 });
21167 t["Times-Bold"] = getLookupTableFactory(function (t) {
21168 t.space = 250;
21169 t.exclam = 333;
21170 t.quotedbl = 555;
21171 t.numbersign = 500;
21172 t.dollar = 500;
21173 t.percent = 1000;
21174 t.ampersand = 833;
21175 t.quoteright = 333;
21176 t.parenleft = 333;
21177 t.parenright = 333;
21178 t.asterisk = 500;
21179 t.plus = 570;
21180 t.comma = 250;
21181 t.hyphen = 333;
21182 t.period = 250;
21183 t.slash = 278;
21184 t.zero = 500;
21185 t.one = 500;
21186 t.two = 500;
21187 t.three = 500;
21188 t.four = 500;
21189 t.five = 500;
21190 t.six = 500;
21191 t.seven = 500;
21192 t.eight = 500;
21193 t.nine = 500;
21194 t.colon = 333;
21195 t.semicolon = 333;
21196 t.less = 570;
21197 t.equal = 570;
21198 t.greater = 570;
21199 t.question = 500;
21200 t.at = 930;
21201 t.A = 722;
21202 t.B = 667;
21203 t.C = 722;
21204 t.D = 722;
21205 t.E = 667;
21206 t.F = 611;
21207 t.G = 778;
21208 t.H = 778;
21209 t.I = 389;
21210 t.J = 500;
21211 t.K = 778;
21212 t.L = 667;
21213 t.M = 944;
21214 t.N = 722;
21215 t.O = 778;
21216 t.P = 611;
21217 t.Q = 778;
21218 t.R = 722;
21219 t.S = 556;
21220 t.T = 667;
21221 t.U = 722;
21222 t.V = 722;
21223 t.W = 1000;
21224 t.X = 722;
21225 t.Y = 722;
21226 t.Z = 667;
21227 t.bracketleft = 333;
21228 t.backslash = 278;
21229 t.bracketright = 333;
21230 t.asciicircum = 581;
21231 t.underscore = 500;
21232 t.quoteleft = 333;
21233 t.a = 500;
21234 t.b = 556;
21235 t.c = 444;
21236 t.d = 556;
21237 t.e = 444;
21238 t.f = 333;
21239 t.g = 500;
21240 t.h = 556;
21241 t.i = 278;
21242 t.j = 333;
21243 t.k = 556;
21244 t.l = 278;
21245 t.m = 833;
21246 t.n = 556;
21247 t.o = 500;
21248 t.p = 556;
21249 t.q = 556;
21250 t.r = 444;
21251 t.s = 389;
21252 t.t = 333;
21253 t.u = 556;
21254 t.v = 500;
21255 t.w = 722;
21256 t.x = 500;
21257 t.y = 500;
21258 t.z = 444;
21259 t.braceleft = 394;
21260 t.bar = 220;
21261 t.braceright = 394;
21262 t.asciitilde = 520;
21263 t.exclamdown = 333;
21264 t.cent = 500;
21265 t.sterling = 500;
21266 t.fraction = 167;
21267 t.yen = 500;
21268 t.florin = 500;
21269 t.section = 500;
21270 t.currency = 500;
21271 t.quotesingle = 278;
21272 t.quotedblleft = 500;
21273 t.guillemotleft = 500;
21274 t.guilsinglleft = 333;
21275 t.guilsinglright = 333;
21276 t.fi = 556;
21277 t.fl = 556;
21278 t.endash = 500;
21279 t.dagger = 500;
21280 t.daggerdbl = 500;
21281 t.periodcentered = 250;
21282 t.paragraph = 540;
21283 t.bullet = 350;
21284 t.quotesinglbase = 333;
21285 t.quotedblbase = 500;
21286 t.quotedblright = 500;
21287 t.guillemotright = 500;
21288 t.ellipsis = 1000;
21289 t.perthousand = 1000;
21290 t.questiondown = 500;
21291 t.grave = 333;
21292 t.acute = 333;
21293 t.circumflex = 333;
21294 t.tilde = 333;
21295 t.macron = 333;
21296 t.breve = 333;
21297 t.dotaccent = 333;
21298 t.dieresis = 333;
21299 t.ring = 333;
21300 t.cedilla = 333;
21301 t.hungarumlaut = 333;
21302 t.ogonek = 333;
21303 t.caron = 333;
21304 t.emdash = 1000;
21305 t.AE = 1000;
21306 t.ordfeminine = 300;
21307 t.Lslash = 667;
21308 t.Oslash = 778;
21309 t.OE = 1000;
21310 t.ordmasculine = 330;
21311 t.ae = 722;
21312 t.dotlessi = 278;
21313 t.lslash = 278;
21314 t.oslash = 500;
21315 t.oe = 722;
21316 t.germandbls = 556;
21317 t.Idieresis = 389;
21318 t.eacute = 444;
21319 t.abreve = 500;
21320 t.uhungarumlaut = 556;
21321 t.ecaron = 444;
21322 t.Ydieresis = 722;
21323 t.divide = 570;
21324 t.Yacute = 722;
21325 t.Acircumflex = 722;
21326 t.aacute = 500;
21327 t.Ucircumflex = 722;
21328 t.yacute = 500;
21329 t.scommaaccent = 389;
21330 t.ecircumflex = 444;
21331 t.Uring = 722;
21332 t.Udieresis = 722;
21333 t.aogonek = 500;
21334 t.Uacute = 722;
21335 t.uogonek = 556;
21336 t.Edieresis = 667;
21337 t.Dcroat = 722;
21338 t.commaaccent = 250;
21339 t.copyright = 747;
21340 t.Emacron = 667;
21341 t.ccaron = 444;
21342 t.aring = 500;
21343 t.Ncommaaccent = 722;
21344 t.lacute = 278;
21345 t.agrave = 500;
21346 t.Tcommaaccent = 667;
21347 t.Cacute = 722;
21348 t.atilde = 500;
21349 t.Edotaccent = 667;
21350 t.scaron = 389;
21351 t.scedilla = 389;
21352 t.iacute = 278;
21353 t.lozenge = 494;
21354 t.Rcaron = 722;
21355 t.Gcommaaccent = 778;
21356 t.ucircumflex = 556;
21357 t.acircumflex = 500;
21358 t.Amacron = 722;
21359 t.rcaron = 444;
21360 t.ccedilla = 444;
21361 t.Zdotaccent = 667;
21362 t.Thorn = 611;
21363 t.Omacron = 778;
21364 t.Racute = 722;
21365 t.Sacute = 556;
21366 t.dcaron = 672;
21367 t.Umacron = 722;
21368 t.uring = 556;
21369 t.threesuperior = 300;
21370 t.Ograve = 778;
21371 t.Agrave = 722;
21372 t.Abreve = 722;
21373 t.multiply = 570;
21374 t.uacute = 556;
21375 t.Tcaron = 667;
21376 t.partialdiff = 494;
21377 t.ydieresis = 500;
21378 t.Nacute = 722;
21379 t.icircumflex = 278;
21380 t.Ecircumflex = 667;
21381 t.adieresis = 500;
21382 t.edieresis = 444;
21383 t.cacute = 444;
21384 t.nacute = 556;
21385 t.umacron = 556;
21386 t.Ncaron = 722;
21387 t.Iacute = 389;
21388 t.plusminus = 570;
21389 t.brokenbar = 220;
21390 t.registered = 747;
21391 t.Gbreve = 778;
21392 t.Idotaccent = 389;
21393 t.summation = 600;
21394 t.Egrave = 667;
21395 t.racute = 444;
21396 t.omacron = 500;
21397 t.Zacute = 667;
21398 t.Zcaron = 667;
21399 t.greaterequal = 549;
21400 t.Eth = 722;
21401 t.Ccedilla = 722;
21402 t.lcommaaccent = 278;
21403 t.tcaron = 416;
21404 t.eogonek = 444;
21405 t.Uogonek = 722;
21406 t.Aacute = 722;
21407 t.Adieresis = 722;
21408 t.egrave = 444;
21409 t.zacute = 444;
21410 t.iogonek = 278;
21411 t.Oacute = 778;
21412 t.oacute = 500;
21413 t.amacron = 500;
21414 t.sacute = 389;
21415 t.idieresis = 278;
21416 t.Ocircumflex = 778;
21417 t.Ugrave = 722;
21418 t.Delta = 612;
21419 t.thorn = 556;
21420 t.twosuperior = 300;
21421 t.Odieresis = 778;
21422 t.mu = 556;
21423 t.igrave = 278;
21424 t.ohungarumlaut = 500;
21425 t.Eogonek = 667;
21426 t.dcroat = 556;
21427 t.threequarters = 750;
21428 t.Scedilla = 556;
21429 t.lcaron = 394;
21430 t.Kcommaaccent = 778;
21431 t.Lacute = 667;
21432 t.trademark = 1000;
21433 t.edotaccent = 444;
21434 t.Igrave = 389;
21435 t.Imacron = 389;
21436 t.Lcaron = 667;
21437 t.onehalf = 750;
21438 t.lessequal = 549;
21439 t.ocircumflex = 500;
21440 t.ntilde = 556;
21441 t.Uhungarumlaut = 722;
21442 t.Eacute = 667;
21443 t.emacron = 444;
21444 t.gbreve = 500;
21445 t.onequarter = 750;
21446 t.Scaron = 556;
21447 t.Scommaaccent = 556;
21448 t.Ohungarumlaut = 778;
21449 t.degree = 400;
21450 t.ograve = 500;
21451 t.Ccaron = 722;
21452 t.ugrave = 556;
21453 t.radical = 549;
21454 t.Dcaron = 722;
21455 t.rcommaaccent = 444;
21456 t.Ntilde = 722;
21457 t.otilde = 500;
21458 t.Rcommaaccent = 722;
21459 t.Lcommaaccent = 667;
21460 t.Atilde = 722;
21461 t.Aogonek = 722;
21462 t.Aring = 722;
21463 t.Otilde = 778;
21464 t.zdotaccent = 444;
21465 t.Ecaron = 667;
21466 t.Iogonek = 389;
21467 t.kcommaaccent = 556;
21468 t.minus = 570;
21469 t.Icircumflex = 389;
21470 t.ncaron = 556;
21471 t.tcommaaccent = 333;
21472 t.logicalnot = 570;
21473 t.odieresis = 500;
21474 t.udieresis = 556;
21475 t.notequal = 549;
21476 t.gcommaaccent = 500;
21477 t.eth = 500;
21478 t.zcaron = 444;
21479 t.ncommaaccent = 556;
21480 t.onesuperior = 300;
21481 t.imacron = 278;
21482 t.Euro = 500;
21483 });
21484 t["Times-BoldItalic"] = getLookupTableFactory(function (t) {
21485 t.space = 250;
21486 t.exclam = 389;
21487 t.quotedbl = 555;
21488 t.numbersign = 500;
21489 t.dollar = 500;
21490 t.percent = 833;
21491 t.ampersand = 778;
21492 t.quoteright = 333;
21493 t.parenleft = 333;
21494 t.parenright = 333;
21495 t.asterisk = 500;
21496 t.plus = 570;
21497 t.comma = 250;
21498 t.hyphen = 333;
21499 t.period = 250;
21500 t.slash = 278;
21501 t.zero = 500;
21502 t.one = 500;
21503 t.two = 500;
21504 t.three = 500;
21505 t.four = 500;
21506 t.five = 500;
21507 t.six = 500;
21508 t.seven = 500;
21509 t.eight = 500;
21510 t.nine = 500;
21511 t.colon = 333;
21512 t.semicolon = 333;
21513 t.less = 570;
21514 t.equal = 570;
21515 t.greater = 570;
21516 t.question = 500;
21517 t.at = 832;
21518 t.A = 667;
21519 t.B = 667;
21520 t.C = 667;
21521 t.D = 722;
21522 t.E = 667;
21523 t.F = 667;
21524 t.G = 722;
21525 t.H = 778;
21526 t.I = 389;
21527 t.J = 500;
21528 t.K = 667;
21529 t.L = 611;
21530 t.M = 889;
21531 t.N = 722;
21532 t.O = 722;
21533 t.P = 611;
21534 t.Q = 722;
21535 t.R = 667;
21536 t.S = 556;
21537 t.T = 611;
21538 t.U = 722;
21539 t.V = 667;
21540 t.W = 889;
21541 t.X = 667;
21542 t.Y = 611;
21543 t.Z = 611;
21544 t.bracketleft = 333;
21545 t.backslash = 278;
21546 t.bracketright = 333;
21547 t.asciicircum = 570;
21548 t.underscore = 500;
21549 t.quoteleft = 333;
21550 t.a = 500;
21551 t.b = 500;
21552 t.c = 444;
21553 t.d = 500;
21554 t.e = 444;
21555 t.f = 333;
21556 t.g = 500;
21557 t.h = 556;
21558 t.i = 278;
21559 t.j = 278;
21560 t.k = 500;
21561 t.l = 278;
21562 t.m = 778;
21563 t.n = 556;
21564 t.o = 500;
21565 t.p = 500;
21566 t.q = 500;
21567 t.r = 389;
21568 t.s = 389;
21569 t.t = 278;
21570 t.u = 556;
21571 t.v = 444;
21572 t.w = 667;
21573 t.x = 500;
21574 t.y = 444;
21575 t.z = 389;
21576 t.braceleft = 348;
21577 t.bar = 220;
21578 t.braceright = 348;
21579 t.asciitilde = 570;
21580 t.exclamdown = 389;
21581 t.cent = 500;
21582 t.sterling = 500;
21583 t.fraction = 167;
21584 t.yen = 500;
21585 t.florin = 500;
21586 t.section = 500;
21587 t.currency = 500;
21588 t.quotesingle = 278;
21589 t.quotedblleft = 500;
21590 t.guillemotleft = 500;
21591 t.guilsinglleft = 333;
21592 t.guilsinglright = 333;
21593 t.fi = 556;
21594 t.fl = 556;
21595 t.endash = 500;
21596 t.dagger = 500;
21597 t.daggerdbl = 500;
21598 t.periodcentered = 250;
21599 t.paragraph = 500;
21600 t.bullet = 350;
21601 t.quotesinglbase = 333;
21602 t.quotedblbase = 500;
21603 t.quotedblright = 500;
21604 t.guillemotright = 500;
21605 t.ellipsis = 1000;
21606 t.perthousand = 1000;
21607 t.questiondown = 500;
21608 t.grave = 333;
21609 t.acute = 333;
21610 t.circumflex = 333;
21611 t.tilde = 333;
21612 t.macron = 333;
21613 t.breve = 333;
21614 t.dotaccent = 333;
21615 t.dieresis = 333;
21616 t.ring = 333;
21617 t.cedilla = 333;
21618 t.hungarumlaut = 333;
21619 t.ogonek = 333;
21620 t.caron = 333;
21621 t.emdash = 1000;
21622 t.AE = 944;
21623 t.ordfeminine = 266;
21624 t.Lslash = 611;
21625 t.Oslash = 722;
21626 t.OE = 944;
21627 t.ordmasculine = 300;
21628 t.ae = 722;
21629 t.dotlessi = 278;
21630 t.lslash = 278;
21631 t.oslash = 500;
21632 t.oe = 722;
21633 t.germandbls = 500;
21634 t.Idieresis = 389;
21635 t.eacute = 444;
21636 t.abreve = 500;
21637 t.uhungarumlaut = 556;
21638 t.ecaron = 444;
21639 t.Ydieresis = 611;
21640 t.divide = 570;
21641 t.Yacute = 611;
21642 t.Acircumflex = 667;
21643 t.aacute = 500;
21644 t.Ucircumflex = 722;
21645 t.yacute = 444;
21646 t.scommaaccent = 389;
21647 t.ecircumflex = 444;
21648 t.Uring = 722;
21649 t.Udieresis = 722;
21650 t.aogonek = 500;
21651 t.Uacute = 722;
21652 t.uogonek = 556;
21653 t.Edieresis = 667;
21654 t.Dcroat = 722;
21655 t.commaaccent = 250;
21656 t.copyright = 747;
21657 t.Emacron = 667;
21658 t.ccaron = 444;
21659 t.aring = 500;
21660 t.Ncommaaccent = 722;
21661 t.lacute = 278;
21662 t.agrave = 500;
21663 t.Tcommaaccent = 611;
21664 t.Cacute = 667;
21665 t.atilde = 500;
21666 t.Edotaccent = 667;
21667 t.scaron = 389;
21668 t.scedilla = 389;
21669 t.iacute = 278;
21670 t.lozenge = 494;
21671 t.Rcaron = 667;
21672 t.Gcommaaccent = 722;
21673 t.ucircumflex = 556;
21674 t.acircumflex = 500;
21675 t.Amacron = 667;
21676 t.rcaron = 389;
21677 t.ccedilla = 444;
21678 t.Zdotaccent = 611;
21679 t.Thorn = 611;
21680 t.Omacron = 722;
21681 t.Racute = 667;
21682 t.Sacute = 556;
21683 t.dcaron = 608;
21684 t.Umacron = 722;
21685 t.uring = 556;
21686 t.threesuperior = 300;
21687 t.Ograve = 722;
21688 t.Agrave = 667;
21689 t.Abreve = 667;
21690 t.multiply = 570;
21691 t.uacute = 556;
21692 t.Tcaron = 611;
21693 t.partialdiff = 494;
21694 t.ydieresis = 444;
21695 t.Nacute = 722;
21696 t.icircumflex = 278;
21697 t.Ecircumflex = 667;
21698 t.adieresis = 500;
21699 t.edieresis = 444;
21700 t.cacute = 444;
21701 t.nacute = 556;
21702 t.umacron = 556;
21703 t.Ncaron = 722;
21704 t.Iacute = 389;
21705 t.plusminus = 570;
21706 t.brokenbar = 220;
21707 t.registered = 747;
21708 t.Gbreve = 722;
21709 t.Idotaccent = 389;
21710 t.summation = 600;
21711 t.Egrave = 667;
21712 t.racute = 389;
21713 t.omacron = 500;
21714 t.Zacute = 611;
21715 t.Zcaron = 611;
21716 t.greaterequal = 549;
21717 t.Eth = 722;
21718 t.Ccedilla = 667;
21719 t.lcommaaccent = 278;
21720 t.tcaron = 366;
21721 t.eogonek = 444;
21722 t.Uogonek = 722;
21723 t.Aacute = 667;
21724 t.Adieresis = 667;
21725 t.egrave = 444;
21726 t.zacute = 389;
21727 t.iogonek = 278;
21728 t.Oacute = 722;
21729 t.oacute = 500;
21730 t.amacron = 500;
21731 t.sacute = 389;
21732 t.idieresis = 278;
21733 t.Ocircumflex = 722;
21734 t.Ugrave = 722;
21735 t.Delta = 612;
21736 t.thorn = 500;
21737 t.twosuperior = 300;
21738 t.Odieresis = 722;
21739 t.mu = 576;
21740 t.igrave = 278;
21741 t.ohungarumlaut = 500;
21742 t.Eogonek = 667;
21743 t.dcroat = 500;
21744 t.threequarters = 750;
21745 t.Scedilla = 556;
21746 t.lcaron = 382;
21747 t.Kcommaaccent = 667;
21748 t.Lacute = 611;
21749 t.trademark = 1000;
21750 t.edotaccent = 444;
21751 t.Igrave = 389;
21752 t.Imacron = 389;
21753 t.Lcaron = 611;
21754 t.onehalf = 750;
21755 t.lessequal = 549;
21756 t.ocircumflex = 500;
21757 t.ntilde = 556;
21758 t.Uhungarumlaut = 722;
21759 t.Eacute = 667;
21760 t.emacron = 444;
21761 t.gbreve = 500;
21762 t.onequarter = 750;
21763 t.Scaron = 556;
21764 t.Scommaaccent = 556;
21765 t.Ohungarumlaut = 722;
21766 t.degree = 400;
21767 t.ograve = 500;
21768 t.Ccaron = 667;
21769 t.ugrave = 556;
21770 t.radical = 549;
21771 t.Dcaron = 722;
21772 t.rcommaaccent = 389;
21773 t.Ntilde = 722;
21774 t.otilde = 500;
21775 t.Rcommaaccent = 667;
21776 t.Lcommaaccent = 611;
21777 t.Atilde = 667;
21778 t.Aogonek = 667;
21779 t.Aring = 667;
21780 t.Otilde = 722;
21781 t.zdotaccent = 389;
21782 t.Ecaron = 667;
21783 t.Iogonek = 389;
21784 t.kcommaaccent = 500;
21785 t.minus = 606;
21786 t.Icircumflex = 389;
21787 t.ncaron = 556;
21788 t.tcommaaccent = 278;
21789 t.logicalnot = 606;
21790 t.odieresis = 500;
21791 t.udieresis = 556;
21792 t.notequal = 549;
21793 t.gcommaaccent = 500;
21794 t.eth = 500;
21795 t.zcaron = 389;
21796 t.ncommaaccent = 556;
21797 t.onesuperior = 300;
21798 t.imacron = 278;
21799 t.Euro = 500;
21800 });
21801 t["Times-Italic"] = getLookupTableFactory(function (t) {
21802 t.space = 250;
21803 t.exclam = 333;
21804 t.quotedbl = 420;
21805 t.numbersign = 500;
21806 t.dollar = 500;
21807 t.percent = 833;
21808 t.ampersand = 778;
21809 t.quoteright = 333;
21810 t.parenleft = 333;
21811 t.parenright = 333;
21812 t.asterisk = 500;
21813 t.plus = 675;
21814 t.comma = 250;
21815 t.hyphen = 333;
21816 t.period = 250;
21817 t.slash = 278;
21818 t.zero = 500;
21819 t.one = 500;
21820 t.two = 500;
21821 t.three = 500;
21822 t.four = 500;
21823 t.five = 500;
21824 t.six = 500;
21825 t.seven = 500;
21826 t.eight = 500;
21827 t.nine = 500;
21828 t.colon = 333;
21829 t.semicolon = 333;
21830 t.less = 675;
21831 t.equal = 675;
21832 t.greater = 675;
21833 t.question = 500;
21834 t.at = 920;
21835 t.A = 611;
21836 t.B = 611;
21837 t.C = 667;
21838 t.D = 722;
21839 t.E = 611;
21840 t.F = 611;
21841 t.G = 722;
21842 t.H = 722;
21843 t.I = 333;
21844 t.J = 444;
21845 t.K = 667;
21846 t.L = 556;
21847 t.M = 833;
21848 t.N = 667;
21849 t.O = 722;
21850 t.P = 611;
21851 t.Q = 722;
21852 t.R = 611;
21853 t.S = 500;
21854 t.T = 556;
21855 t.U = 722;
21856 t.V = 611;
21857 t.W = 833;
21858 t.X = 611;
21859 t.Y = 556;
21860 t.Z = 556;
21861 t.bracketleft = 389;
21862 t.backslash = 278;
21863 t.bracketright = 389;
21864 t.asciicircum = 422;
21865 t.underscore = 500;
21866 t.quoteleft = 333;
21867 t.a = 500;
21868 t.b = 500;
21869 t.c = 444;
21870 t.d = 500;
21871 t.e = 444;
21872 t.f = 278;
21873 t.g = 500;
21874 t.h = 500;
21875 t.i = 278;
21876 t.j = 278;
21877 t.k = 444;
21878 t.l = 278;
21879 t.m = 722;
21880 t.n = 500;
21881 t.o = 500;
21882 t.p = 500;
21883 t.q = 500;
21884 t.r = 389;
21885 t.s = 389;
21886 t.t = 278;
21887 t.u = 500;
21888 t.v = 444;
21889 t.w = 667;
21890 t.x = 444;
21891 t.y = 444;
21892 t.z = 389;
21893 t.braceleft = 400;
21894 t.bar = 275;
21895 t.braceright = 400;
21896 t.asciitilde = 541;
21897 t.exclamdown = 389;
21898 t.cent = 500;
21899 t.sterling = 500;
21900 t.fraction = 167;
21901 t.yen = 500;
21902 t.florin = 500;
21903 t.section = 500;
21904 t.currency = 500;
21905 t.quotesingle = 214;
21906 t.quotedblleft = 556;
21907 t.guillemotleft = 500;
21908 t.guilsinglleft = 333;
21909 t.guilsinglright = 333;
21910 t.fi = 500;
21911 t.fl = 500;
21912 t.endash = 500;
21913 t.dagger = 500;
21914 t.daggerdbl = 500;
21915 t.periodcentered = 250;
21916 t.paragraph = 523;
21917 t.bullet = 350;
21918 t.quotesinglbase = 333;
21919 t.quotedblbase = 556;
21920 t.quotedblright = 556;
21921 t.guillemotright = 500;
21922 t.ellipsis = 889;
21923 t.perthousand = 1000;
21924 t.questiondown = 500;
21925 t.grave = 333;
21926 t.acute = 333;
21927 t.circumflex = 333;
21928 t.tilde = 333;
21929 t.macron = 333;
21930 t.breve = 333;
21931 t.dotaccent = 333;
21932 t.dieresis = 333;
21933 t.ring = 333;
21934 t.cedilla = 333;
21935 t.hungarumlaut = 333;
21936 t.ogonek = 333;
21937 t.caron = 333;
21938 t.emdash = 889;
21939 t.AE = 889;
21940 t.ordfeminine = 276;
21941 t.Lslash = 556;
21942 t.Oslash = 722;
21943 t.OE = 944;
21944 t.ordmasculine = 310;
21945 t.ae = 667;
21946 t.dotlessi = 278;
21947 t.lslash = 278;
21948 t.oslash = 500;
21949 t.oe = 667;
21950 t.germandbls = 500;
21951 t.Idieresis = 333;
21952 t.eacute = 444;
21953 t.abreve = 500;
21954 t.uhungarumlaut = 500;
21955 t.ecaron = 444;
21956 t.Ydieresis = 556;
21957 t.divide = 675;
21958 t.Yacute = 556;
21959 t.Acircumflex = 611;
21960 t.aacute = 500;
21961 t.Ucircumflex = 722;
21962 t.yacute = 444;
21963 t.scommaaccent = 389;
21964 t.ecircumflex = 444;
21965 t.Uring = 722;
21966 t.Udieresis = 722;
21967 t.aogonek = 500;
21968 t.Uacute = 722;
21969 t.uogonek = 500;
21970 t.Edieresis = 611;
21971 t.Dcroat = 722;
21972 t.commaaccent = 250;
21973 t.copyright = 760;
21974 t.Emacron = 611;
21975 t.ccaron = 444;
21976 t.aring = 500;
21977 t.Ncommaaccent = 667;
21978 t.lacute = 278;
21979 t.agrave = 500;
21980 t.Tcommaaccent = 556;
21981 t.Cacute = 667;
21982 t.atilde = 500;
21983 t.Edotaccent = 611;
21984 t.scaron = 389;
21985 t.scedilla = 389;
21986 t.iacute = 278;
21987 t.lozenge = 471;
21988 t.Rcaron = 611;
21989 t.Gcommaaccent = 722;
21990 t.ucircumflex = 500;
21991 t.acircumflex = 500;
21992 t.Amacron = 611;
21993 t.rcaron = 389;
21994 t.ccedilla = 444;
21995 t.Zdotaccent = 556;
21996 t.Thorn = 611;
21997 t.Omacron = 722;
21998 t.Racute = 611;
21999 t.Sacute = 500;
22000 t.dcaron = 544;
22001 t.Umacron = 722;
22002 t.uring = 500;
22003 t.threesuperior = 300;
22004 t.Ograve = 722;
22005 t.Agrave = 611;
22006 t.Abreve = 611;
22007 t.multiply = 675;
22008 t.uacute = 500;
22009 t.Tcaron = 556;
22010 t.partialdiff = 476;
22011 t.ydieresis = 444;
22012 t.Nacute = 667;
22013 t.icircumflex = 278;
22014 t.Ecircumflex = 611;
22015 t.adieresis = 500;
22016 t.edieresis = 444;
22017 t.cacute = 444;
22018 t.nacute = 500;
22019 t.umacron = 500;
22020 t.Ncaron = 667;
22021 t.Iacute = 333;
22022 t.plusminus = 675;
22023 t.brokenbar = 275;
22024 t.registered = 760;
22025 t.Gbreve = 722;
22026 t.Idotaccent = 333;
22027 t.summation = 600;
22028 t.Egrave = 611;
22029 t.racute = 389;
22030 t.omacron = 500;
22031 t.Zacute = 556;
22032 t.Zcaron = 556;
22033 t.greaterequal = 549;
22034 t.Eth = 722;
22035 t.Ccedilla = 667;
22036 t.lcommaaccent = 278;
22037 t.tcaron = 300;
22038 t.eogonek = 444;
22039 t.Uogonek = 722;
22040 t.Aacute = 611;
22041 t.Adieresis = 611;
22042 t.egrave = 444;
22043 t.zacute = 389;
22044 t.iogonek = 278;
22045 t.Oacute = 722;
22046 t.oacute = 500;
22047 t.amacron = 500;
22048 t.sacute = 389;
22049 t.idieresis = 278;
22050 t.Ocircumflex = 722;
22051 t.Ugrave = 722;
22052 t.Delta = 612;
22053 t.thorn = 500;
22054 t.twosuperior = 300;
22055 t.Odieresis = 722;
22056 t.mu = 500;
22057 t.igrave = 278;
22058 t.ohungarumlaut = 500;
22059 t.Eogonek = 611;
22060 t.dcroat = 500;
22061 t.threequarters = 750;
22062 t.Scedilla = 500;
22063 t.lcaron = 300;
22064 t.Kcommaaccent = 667;
22065 t.Lacute = 556;
22066 t.trademark = 980;
22067 t.edotaccent = 444;
22068 t.Igrave = 333;
22069 t.Imacron = 333;
22070 t.Lcaron = 611;
22071 t.onehalf = 750;
22072 t.lessequal = 549;
22073 t.ocircumflex = 500;
22074 t.ntilde = 500;
22075 t.Uhungarumlaut = 722;
22076 t.Eacute = 611;
22077 t.emacron = 444;
22078 t.gbreve = 500;
22079 t.onequarter = 750;
22080 t.Scaron = 500;
22081 t.Scommaaccent = 500;
22082 t.Ohungarumlaut = 722;
22083 t.degree = 400;
22084 t.ograve = 500;
22085 t.Ccaron = 667;
22086 t.ugrave = 500;
22087 t.radical = 453;
22088 t.Dcaron = 722;
22089 t.rcommaaccent = 389;
22090 t.Ntilde = 667;
22091 t.otilde = 500;
22092 t.Rcommaaccent = 611;
22093 t.Lcommaaccent = 556;
22094 t.Atilde = 611;
22095 t.Aogonek = 611;
22096 t.Aring = 611;
22097 t.Otilde = 722;
22098 t.zdotaccent = 389;
22099 t.Ecaron = 611;
22100 t.Iogonek = 333;
22101 t.kcommaaccent = 444;
22102 t.minus = 675;
22103 t.Icircumflex = 333;
22104 t.ncaron = 500;
22105 t.tcommaaccent = 278;
22106 t.logicalnot = 675;
22107 t.odieresis = 500;
22108 t.udieresis = 500;
22109 t.notequal = 549;
22110 t.gcommaaccent = 500;
22111 t.eth = 500;
22112 t.zcaron = 389;
22113 t.ncommaaccent = 500;
22114 t.onesuperior = 300;
22115 t.imacron = 278;
22116 t.Euro = 500;
22117 });
22118 t.ZapfDingbats = getLookupTableFactory(function (t) {
22119 t.space = 278;
22120 t.a1 = 974;
22121 t.a2 = 961;
22122 t.a202 = 974;
22123 t.a3 = 980;
22124 t.a4 = 719;
22125 t.a5 = 789;
22126 t.a119 = 790;
22127 t.a118 = 791;
22128 t.a117 = 690;
22129 t.a11 = 960;
22130 t.a12 = 939;
22131 t.a13 = 549;
22132 t.a14 = 855;
22133 t.a15 = 911;
22134 t.a16 = 933;
22135 t.a105 = 911;
22136 t.a17 = 945;
22137 t.a18 = 974;
22138 t.a19 = 755;
22139 t.a20 = 846;
22140 t.a21 = 762;
22141 t.a22 = 761;
22142 t.a23 = 571;
22143 t.a24 = 677;
22144 t.a25 = 763;
22145 t.a26 = 760;
22146 t.a27 = 759;
22147 t.a28 = 754;
22148 t.a6 = 494;
22149 t.a7 = 552;
22150 t.a8 = 537;
22151 t.a9 = 577;
22152 t.a10 = 692;
22153 t.a29 = 786;
22154 t.a30 = 788;
22155 t.a31 = 788;
22156 t.a32 = 790;
22157 t.a33 = 793;
22158 t.a34 = 794;
22159 t.a35 = 816;
22160 t.a36 = 823;
22161 t.a37 = 789;
22162 t.a38 = 841;
22163 t.a39 = 823;
22164 t.a40 = 833;
22165 t.a41 = 816;
22166 t.a42 = 831;
22167 t.a43 = 923;
22168 t.a44 = 744;
22169 t.a45 = 723;
22170 t.a46 = 749;
22171 t.a47 = 790;
22172 t.a48 = 792;
22173 t.a49 = 695;
22174 t.a50 = 776;
22175 t.a51 = 768;
22176 t.a52 = 792;
22177 t.a53 = 759;
22178 t.a54 = 707;
22179 t.a55 = 708;
22180 t.a56 = 682;
22181 t.a57 = 701;
22182 t.a58 = 826;
22183 t.a59 = 815;
22184 t.a60 = 789;
22185 t.a61 = 789;
22186 t.a62 = 707;
22187 t.a63 = 687;
22188 t.a64 = 696;
22189 t.a65 = 689;
22190 t.a66 = 786;
22191 t.a67 = 787;
22192 t.a68 = 713;
22193 t.a69 = 791;
22194 t.a70 = 785;
22195 t.a71 = 791;
22196 t.a72 = 873;
22197 t.a73 = 761;
22198 t.a74 = 762;
22199 t.a203 = 762;
22200 t.a75 = 759;
22201 t.a204 = 759;
22202 t.a76 = 892;
22203 t.a77 = 892;
22204 t.a78 = 788;
22205 t.a79 = 784;
22206 t.a81 = 438;
22207 t.a82 = 138;
22208 t.a83 = 277;
22209 t.a84 = 415;
22210 t.a97 = 392;
22211 t.a98 = 392;
22212 t.a99 = 668;
22213 t.a100 = 668;
22214 t.a89 = 390;
22215 t.a90 = 390;
22216 t.a93 = 317;
22217 t.a94 = 317;
22218 t.a91 = 276;
22219 t.a92 = 276;
22220 t.a205 = 509;
22221 t.a85 = 509;
22222 t.a206 = 410;
22223 t.a86 = 410;
22224 t.a87 = 234;
22225 t.a88 = 234;
22226 t.a95 = 334;
22227 t.a96 = 334;
22228 t.a101 = 732;
22229 t.a102 = 544;
22230 t.a103 = 544;
22231 t.a104 = 910;
22232 t.a106 = 667;
22233 t.a107 = 760;
22234 t.a108 = 760;
22235 t.a112 = 776;
22236 t.a111 = 595;
22237 t.a110 = 694;
22238 t.a109 = 626;
22239 t.a120 = 788;
22240 t.a121 = 788;
22241 t.a122 = 788;
22242 t.a123 = 788;
22243 t.a124 = 788;
22244 t.a125 = 788;
22245 t.a126 = 788;
22246 t.a127 = 788;
22247 t.a128 = 788;
22248 t.a129 = 788;
22249 t.a130 = 788;
22250 t.a131 = 788;
22251 t.a132 = 788;
22252 t.a133 = 788;
22253 t.a134 = 788;
22254 t.a135 = 788;
22255 t.a136 = 788;
22256 t.a137 = 788;
22257 t.a138 = 788;
22258 t.a139 = 788;
22259 t.a140 = 788;
22260 t.a141 = 788;
22261 t.a142 = 788;
22262 t.a143 = 788;
22263 t.a144 = 788;
22264 t.a145 = 788;
22265 t.a146 = 788;
22266 t.a147 = 788;
22267 t.a148 = 788;
22268 t.a149 = 788;
22269 t.a150 = 788;
22270 t.a151 = 788;
22271 t.a152 = 788;
22272 t.a153 = 788;
22273 t.a154 = 788;
22274 t.a155 = 788;
22275 t.a156 = 788;
22276 t.a157 = 788;
22277 t.a158 = 788;
22278 t.a159 = 788;
22279 t.a160 = 894;
22280 t.a161 = 838;
22281 t.a163 = 1016;
22282 t.a164 = 458;
22283 t.a196 = 748;
22284 t.a165 = 924;
22285 t.a192 = 748;
22286 t.a166 = 918;
22287 t.a167 = 927;
22288 t.a168 = 928;
22289 t.a169 = 928;
22290 t.a170 = 834;
22291 t.a171 = 873;
22292 t.a172 = 828;
22293 t.a173 = 924;
22294 t.a162 = 924;
22295 t.a174 = 917;
22296 t.a175 = 930;
22297 t.a176 = 931;
22298 t.a177 = 463;
22299 t.a178 = 883;
22300 t.a179 = 836;
22301 t.a193 = 836;
22302 t.a180 = 867;
22303 t.a199 = 867;
22304 t.a181 = 696;
22305 t.a200 = 696;
22306 t.a182 = 874;
22307 t.a201 = 874;
22308 t.a183 = 760;
22309 t.a184 = 946;
22310 t.a197 = 771;
22311 t.a185 = 865;
22312 t.a194 = 771;
22313 t.a198 = 888;
22314 t.a186 = 967;
22315 t.a195 = 888;
22316 t.a187 = 831;
22317 t.a188 = 873;
22318 t.a189 = 927;
22319 t.a190 = 970;
22320 t.a191 = 918;
22321 });
22322});
22323const getFontBasicMetrics = getLookupTableFactory(function (t) {
22324 t.Courier = {
22325 ascent: 629,
22326 descent: -157,
22327 capHeight: 562,
22328 xHeight: -426
22329 };
22330 t["Courier-Bold"] = {
22331 ascent: 629,
22332 descent: -157,
22333 capHeight: 562,
22334 xHeight: 439
22335 };
22336 t["Courier-Oblique"] = {
22337 ascent: 629,
22338 descent: -157,
22339 capHeight: 562,
22340 xHeight: 426
22341 };
22342 t["Courier-BoldOblique"] = {
22343 ascent: 629,
22344 descent: -157,
22345 capHeight: 562,
22346 xHeight: 426
22347 };
22348 t.Helvetica = {
22349 ascent: 718,
22350 descent: -207,
22351 capHeight: 718,
22352 xHeight: 523
22353 };
22354 t["Helvetica-Bold"] = {
22355 ascent: 718,
22356 descent: -207,
22357 capHeight: 718,
22358 xHeight: 532
22359 };
22360 t["Helvetica-Oblique"] = {
22361 ascent: 718,
22362 descent: -207,
22363 capHeight: 718,
22364 xHeight: 523
22365 };
22366 t["Helvetica-BoldOblique"] = {
22367 ascent: 718,
22368 descent: -207,
22369 capHeight: 718,
22370 xHeight: 532
22371 };
22372 t["Times-Roman"] = {
22373 ascent: 683,
22374 descent: -217,
22375 capHeight: 662,
22376 xHeight: 450
22377 };
22378 t["Times-Bold"] = {
22379 ascent: 683,
22380 descent: -217,
22381 capHeight: 676,
22382 xHeight: 461
22383 };
22384 t["Times-Italic"] = {
22385 ascent: 683,
22386 descent: -217,
22387 capHeight: 653,
22388 xHeight: 441
22389 };
22390 t["Times-BoldItalic"] = {
22391 ascent: 683,
22392 descent: -217,
22393 capHeight: 669,
22394 xHeight: 462
22395 };
22396 t.Symbol = {
22397 ascent: Math.NaN,
22398 descent: Math.NaN,
22399 capHeight: Math.NaN,
22400 xHeight: Math.NaN
22401 };
22402 t.ZapfDingbats = {
22403 ascent: Math.NaN,
22404 descent: Math.NaN,
22405 capHeight: Math.NaN,
22406 xHeight: Math.NaN
22407 };
22408});
22409
22410;// CONCATENATED MODULE: ./src/core/glyf.js
22411const ON_CURVE_POINT = 1 << 0;
22412const X_SHORT_VECTOR = 1 << 1;
22413const Y_SHORT_VECTOR = 1 << 2;
22414const REPEAT_FLAG = 1 << 3;
22415const X_IS_SAME_OR_POSITIVE_X_SHORT_VECTOR = 1 << 4;
22416const Y_IS_SAME_OR_POSITIVE_Y_SHORT_VECTOR = 1 << 5;
22417const OVERLAP_SIMPLE = 1 << 6;
22418const ARG_1_AND_2_ARE_WORDS = 1 << 0;
22419const ARGS_ARE_XY_VALUES = 1 << 1;
22420const WE_HAVE_A_SCALE = 1 << 3;
22421const MORE_COMPONENTS = 1 << 5;
22422const WE_HAVE_AN_X_AND_Y_SCALE = 1 << 6;
22423const WE_HAVE_A_TWO_BY_TWO = 1 << 7;
22424const WE_HAVE_INSTRUCTIONS = 1 << 8;
22425class GlyfTable {
22426 constructor({
22427 glyfTable,
22428 isGlyphLocationsLong,
22429 locaTable,
22430 numGlyphs
22431 }) {
22432 this.glyphs = [];
22433 const loca = new DataView(locaTable.buffer, locaTable.byteOffset, locaTable.byteLength);
22434 const glyf = new DataView(glyfTable.buffer, glyfTable.byteOffset, glyfTable.byteLength);
22435 const offsetSize = isGlyphLocationsLong ? 4 : 2;
22436 let prev = isGlyphLocationsLong ? loca.getUint32(0) : 2 * loca.getUint16(0);
22437 let pos = 0;
22438 for (let i = 0; i < numGlyphs; i++) {
22439 pos += offsetSize;
22440 const next = isGlyphLocationsLong ? loca.getUint32(pos) : 2 * loca.getUint16(pos);
22441 if (next === prev) {
22442 this.glyphs.push(new Glyph({}));
22443 continue;
22444 }
22445 const glyph = Glyph.parse(prev, glyf);
22446 this.glyphs.push(glyph);
22447 prev = next;
22448 }
22449 }
22450 getSize() {
22451 return this.glyphs.reduce((a, g) => {
22452 const size = g.getSize();
22453 return a + (size + 3 & ~3);
22454 }, 0);
22455 }
22456 write() {
22457 const totalSize = this.getSize();
22458 const glyfTable = new DataView(new ArrayBuffer(totalSize));
22459 const isLocationLong = totalSize > 0x1fffe;
22460 const offsetSize = isLocationLong ? 4 : 2;
22461 const locaTable = new DataView(new ArrayBuffer((this.glyphs.length + 1) * offsetSize));
22462 if (isLocationLong) {
22463 locaTable.setUint32(0, 0);
22464 } else {
22465 locaTable.setUint16(0, 0);
22466 }
22467 let pos = 0;
22468 let locaIndex = 0;
22469 for (const glyph of this.glyphs) {
22470 pos += glyph.write(pos, glyfTable);
22471 pos = pos + 3 & ~3;
22472 locaIndex += offsetSize;
22473 if (isLocationLong) {
22474 locaTable.setUint32(locaIndex, pos);
22475 } else {
22476 locaTable.setUint16(locaIndex, pos >> 1);
22477 }
22478 }
22479 return {
22480 isLocationLong,
22481 loca: new Uint8Array(locaTable.buffer),
22482 glyf: new Uint8Array(glyfTable.buffer)
22483 };
22484 }
22485 scale(factors) {
22486 for (let i = 0, ii = this.glyphs.length; i < ii; i++) {
22487 this.glyphs[i].scale(factors[i]);
22488 }
22489 }
22490}
22491class Glyph {
22492 constructor({
22493 header = null,
22494 simple = null,
22495 composites = null
22496 }) {
22497 this.header = header;
22498 this.simple = simple;
22499 this.composites = composites;
22500 }
22501 static parse(pos, glyf) {
22502 const [read, header] = GlyphHeader.parse(pos, glyf);
22503 pos += read;
22504 if (header.numberOfContours < 0) {
22505 const composites = [];
22506 while (true) {
22507 const [n, composite] = CompositeGlyph.parse(pos, glyf);
22508 pos += n;
22509 composites.push(composite);
22510 if (!(composite.flags & MORE_COMPONENTS)) {
22511 break;
22512 }
22513 }
22514 return new Glyph({
22515 header,
22516 composites
22517 });
22518 }
22519 const simple = SimpleGlyph.parse(pos, glyf, header.numberOfContours);
22520 return new Glyph({
22521 header,
22522 simple
22523 });
22524 }
22525 getSize() {
22526 if (!this.header) {
22527 return 0;
22528 }
22529 const size = this.simple ? this.simple.getSize() : this.composites.reduce((a, c) => a + c.getSize(), 0);
22530 return this.header.getSize() + size;
22531 }
22532 write(pos, buf) {
22533 if (!this.header) {
22534 return 0;
22535 }
22536 const spos = pos;
22537 pos += this.header.write(pos, buf);
22538 if (this.simple) {
22539 pos += this.simple.write(pos, buf);
22540 } else {
22541 for (const composite of this.composites) {
22542 pos += composite.write(pos, buf);
22543 }
22544 }
22545 return pos - spos;
22546 }
22547 scale(factor) {
22548 if (!this.header) {
22549 return;
22550 }
22551 const xMiddle = (this.header.xMin + this.header.xMax) / 2;
22552 this.header.scale(xMiddle, factor);
22553 if (this.simple) {
22554 this.simple.scale(xMiddle, factor);
22555 } else {
22556 for (const composite of this.composites) {
22557 composite.scale(xMiddle, factor);
22558 }
22559 }
22560 }
22561}
22562class GlyphHeader {
22563 constructor({
22564 numberOfContours,
22565 xMin,
22566 yMin,
22567 xMax,
22568 yMax
22569 }) {
22570 this.numberOfContours = numberOfContours;
22571 this.xMin = xMin;
22572 this.yMin = yMin;
22573 this.xMax = xMax;
22574 this.yMax = yMax;
22575 }
22576 static parse(pos, glyf) {
22577 return [10, new GlyphHeader({
22578 numberOfContours: glyf.getInt16(pos),
22579 xMin: glyf.getInt16(pos + 2),
22580 yMin: glyf.getInt16(pos + 4),
22581 xMax: glyf.getInt16(pos + 6),
22582 yMax: glyf.getInt16(pos + 8)
22583 })];
22584 }
22585 getSize() {
22586 return 10;
22587 }
22588 write(pos, buf) {
22589 buf.setInt16(pos, this.numberOfContours);
22590 buf.setInt16(pos + 2, this.xMin);
22591 buf.setInt16(pos + 4, this.yMin);
22592 buf.setInt16(pos + 6, this.xMax);
22593 buf.setInt16(pos + 8, this.yMax);
22594 return 10;
22595 }
22596 scale(x, factor) {
22597 this.xMin = Math.round(x + (this.xMin - x) * factor);
22598 this.xMax = Math.round(x + (this.xMax - x) * factor);
22599 }
22600}
22601class Contour {
22602 constructor({
22603 flags,
22604 xCoordinates,
22605 yCoordinates
22606 }) {
22607 this.xCoordinates = xCoordinates;
22608 this.yCoordinates = yCoordinates;
22609 this.flags = flags;
22610 }
22611}
22612class SimpleGlyph {
22613 constructor({
22614 contours,
22615 instructions
22616 }) {
22617 this.contours = contours;
22618 this.instructions = instructions;
22619 }
22620 static parse(pos, glyf, numberOfContours) {
22621 const endPtsOfContours = [];
22622 for (let i = 0; i < numberOfContours; i++) {
22623 const endPt = glyf.getUint16(pos);
22624 pos += 2;
22625 endPtsOfContours.push(endPt);
22626 }
22627 const numberOfPt = endPtsOfContours[numberOfContours - 1] + 1;
22628 const instructionLength = glyf.getUint16(pos);
22629 pos += 2;
22630 const instructions = new Uint8Array(glyf).slice(pos, pos + instructionLength);
22631 pos += instructionLength;
22632 const flags = [];
22633 for (let i = 0; i < numberOfPt; pos++, i++) {
22634 let flag = glyf.getUint8(pos);
22635 flags.push(flag);
22636 if (flag & REPEAT_FLAG) {
22637 const count = glyf.getUint8(++pos);
22638 flag ^= REPEAT_FLAG;
22639 for (let m = 0; m < count; m++) {
22640 flags.push(flag);
22641 }
22642 i += count;
22643 }
22644 }
22645 const allXCoordinates = [];
22646 let xCoordinates = [];
22647 let yCoordinates = [];
22648 let pointFlags = [];
22649 const contours = [];
22650 let endPtsOfContoursIndex = 0;
22651 let lastCoordinate = 0;
22652 for (let i = 0; i < numberOfPt; i++) {
22653 const flag = flags[i];
22654 if (flag & X_SHORT_VECTOR) {
22655 const x = glyf.getUint8(pos++);
22656 lastCoordinate += flag & X_IS_SAME_OR_POSITIVE_X_SHORT_VECTOR ? x : -x;
22657 xCoordinates.push(lastCoordinate);
22658 } else if (flag & X_IS_SAME_OR_POSITIVE_X_SHORT_VECTOR) {
22659 xCoordinates.push(lastCoordinate);
22660 } else {
22661 lastCoordinate += glyf.getInt16(pos);
22662 pos += 2;
22663 xCoordinates.push(lastCoordinate);
22664 }
22665 if (endPtsOfContours[endPtsOfContoursIndex] === i) {
22666 endPtsOfContoursIndex++;
22667 allXCoordinates.push(xCoordinates);
22668 xCoordinates = [];
22669 }
22670 }
22671 lastCoordinate = 0;
22672 endPtsOfContoursIndex = 0;
22673 for (let i = 0; i < numberOfPt; i++) {
22674 const flag = flags[i];
22675 if (flag & Y_SHORT_VECTOR) {
22676 const y = glyf.getUint8(pos++);
22677 lastCoordinate += flag & Y_IS_SAME_OR_POSITIVE_Y_SHORT_VECTOR ? y : -y;
22678 yCoordinates.push(lastCoordinate);
22679 } else if (flag & Y_IS_SAME_OR_POSITIVE_Y_SHORT_VECTOR) {
22680 yCoordinates.push(lastCoordinate);
22681 } else {
22682 lastCoordinate += glyf.getInt16(pos);
22683 pos += 2;
22684 yCoordinates.push(lastCoordinate);
22685 }
22686 pointFlags.push(flag & ON_CURVE_POINT | flag & OVERLAP_SIMPLE);
22687 if (endPtsOfContours[endPtsOfContoursIndex] === i) {
22688 xCoordinates = allXCoordinates[endPtsOfContoursIndex];
22689 endPtsOfContoursIndex++;
22690 contours.push(new Contour({
22691 flags: pointFlags,
22692 xCoordinates,
22693 yCoordinates
22694 }));
22695 yCoordinates = [];
22696 pointFlags = [];
22697 }
22698 }
22699 return new SimpleGlyph({
22700 contours,
22701 instructions
22702 });
22703 }
22704 getSize() {
22705 let size = this.contours.length * 2 + 2 + this.instructions.length;
22706 let lastX = 0;
22707 let lastY = 0;
22708 for (const contour of this.contours) {
22709 size += contour.flags.length;
22710 for (let i = 0, ii = contour.xCoordinates.length; i < ii; i++) {
22711 const x = contour.xCoordinates[i];
22712 const y = contour.yCoordinates[i];
22713 let abs = Math.abs(x - lastX);
22714 if (abs > 255) {
22715 size += 2;
22716 } else if (abs > 0) {
22717 size += 1;
22718 }
22719 lastX = x;
22720 abs = Math.abs(y - lastY);
22721 if (abs > 255) {
22722 size += 2;
22723 } else if (abs > 0) {
22724 size += 1;
22725 }
22726 lastY = y;
22727 }
22728 }
22729 return size;
22730 }
22731 write(pos, buf) {
22732 const spos = pos;
22733 const xCoordinates = [];
22734 const yCoordinates = [];
22735 const flags = [];
22736 let lastX = 0;
22737 let lastY = 0;
22738 for (const contour of this.contours) {
22739 for (let i = 0, ii = contour.xCoordinates.length; i < ii; i++) {
22740 let flag = contour.flags[i];
22741 const x = contour.xCoordinates[i];
22742 let delta = x - lastX;
22743 if (delta === 0) {
22744 flag |= X_IS_SAME_OR_POSITIVE_X_SHORT_VECTOR;
22745 xCoordinates.push(0);
22746 } else {
22747 const abs = Math.abs(delta);
22748 if (abs <= 255) {
22749 flag |= delta >= 0 ? X_SHORT_VECTOR | X_IS_SAME_OR_POSITIVE_X_SHORT_VECTOR : X_SHORT_VECTOR;
22750 xCoordinates.push(abs);
22751 } else {
22752 xCoordinates.push(delta);
22753 }
22754 }
22755 lastX = x;
22756 const y = contour.yCoordinates[i];
22757 delta = y - lastY;
22758 if (delta === 0) {
22759 flag |= Y_IS_SAME_OR_POSITIVE_Y_SHORT_VECTOR;
22760 yCoordinates.push(0);
22761 } else {
22762 const abs = Math.abs(delta);
22763 if (abs <= 255) {
22764 flag |= delta >= 0 ? Y_SHORT_VECTOR | Y_IS_SAME_OR_POSITIVE_Y_SHORT_VECTOR : Y_SHORT_VECTOR;
22765 yCoordinates.push(abs);
22766 } else {
22767 yCoordinates.push(delta);
22768 }
22769 }
22770 lastY = y;
22771 flags.push(flag);
22772 }
22773 buf.setUint16(pos, xCoordinates.length - 1);
22774 pos += 2;
22775 }
22776 buf.setUint16(pos, this.instructions.length);
22777 pos += 2;
22778 if (this.instructions.length) {
22779 new Uint8Array(buf.buffer, 0, buf.buffer.byteLength).set(this.instructions, pos);
22780 pos += this.instructions.length;
22781 }
22782 for (const flag of flags) {
22783 buf.setUint8(pos++, flag);
22784 }
22785 for (let i = 0, ii = xCoordinates.length; i < ii; i++) {
22786 const x = xCoordinates[i];
22787 const flag = flags[i];
22788 if (flag & X_SHORT_VECTOR) {
22789 buf.setUint8(pos++, x);
22790 } else if (!(flag & X_IS_SAME_OR_POSITIVE_X_SHORT_VECTOR)) {
22791 buf.setInt16(pos, x);
22792 pos += 2;
22793 }
22794 }
22795 for (let i = 0, ii = yCoordinates.length; i < ii; i++) {
22796 const y = yCoordinates[i];
22797 const flag = flags[i];
22798 if (flag & Y_SHORT_VECTOR) {
22799 buf.setUint8(pos++, y);
22800 } else if (!(flag & Y_IS_SAME_OR_POSITIVE_Y_SHORT_VECTOR)) {
22801 buf.setInt16(pos, y);
22802 pos += 2;
22803 }
22804 }
22805 return pos - spos;
22806 }
22807 scale(x, factor) {
22808 for (const contour of this.contours) {
22809 if (contour.xCoordinates.length === 0) {
22810 continue;
22811 }
22812 for (let i = 0, ii = contour.xCoordinates.length; i < ii; i++) {
22813 contour.xCoordinates[i] = Math.round(x + (contour.xCoordinates[i] - x) * factor);
22814 }
22815 }
22816 }
22817}
22818class CompositeGlyph {
22819 constructor({
22820 flags,
22821 glyphIndex,
22822 argument1,
22823 argument2,
22824 transf,
22825 instructions
22826 }) {
22827 this.flags = flags;
22828 this.glyphIndex = glyphIndex;
22829 this.argument1 = argument1;
22830 this.argument2 = argument2;
22831 this.transf = transf;
22832 this.instructions = instructions;
22833 }
22834 static parse(pos, glyf) {
22835 const spos = pos;
22836 const transf = [];
22837 let flags = glyf.getUint16(pos);
22838 const glyphIndex = glyf.getUint16(pos + 2);
22839 pos += 4;
22840 let argument1, argument2;
22841 if (flags & ARG_1_AND_2_ARE_WORDS) {
22842 if (flags & ARGS_ARE_XY_VALUES) {
22843 argument1 = glyf.getInt16(pos);
22844 argument2 = glyf.getInt16(pos + 2);
22845 } else {
22846 argument1 = glyf.getUint16(pos);
22847 argument2 = glyf.getUint16(pos + 2);
22848 }
22849 pos += 4;
22850 flags ^= ARG_1_AND_2_ARE_WORDS;
22851 } else {
22852 if (flags & ARGS_ARE_XY_VALUES) {
22853 argument1 = glyf.getInt8(pos);
22854 argument2 = glyf.getInt8(pos + 1);
22855 } else {
22856 argument1 = glyf.getUint8(pos);
22857 argument2 = glyf.getUint8(pos + 1);
22858 }
22859 pos += 2;
22860 }
22861 if (flags & WE_HAVE_A_SCALE) {
22862 transf.push(glyf.getUint16(pos));
22863 pos += 2;
22864 } else if (flags & WE_HAVE_AN_X_AND_Y_SCALE) {
22865 transf.push(glyf.getUint16(pos), glyf.getUint16(pos + 2));
22866 pos += 4;
22867 } else if (flags & WE_HAVE_A_TWO_BY_TWO) {
22868 transf.push(glyf.getUint16(pos), glyf.getUint16(pos + 2), glyf.getUint16(pos + 4), glyf.getUint16(pos + 6));
22869 pos += 8;
22870 }
22871 let instructions = null;
22872 if (flags & WE_HAVE_INSTRUCTIONS) {
22873 const instructionLength = glyf.getUint16(pos);
22874 pos += 2;
22875 instructions = new Uint8Array(glyf).slice(pos, pos + instructionLength);
22876 pos += instructionLength;
22877 }
22878 return [pos - spos, new CompositeGlyph({
22879 flags,
22880 glyphIndex,
22881 argument1,
22882 argument2,
22883 transf,
22884 instructions
22885 })];
22886 }
22887 getSize() {
22888 let size = 2 + 2 + this.transf.length * 2;
22889 if (this.flags & WE_HAVE_INSTRUCTIONS) {
22890 size += 2 + this.instructions.length;
22891 }
22892 size += 2;
22893 if (this.flags & 2) {
22894 if (!(this.argument1 >= -128 && this.argument1 <= 127 && this.argument2 >= -128 && this.argument2 <= 127)) {
22895 size += 2;
22896 }
22897 } else if (!(this.argument1 >= 0 && this.argument1 <= 255 && this.argument2 >= 0 && this.argument2 <= 255)) {
22898 size += 2;
22899 }
22900 return size;
22901 }
22902 write(pos, buf) {
22903 const spos = pos;
22904 if (this.flags & ARGS_ARE_XY_VALUES) {
22905 if (!(this.argument1 >= -128 && this.argument1 <= 127 && this.argument2 >= -128 && this.argument2 <= 127)) {
22906 this.flags |= ARG_1_AND_2_ARE_WORDS;
22907 }
22908 } else if (!(this.argument1 >= 0 && this.argument1 <= 255 && this.argument2 >= 0 && this.argument2 <= 255)) {
22909 this.flags |= ARG_1_AND_2_ARE_WORDS;
22910 }
22911 buf.setUint16(pos, this.flags);
22912 buf.setUint16(pos + 2, this.glyphIndex);
22913 pos += 4;
22914 if (this.flags & ARG_1_AND_2_ARE_WORDS) {
22915 if (this.flags & ARGS_ARE_XY_VALUES) {
22916 buf.setInt16(pos, this.argument1);
22917 buf.setInt16(pos + 2, this.argument2);
22918 } else {
22919 buf.setUint16(pos, this.argument1);
22920 buf.setUint16(pos + 2, this.argument2);
22921 }
22922 pos += 4;
22923 } else {
22924 buf.setUint8(pos, this.argument1);
22925 buf.setUint8(pos + 1, this.argument2);
22926 pos += 2;
22927 }
22928 if (this.flags & WE_HAVE_INSTRUCTIONS) {
22929 buf.setUint16(pos, this.instructions.length);
22930 pos += 2;
22931 if (this.instructions.length) {
22932 new Uint8Array(buf.buffer, 0, buf.buffer.byteLength).set(this.instructions, pos);
22933 pos += this.instructions.length;
22934 }
22935 }
22936 return pos - spos;
22937 }
22938 scale(x, factor) {}
22939}
22940
22941;// CONCATENATED MODULE: ./src/core/opentype_file_builder.js
22942
22943
22944function writeInt16(dest, offset, num) {
22945 dest[offset] = num >> 8 & 0xff;
22946 dest[offset + 1] = num & 0xff;
22947}
22948function writeInt32(dest, offset, num) {
22949 dest[offset] = num >> 24 & 0xff;
22950 dest[offset + 1] = num >> 16 & 0xff;
22951 dest[offset + 2] = num >> 8 & 0xff;
22952 dest[offset + 3] = num & 0xff;
22953}
22954function writeData(dest, offset, data) {
22955 if (data instanceof Uint8Array) {
22956 dest.set(data, offset);
22957 } else if (typeof data === "string") {
22958 for (let i = 0, ii = data.length; i < ii; i++) {
22959 dest[offset++] = data.charCodeAt(i) & 0xff;
22960 }
22961 } else {
22962 for (const num of data) {
22963 dest[offset++] = num & 0xff;
22964 }
22965 }
22966}
22967const OTF_HEADER_SIZE = 12;
22968const OTF_TABLE_ENTRY_SIZE = 16;
22969class OpenTypeFileBuilder {
22970 constructor(sfnt) {
22971 this.sfnt = sfnt;
22972 this.tables = Object.create(null);
22973 }
22974 static getSearchParams(entriesCount, entrySize) {
22975 let maxPower2 = 1,
22976 log2 = 0;
22977 while ((maxPower2 ^ entriesCount) > maxPower2) {
22978 maxPower2 <<= 1;
22979 log2++;
22980 }
22981 const searchRange = maxPower2 * entrySize;
22982 return {
22983 range: searchRange,
22984 entry: log2,
22985 rangeShift: entrySize * entriesCount - searchRange
22986 };
22987 }
22988 toArray() {
22989 let sfnt = this.sfnt;
22990 const tables = this.tables;
22991 const tablesNames = Object.keys(tables);
22992 tablesNames.sort();
22993 const numTables = tablesNames.length;
22994 let i, j, jj, table, tableName;
22995 let offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
22996 const tableOffsets = [offset];
22997 for (i = 0; i < numTables; i++) {
22998 table = tables[tablesNames[i]];
22999 const paddedLength = (table.length + 3 & ~3) >>> 0;
23000 offset += paddedLength;
23001 tableOffsets.push(offset);
23002 }
23003 const file = new Uint8Array(offset);
23004 for (i = 0; i < numTables; i++) {
23005 table = tables[tablesNames[i]];
23006 writeData(file, tableOffsets[i], table);
23007 }
23008 if (sfnt === "true") {
23009 sfnt = string32(0x00010000);
23010 }
23011 file[0] = sfnt.charCodeAt(0) & 0xff;
23012 file[1] = sfnt.charCodeAt(1) & 0xff;
23013 file[2] = sfnt.charCodeAt(2) & 0xff;
23014 file[3] = sfnt.charCodeAt(3) & 0xff;
23015 writeInt16(file, 4, numTables);
23016 const searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
23017 writeInt16(file, 6, searchParams.range);
23018 writeInt16(file, 8, searchParams.entry);
23019 writeInt16(file, 10, searchParams.rangeShift);
23020 offset = OTF_HEADER_SIZE;
23021 for (i = 0; i < numTables; i++) {
23022 tableName = tablesNames[i];
23023 file[offset] = tableName.charCodeAt(0) & 0xff;
23024 file[offset + 1] = tableName.charCodeAt(1) & 0xff;
23025 file[offset + 2] = tableName.charCodeAt(2) & 0xff;
23026 file[offset + 3] = tableName.charCodeAt(3) & 0xff;
23027 let checksum = 0;
23028 for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
23029 const quad = readUint32(file, j);
23030 checksum = checksum + quad >>> 0;
23031 }
23032 writeInt32(file, offset + 4, checksum);
23033 writeInt32(file, offset + 8, tableOffsets[i]);
23034 writeInt32(file, offset + 12, tables[tableName].length);
23035 offset += OTF_TABLE_ENTRY_SIZE;
23036 }
23037 return file;
23038 }
23039 addTable(tag, data) {
23040 if (tag in this.tables) {
23041 throw new Error("Table " + tag + " already exists");
23042 }
23043 this.tables[tag] = data;
23044 }
23045}
23046
23047;// CONCATENATED MODULE: ./src/core/type1_parser.js
23048
23049
23050
23051
23052const HINTING_ENABLED = false;
23053const COMMAND_MAP = {
23054 hstem: [1],
23055 vstem: [3],
23056 vmoveto: [4],
23057 rlineto: [5],
23058 hlineto: [6],
23059 vlineto: [7],
23060 rrcurveto: [8],
23061 callsubr: [10],
23062 flex: [12, 35],
23063 drop: [12, 18],
23064 endchar: [14],
23065 rmoveto: [21],
23066 hmoveto: [22],
23067 vhcurveto: [30],
23068 hvcurveto: [31]
23069};
23070class Type1CharString {
23071 constructor() {
23072 this.width = 0;
23073 this.lsb = 0;
23074 this.flexing = false;
23075 this.output = [];
23076 this.stack = [];
23077 }
23078 convert(encoded, subrs, seacAnalysisEnabled) {
23079 const count = encoded.length;
23080 let error = false;
23081 let wx, sbx, subrNumber;
23082 for (let i = 0; i < count; i++) {
23083 let value = encoded[i];
23084 if (value < 32) {
23085 if (value === 12) {
23086 value = (value << 8) + encoded[++i];
23087 }
23088 switch (value) {
23089 case 1:
23090 if (!HINTING_ENABLED) {
23091 this.stack = [];
23092 break;
23093 }
23094 error = this.executeCommand(2, COMMAND_MAP.hstem);
23095 break;
23096 case 3:
23097 if (!HINTING_ENABLED) {
23098 this.stack = [];
23099 break;
23100 }
23101 error = this.executeCommand(2, COMMAND_MAP.vstem);
23102 break;
23103 case 4:
23104 if (this.flexing) {
23105 if (this.stack.length < 1) {
23106 error = true;
23107 break;
23108 }
23109 const dy = this.stack.pop();
23110 this.stack.push(0, dy);
23111 break;
23112 }
23113 error = this.executeCommand(1, COMMAND_MAP.vmoveto);
23114 break;
23115 case 5:
23116 error = this.executeCommand(2, COMMAND_MAP.rlineto);
23117 break;
23118 case 6:
23119 error = this.executeCommand(1, COMMAND_MAP.hlineto);
23120 break;
23121 case 7:
23122 error = this.executeCommand(1, COMMAND_MAP.vlineto);
23123 break;
23124 case 8:
23125 error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
23126 break;
23127 case 9:
23128 this.stack = [];
23129 break;
23130 case 10:
23131 if (this.stack.length < 1) {
23132 error = true;
23133 break;
23134 }
23135 subrNumber = this.stack.pop();
23136 if (!subrs[subrNumber]) {
23137 error = true;
23138 break;
23139 }
23140 error = this.convert(subrs[subrNumber], subrs, seacAnalysisEnabled);
23141 break;
23142 case 11:
23143 return error;
23144 case 13:
23145 if (this.stack.length < 2) {
23146 error = true;
23147 break;
23148 }
23149 wx = this.stack.pop();
23150 sbx = this.stack.pop();
23151 this.lsb = sbx;
23152 this.width = wx;
23153 this.stack.push(wx, sbx);
23154 error = this.executeCommand(2, COMMAND_MAP.hmoveto);
23155 break;
23156 case 14:
23157 this.output.push(COMMAND_MAP.endchar[0]);
23158 break;
23159 case 21:
23160 if (this.flexing) {
23161 break;
23162 }
23163 error = this.executeCommand(2, COMMAND_MAP.rmoveto);
23164 break;
23165 case 22:
23166 if (this.flexing) {
23167 this.stack.push(0);
23168 break;
23169 }
23170 error = this.executeCommand(1, COMMAND_MAP.hmoveto);
23171 break;
23172 case 30:
23173 error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
23174 break;
23175 case 31:
23176 error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
23177 break;
23178 case (12 << 8) + 0:
23179 this.stack = [];
23180 break;
23181 case (12 << 8) + 1:
23182 if (!HINTING_ENABLED) {
23183 this.stack = [];
23184 break;
23185 }
23186 error = this.executeCommand(2, COMMAND_MAP.vstem);
23187 break;
23188 case (12 << 8) + 2:
23189 if (!HINTING_ENABLED) {
23190 this.stack = [];
23191 break;
23192 }
23193 error = this.executeCommand(2, COMMAND_MAP.hstem);
23194 break;
23195 case (12 << 8) + 6:
23196 if (seacAnalysisEnabled) {
23197 const asb = this.stack.at(-5);
23198 this.seac = this.stack.splice(-4, 4);
23199 this.seac[0] += this.lsb - asb;
23200 error = this.executeCommand(0, COMMAND_MAP.endchar);
23201 } else {
23202 error = this.executeCommand(4, COMMAND_MAP.endchar);
23203 }
23204 break;
23205 case (12 << 8) + 7:
23206 if (this.stack.length < 4) {
23207 error = true;
23208 break;
23209 }
23210 this.stack.pop();
23211 wx = this.stack.pop();
23212 const sby = this.stack.pop();
23213 sbx = this.stack.pop();
23214 this.lsb = sbx;
23215 this.width = wx;
23216 this.stack.push(wx, sbx, sby);
23217 error = this.executeCommand(3, COMMAND_MAP.rmoveto);
23218 break;
23219 case (12 << 8) + 12:
23220 if (this.stack.length < 2) {
23221 error = true;
23222 break;
23223 }
23224 const num2 = this.stack.pop();
23225 const num1 = this.stack.pop();
23226 this.stack.push(num1 / num2);
23227 break;
23228 case (12 << 8) + 16:
23229 if (this.stack.length < 2) {
23230 error = true;
23231 break;
23232 }
23233 subrNumber = this.stack.pop();
23234 const numArgs = this.stack.pop();
23235 if (subrNumber === 0 && numArgs === 3) {
23236 const flexArgs = this.stack.splice(-17, 17);
23237 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]);
23238 error = this.executeCommand(13, COMMAND_MAP.flex, true);
23239 this.flexing = false;
23240 this.stack.push(flexArgs[15], flexArgs[16]);
23241 } else if (subrNumber === 1 && numArgs === 0) {
23242 this.flexing = true;
23243 }
23244 break;
23245 case (12 << 8) + 17:
23246 break;
23247 case (12 << 8) + 33:
23248 this.stack = [];
23249 break;
23250 default:
23251 warn('Unknown type 1 charstring command of "' + value + '"');
23252 break;
23253 }
23254 if (error) {
23255 break;
23256 }
23257 continue;
23258 } else if (value <= 246) {
23259 value -= 139;
23260 } else if (value <= 250) {
23261 value = (value - 247) * 256 + encoded[++i] + 108;
23262 } else if (value <= 254) {
23263 value = -((value - 251) * 256) - encoded[++i] - 108;
23264 } else {
23265 value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 | (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
23266 }
23267 this.stack.push(value);
23268 }
23269 return error;
23270 }
23271 executeCommand(howManyArgs, command, keepStack) {
23272 const stackLength = this.stack.length;
23273 if (howManyArgs > stackLength) {
23274 return true;
23275 }
23276 const start = stackLength - howManyArgs;
23277 for (let i = start; i < stackLength; i++) {
23278 let value = this.stack[i];
23279 if (Number.isInteger(value)) {
23280 this.output.push(28, value >> 8 & 0xff, value & 0xff);
23281 } else {
23282 value = 65536 * value | 0;
23283 this.output.push(255, value >> 24 & 0xff, value >> 16 & 0xff, value >> 8 & 0xff, value & 0xff);
23284 }
23285 }
23286 this.output.push(...command);
23287 if (keepStack) {
23288 this.stack.splice(start, howManyArgs);
23289 } else {
23290 this.stack.length = 0;
23291 }
23292 return false;
23293 }
23294}
23295const EEXEC_ENCRYPT_KEY = 55665;
23296const CHAR_STRS_ENCRYPT_KEY = 4330;
23297function isHexDigit(code) {
23298 return code >= 48 && code <= 57 || code >= 65 && code <= 70 || code >= 97 && code <= 102;
23299}
23300function decrypt(data, key, discardNumber) {
23301 if (discardNumber >= data.length) {
23302 return new Uint8Array(0);
23303 }
23304 const c1 = 52845,
23305 c2 = 22719;
23306 let r = key | 0,
23307 i,
23308 j;
23309 for (i = 0; i < discardNumber; i++) {
23310 r = (data[i] + r) * c1 + c2 & (1 << 16) - 1;
23311 }
23312 const count = data.length - discardNumber;
23313 const decrypted = new Uint8Array(count);
23314 for (i = discardNumber, j = 0; j < count; i++, j++) {
23315 const value = data[i];
23316 decrypted[j] = value ^ r >> 8;
23317 r = (value + r) * c1 + c2 & (1 << 16) - 1;
23318 }
23319 return decrypted;
23320}
23321function decryptAscii(data, key, discardNumber) {
23322 const c1 = 52845,
23323 c2 = 22719;
23324 let r = key | 0;
23325 const count = data.length,
23326 maybeLength = count >>> 1;
23327 const decrypted = new Uint8Array(maybeLength);
23328 let i, j;
23329 for (i = 0, j = 0; i < count; i++) {
23330 const digit1 = data[i];
23331 if (!isHexDigit(digit1)) {
23332 continue;
23333 }
23334 i++;
23335 let digit2;
23336 while (i < count && !isHexDigit(digit2 = data[i])) {
23337 i++;
23338 }
23339 if (i < count) {
23340 const value = parseInt(String.fromCharCode(digit1, digit2), 16);
23341 decrypted[j++] = value ^ r >> 8;
23342 r = (value + r) * c1 + c2 & (1 << 16) - 1;
23343 }
23344 }
23345 return decrypted.slice(discardNumber, j);
23346}
23347function isSpecial(c) {
23348 return c === 0x2f || c === 0x5b || c === 0x5d || c === 0x7b || c === 0x7d || c === 0x28 || c === 0x29;
23349}
23350class Type1Parser {
23351 constructor(stream, encrypted, seacAnalysisEnabled) {
23352 if (encrypted) {
23353 const data = stream.getBytes();
23354 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]));
23355 stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) : decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
23356 }
23357 this.seacAnalysisEnabled = !!seacAnalysisEnabled;
23358 this.stream = stream;
23359 this.nextChar();
23360 }
23361 readNumberArray() {
23362 this.getToken();
23363 const array = [];
23364 while (true) {
23365 const token = this.getToken();
23366 if (token === null || token === "]" || token === "}") {
23367 break;
23368 }
23369 array.push(parseFloat(token || 0));
23370 }
23371 return array;
23372 }
23373 readNumber() {
23374 const token = this.getToken();
23375 return parseFloat(token || 0);
23376 }
23377 readInt() {
23378 const token = this.getToken();
23379 return parseInt(token || 0, 10) | 0;
23380 }
23381 readBoolean() {
23382 const token = this.getToken();
23383 return token === "true" ? 1 : 0;
23384 }
23385 nextChar() {
23386 return this.currentChar = this.stream.getByte();
23387 }
23388 prevChar() {
23389 this.stream.skip(-2);
23390 return this.currentChar = this.stream.getByte();
23391 }
23392 getToken() {
23393 let comment = false;
23394 let ch = this.currentChar;
23395 while (true) {
23396 if (ch === -1) {
23397 return null;
23398 }
23399 if (comment) {
23400 if (ch === 0x0a || ch === 0x0d) {
23401 comment = false;
23402 }
23403 } else if (ch === 0x25) {
23404 comment = true;
23405 } else if (!isWhiteSpace(ch)) {
23406 break;
23407 }
23408 ch = this.nextChar();
23409 }
23410 if (isSpecial(ch)) {
23411 this.nextChar();
23412 return String.fromCharCode(ch);
23413 }
23414 let token = "";
23415 do {
23416 token += String.fromCharCode(ch);
23417 ch = this.nextChar();
23418 } while (ch >= 0 && !isWhiteSpace(ch) && !isSpecial(ch));
23419 return token;
23420 }
23421 readCharStrings(bytes, lenIV) {
23422 if (lenIV === -1) {
23423 return bytes;
23424 }
23425 return decrypt(bytes, CHAR_STRS_ENCRYPT_KEY, lenIV);
23426 }
23427 extractFontProgram(properties) {
23428 const stream = this.stream;
23429 const subrs = [],
23430 charstrings = [];
23431 const privateData = Object.create(null);
23432 privateData.lenIV = 4;
23433 const program = {
23434 subrs: [],
23435 charstrings: [],
23436 properties: {
23437 privateData
23438 }
23439 };
23440 let token, length, data, lenIV;
23441 while ((token = this.getToken()) !== null) {
23442 if (token !== "/") {
23443 continue;
23444 }
23445 token = this.getToken();
23446 switch (token) {
23447 case "CharStrings":
23448 this.getToken();
23449 this.getToken();
23450 this.getToken();
23451 this.getToken();
23452 while (true) {
23453 token = this.getToken();
23454 if (token === null || token === "end") {
23455 break;
23456 }
23457 if (token !== "/") {
23458 continue;
23459 }
23460 const glyph = this.getToken();
23461 length = this.readInt();
23462 this.getToken();
23463 data = length > 0 ? stream.getBytes(length) : new Uint8Array(0);
23464 lenIV = program.properties.privateData.lenIV;
23465 const encoded = this.readCharStrings(data, lenIV);
23466 this.nextChar();
23467 token = this.getToken();
23468 if (token === "noaccess") {
23469 this.getToken();
23470 } else if (token === "/") {
23471 this.prevChar();
23472 }
23473 charstrings.push({
23474 glyph,
23475 encoded
23476 });
23477 }
23478 break;
23479 case "Subrs":
23480 this.readInt();
23481 this.getToken();
23482 while (this.getToken() === "dup") {
23483 const index = this.readInt();
23484 length = this.readInt();
23485 this.getToken();
23486 data = length > 0 ? stream.getBytes(length) : new Uint8Array(0);
23487 lenIV = program.properties.privateData.lenIV;
23488 const encoded = this.readCharStrings(data, lenIV);
23489 this.nextChar();
23490 token = this.getToken();
23491 if (token === "noaccess") {
23492 this.getToken();
23493 }
23494 subrs[index] = encoded;
23495 }
23496 break;
23497 case "BlueValues":
23498 case "OtherBlues":
23499 case "FamilyBlues":
23500 case "FamilyOtherBlues":
23501 const blueArray = this.readNumberArray();
23502 if (blueArray.length > 0 && blueArray.length % 2 === 0 && HINTING_ENABLED) {
23503 program.properties.privateData[token] = blueArray;
23504 }
23505 break;
23506 case "StemSnapH":
23507 case "StemSnapV":
23508 program.properties.privateData[token] = this.readNumberArray();
23509 break;
23510 case "StdHW":
23511 case "StdVW":
23512 program.properties.privateData[token] = this.readNumberArray()[0];
23513 break;
23514 case "BlueShift":
23515 case "lenIV":
23516 case "BlueFuzz":
23517 case "BlueScale":
23518 case "LanguageGroup":
23519 program.properties.privateData[token] = this.readNumber();
23520 break;
23521 case "ExpansionFactor":
23522 program.properties.privateData[token] = this.readNumber() || 0.06;
23523 break;
23524 case "ForceBold":
23525 program.properties.privateData[token] = this.readBoolean();
23526 break;
23527 }
23528 }
23529 for (const {
23530 encoded,
23531 glyph
23532 } of charstrings) {
23533 const charString = new Type1CharString();
23534 const error = charString.convert(encoded, subrs, this.seacAnalysisEnabled);
23535 let output = charString.output;
23536 if (error) {
23537 output = [14];
23538 }
23539 const charStringObject = {
23540 glyphName: glyph,
23541 charstring: output,
23542 width: charString.width,
23543 lsb: charString.lsb,
23544 seac: charString.seac
23545 };
23546 if (glyph === ".notdef") {
23547 program.charstrings.unshift(charStringObject);
23548 } else {
23549 program.charstrings.push(charStringObject);
23550 }
23551 if (properties.builtInEncoding) {
23552 const index = properties.builtInEncoding.indexOf(glyph);
23553 if (index > -1 && properties.widths[index] === undefined && index >= properties.firstChar && index <= properties.lastChar) {
23554 properties.widths[index] = charString.width;
23555 }
23556 }
23557 }
23558 return program;
23559 }
23560 extractFontHeader(properties) {
23561 let token;
23562 while ((token = this.getToken()) !== null) {
23563 if (token !== "/") {
23564 continue;
23565 }
23566 token = this.getToken();
23567 switch (token) {
23568 case "FontMatrix":
23569 const matrix = this.readNumberArray();
23570 properties.fontMatrix = matrix;
23571 break;
23572 case "Encoding":
23573 const encodingArg = this.getToken();
23574 let encoding;
23575 if (!/^\d+$/.test(encodingArg)) {
23576 encoding = getEncoding(encodingArg);
23577 } else {
23578 encoding = [];
23579 const size = parseInt(encodingArg, 10) | 0;
23580 this.getToken();
23581 for (let j = 0; j < size; j++) {
23582 token = this.getToken();
23583 while (token !== "dup" && token !== "def") {
23584 token = this.getToken();
23585 if (token === null) {
23586 return;
23587 }
23588 }
23589 if (token === "def") {
23590 break;
23591 }
23592 const index = this.readInt();
23593 this.getToken();
23594 const glyph = this.getToken();
23595 encoding[index] = glyph;
23596 this.getToken();
23597 }
23598 }
23599 properties.builtInEncoding = encoding;
23600 break;
23601 case "FontBBox":
23602 const fontBBox = this.readNumberArray();
23603 properties.ascent = Math.max(fontBBox[3], fontBBox[1]);
23604 properties.descent = Math.min(fontBBox[1], fontBBox[3]);
23605 properties.ascentScaled = true;
23606 break;
23607 }
23608 }
23609 }
23610}
23611
23612;// CONCATENATED MODULE: ./src/core/type1_font.js
23613
23614
23615
23616
23617
23618
23619function findBlock(streamBytes, signature, startIndex) {
23620 const streamBytesLength = streamBytes.length;
23621 const signatureLength = signature.length;
23622 const scanLength = streamBytesLength - signatureLength;
23623 let i = startIndex,
23624 found = false;
23625 while (i < scanLength) {
23626 let j = 0;
23627 while (j < signatureLength && streamBytes[i + j] === signature[j]) {
23628 j++;
23629 }
23630 if (j >= signatureLength) {
23631 i += j;
23632 while (i < streamBytesLength && isWhiteSpace(streamBytes[i])) {
23633 i++;
23634 }
23635 found = true;
23636 break;
23637 }
23638 i++;
23639 }
23640 return {
23641 found,
23642 length: i
23643 };
23644}
23645function getHeaderBlock(stream, suggestedLength) {
23646 const EEXEC_SIGNATURE = [0x65, 0x65, 0x78, 0x65, 0x63];
23647 const streamStartPos = stream.pos;
23648 let headerBytes, headerBytesLength, block;
23649 try {
23650 headerBytes = stream.getBytes(suggestedLength);
23651 headerBytesLength = headerBytes.length;
23652 } catch {}
23653 if (headerBytesLength === suggestedLength) {
23654 block = findBlock(headerBytes, EEXEC_SIGNATURE, suggestedLength - 2 * EEXEC_SIGNATURE.length);
23655 if (block.found && block.length === suggestedLength) {
23656 return {
23657 stream: new Stream(headerBytes),
23658 length: suggestedLength
23659 };
23660 }
23661 }
23662 warn('Invalid "Length1" property in Type1 font -- trying to recover.');
23663 stream.pos = streamStartPos;
23664 const SCAN_BLOCK_LENGTH = 2048;
23665 let actualLength;
23666 while (true) {
23667 const scanBytes = stream.peekBytes(SCAN_BLOCK_LENGTH);
23668 block = findBlock(scanBytes, EEXEC_SIGNATURE, 0);
23669 if (block.length === 0) {
23670 break;
23671 }
23672 stream.pos += block.length;
23673 if (block.found) {
23674 actualLength = stream.pos - streamStartPos;
23675 break;
23676 }
23677 }
23678 stream.pos = streamStartPos;
23679 if (actualLength) {
23680 return {
23681 stream: new Stream(stream.getBytes(actualLength)),
23682 length: actualLength
23683 };
23684 }
23685 warn('Unable to recover "Length1" property in Type1 font -- using as is.');
23686 return {
23687 stream: new Stream(stream.getBytes(suggestedLength)),
23688 length: suggestedLength
23689 };
23690}
23691function getEexecBlock(stream, suggestedLength) {
23692 const eexecBytes = stream.getBytes();
23693 if (eexecBytes.length === 0) {
23694 throw new FormatError("getEexecBlock - no font program found.");
23695 }
23696 return {
23697 stream: new Stream(eexecBytes),
23698 length: eexecBytes.length
23699 };
23700}
23701class Type1Font {
23702 constructor(name, file, properties) {
23703 const PFB_HEADER_SIZE = 6;
23704 let headerBlockLength = properties.length1;
23705 let eexecBlockLength = properties.length2;
23706 let pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
23707 const pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
23708 if (pfbHeaderPresent) {
23709 file.skip(PFB_HEADER_SIZE);
23710 headerBlockLength = pfbHeader[5] << 24 | pfbHeader[4] << 16 | pfbHeader[3] << 8 | pfbHeader[2];
23711 }
23712 const headerBlock = getHeaderBlock(file, headerBlockLength);
23713 const headerBlockParser = new Type1Parser(headerBlock.stream, false, SEAC_ANALYSIS_ENABLED);
23714 headerBlockParser.extractFontHeader(properties);
23715 if (pfbHeaderPresent) {
23716 pfbHeader = file.getBytes(PFB_HEADER_SIZE);
23717 eexecBlockLength = pfbHeader[5] << 24 | pfbHeader[4] << 16 | pfbHeader[3] << 8 | pfbHeader[2];
23718 }
23719 const eexecBlock = getEexecBlock(file, eexecBlockLength);
23720 const eexecBlockParser = new Type1Parser(eexecBlock.stream, true, SEAC_ANALYSIS_ENABLED);
23721 const data = eexecBlockParser.extractFontProgram(properties);
23722 for (const key in data.properties) {
23723 properties[key] = data.properties[key];
23724 }
23725 const charstrings = data.charstrings;
23726 const type2Charstrings = this.getType2Charstrings(charstrings);
23727 const subrs = this.getType2Subrs(data.subrs);
23728 this.charstrings = charstrings;
23729 this.data = this.wrap(name, type2Charstrings, this.charstrings, subrs, properties);
23730 this.seacs = this.getSeacs(data.charstrings);
23731 }
23732 get numGlyphs() {
23733 return this.charstrings.length + 1;
23734 }
23735 getCharset() {
23736 const charset = [".notdef"];
23737 for (const {
23738 glyphName
23739 } of this.charstrings) {
23740 charset.push(glyphName);
23741 }
23742 return charset;
23743 }
23744 getGlyphMapping(properties) {
23745 const charstrings = this.charstrings;
23746 if (properties.composite) {
23747 const charCodeToGlyphId = Object.create(null);
23748 for (let glyphId = 0, charstringsLen = charstrings.length; glyphId < charstringsLen; glyphId++) {
23749 const charCode = properties.cMap.charCodeOf(glyphId);
23750 charCodeToGlyphId[charCode] = glyphId + 1;
23751 }
23752 return charCodeToGlyphId;
23753 }
23754 const glyphNames = [".notdef"];
23755 let builtInEncoding, glyphId;
23756 for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
23757 glyphNames.push(charstrings[glyphId].glyphName);
23758 }
23759 const encoding = properties.builtInEncoding;
23760 if (encoding) {
23761 builtInEncoding = Object.create(null);
23762 for (const charCode in encoding) {
23763 glyphId = glyphNames.indexOf(encoding[charCode]);
23764 if (glyphId >= 0) {
23765 builtInEncoding[charCode] = glyphId;
23766 }
23767 }
23768 }
23769 return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
23770 }
23771 hasGlyphId(id) {
23772 if (id < 0 || id >= this.numGlyphs) {
23773 return false;
23774 }
23775 if (id === 0) {
23776 return true;
23777 }
23778 const glyph = this.charstrings[id - 1];
23779 return glyph.charstring.length > 0;
23780 }
23781 getSeacs(charstrings) {
23782 const seacMap = [];
23783 for (let i = 0, ii = charstrings.length; i < ii; i++) {
23784 const charstring = charstrings[i];
23785 if (charstring.seac) {
23786 seacMap[i + 1] = charstring.seac;
23787 }
23788 }
23789 return seacMap;
23790 }
23791 getType2Charstrings(type1Charstrings) {
23792 const type2Charstrings = [];
23793 for (const type1Charstring of type1Charstrings) {
23794 type2Charstrings.push(type1Charstring.charstring);
23795 }
23796 return type2Charstrings;
23797 }
23798 getType2Subrs(type1Subrs) {
23799 let bias = 0;
23800 const count = type1Subrs.length;
23801 if (count < 1133) {
23802 bias = 107;
23803 } else if (count < 33769) {
23804 bias = 1131;
23805 } else {
23806 bias = 32768;
23807 }
23808 const type2Subrs = [];
23809 let i;
23810 for (i = 0; i < bias; i++) {
23811 type2Subrs.push([0x0b]);
23812 }
23813 for (i = 0; i < count; i++) {
23814 type2Subrs.push(type1Subrs[i]);
23815 }
23816 return type2Subrs;
23817 }
23818 wrap(name, glyphs, charstrings, subrs, properties) {
23819 const cff = new CFF();
23820 cff.header = new CFFHeader(1, 0, 4, 4);
23821 cff.names = [name];
23822 const topDict = new CFFTopDict();
23823 topDict.setByName("version", 391);
23824 topDict.setByName("Notice", 392);
23825 topDict.setByName("FullName", 393);
23826 topDict.setByName("FamilyName", 394);
23827 topDict.setByName("Weight", 395);
23828 topDict.setByName("Encoding", null);
23829 topDict.setByName("FontMatrix", properties.fontMatrix);
23830 topDict.setByName("FontBBox", properties.bbox);
23831 topDict.setByName("charset", null);
23832 topDict.setByName("CharStrings", null);
23833 topDict.setByName("Private", null);
23834 cff.topDict = topDict;
23835 const strings = new CFFStrings();
23836 strings.add("Version 0.11");
23837 strings.add("See original notice");
23838 strings.add(name);
23839 strings.add(name);
23840 strings.add("Medium");
23841 cff.strings = strings;
23842 cff.globalSubrIndex = new CFFIndex();
23843 const count = glyphs.length;
23844 const charsetArray = [".notdef"];
23845 let i, ii;
23846 for (i = 0; i < count; i++) {
23847 const glyphName = charstrings[i].glyphName;
23848 const index = CFFStandardStrings.indexOf(glyphName);
23849 if (index === -1) {
23850 strings.add(glyphName);
23851 }
23852 charsetArray.push(glyphName);
23853 }
23854 cff.charset = new CFFCharset(false, 0, charsetArray);
23855 const charStringsIndex = new CFFIndex();
23856 charStringsIndex.add([0x8b, 0x0e]);
23857 for (i = 0; i < count; i++) {
23858 charStringsIndex.add(glyphs[i]);
23859 }
23860 cff.charStrings = charStringsIndex;
23861 const privateDict = new CFFPrivateDict();
23862 privateDict.setByName("Subrs", null);
23863 const fields = ["BlueValues", "OtherBlues", "FamilyBlues", "FamilyOtherBlues", "StemSnapH", "StemSnapV", "BlueShift", "BlueFuzz", "BlueScale", "LanguageGroup", "ExpansionFactor", "ForceBold", "StdHW", "StdVW"];
23864 for (i = 0, ii = fields.length; i < ii; i++) {
23865 const field = fields[i];
23866 if (!(field in properties.privateData)) {
23867 continue;
23868 }
23869 const value = properties.privateData[field];
23870 if (Array.isArray(value)) {
23871 for (let j = value.length - 1; j > 0; j--) {
23872 value[j] -= value[j - 1];
23873 }
23874 }
23875 privateDict.setByName(field, value);
23876 }
23877 cff.topDict.privateDict = privateDict;
23878 const subrIndex = new CFFIndex();
23879 for (i = 0, ii = subrs.length; i < ii; i++) {
23880 subrIndex.add(subrs[i]);
23881 }
23882 privateDict.subrsIndex = subrIndex;
23883 const compiler = new CFFCompiler(cff);
23884 return compiler.compile();
23885 }
23886}
23887
23888;// CONCATENATED MODULE: ./src/core/fonts.js
23889
23890
23891
23892
23893
23894
23895
23896
23897
23898
23899
23900
23901
23902
23903
23904
23905
23906const PRIVATE_USE_AREAS = [[0xe000, 0xf8ff], [0x100000, 0x10fffd]];
23907const PDF_GLYPH_SPACE_UNITS = 1000;
23908const EXPORT_DATA_PROPERTIES = ["ascent", "bbox", "black", "bold", "charProcOperatorList", "composite", "cssFontInfo", "data", "defaultVMetrics", "defaultWidth", "descent", "fallbackName", "fontMatrix", "isInvalidPDFjsFont", "isType3Font", "italic", "loadedName", "mimetype", "missingFile", "name", "remeasure", "subtype", "systemFontInfo", "type", "vertical"];
23909const EXPORT_DATA_EXTRA_PROPERTIES = ["cMap", "defaultEncoding", "differences", "isMonospace", "isSerifFont", "isSymbolicFont", "seacMap", "toFontChar", "toUnicode", "vmetrics", "widths"];
23910function adjustWidths(properties) {
23911 if (!properties.fontMatrix) {
23912 return;
23913 }
23914 if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
23915 return;
23916 }
23917 const scale = 0.001 / properties.fontMatrix[0];
23918 const glyphsWidths = properties.widths;
23919 for (const glyph in glyphsWidths) {
23920 glyphsWidths[glyph] *= scale;
23921 }
23922 properties.defaultWidth *= scale;
23923}
23924function adjustTrueTypeToUnicode(properties, isSymbolicFont, nameRecords) {
23925 if (properties.isInternalFont) {
23926 return;
23927 }
23928 if (properties.hasIncludedToUnicodeMap) {
23929 return;
23930 }
23931 if (properties.hasEncoding) {
23932 return;
23933 }
23934 if (properties.toUnicode instanceof IdentityToUnicodeMap) {
23935 return;
23936 }
23937 if (!isSymbolicFont) {
23938 return;
23939 }
23940 if (nameRecords.length === 0) {
23941 return;
23942 }
23943 if (properties.defaultEncoding === WinAnsiEncoding) {
23944 return;
23945 }
23946 for (const r of nameRecords) {
23947 if (!isWinNameRecord(r)) {
23948 return;
23949 }
23950 }
23951 const encoding = WinAnsiEncoding;
23952 const toUnicode = [],
23953 glyphsUnicodeMap = getGlyphsUnicode();
23954 for (const charCode in encoding) {
23955 const glyphName = encoding[charCode];
23956 if (glyphName === "") {
23957 continue;
23958 }
23959 const unicode = glyphsUnicodeMap[glyphName];
23960 if (unicode === undefined) {
23961 continue;
23962 }
23963 toUnicode[charCode] = String.fromCharCode(unicode);
23964 }
23965 if (toUnicode.length > 0) {
23966 properties.toUnicode.amend(toUnicode);
23967 }
23968}
23969function adjustType1ToUnicode(properties, builtInEncoding) {
23970 if (properties.isInternalFont) {
23971 return;
23972 }
23973 if (properties.hasIncludedToUnicodeMap) {
23974 return;
23975 }
23976 if (builtInEncoding === properties.defaultEncoding) {
23977 return;
23978 }
23979 if (properties.toUnicode instanceof IdentityToUnicodeMap) {
23980 return;
23981 }
23982 const toUnicode = [],
23983 glyphsUnicodeMap = getGlyphsUnicode();
23984 for (const charCode in builtInEncoding) {
23985 if (properties.hasEncoding) {
23986 if (properties.baseEncodingName || properties.differences[charCode] !== undefined) {
23987 continue;
23988 }
23989 }
23990 const glyphName = builtInEncoding[charCode];
23991 const unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
23992 if (unicode !== -1) {
23993 toUnicode[charCode] = String.fromCharCode(unicode);
23994 }
23995 }
23996 if (toUnicode.length > 0) {
23997 properties.toUnicode.amend(toUnicode);
23998 }
23999}
24000function amendFallbackToUnicode(properties) {
24001 if (!properties.fallbackToUnicode) {
24002 return;
24003 }
24004 if (properties.toUnicode instanceof IdentityToUnicodeMap) {
24005 return;
24006 }
24007 const toUnicode = [];
24008 for (const charCode in properties.fallbackToUnicode) {
24009 if (properties.toUnicode.has(charCode)) {
24010 continue;
24011 }
24012 toUnicode[charCode] = properties.fallbackToUnicode[charCode];
24013 }
24014 if (toUnicode.length > 0) {
24015 properties.toUnicode.amend(toUnicode);
24016 }
24017}
24018class fonts_Glyph {
24019 constructor(originalCharCode, fontChar, unicode, accent, width, vmetric, operatorListId, isSpace, isInFont) {
24020 this.originalCharCode = originalCharCode;
24021 this.fontChar = fontChar;
24022 this.unicode = unicode;
24023 this.accent = accent;
24024 this.width = width;
24025 this.vmetric = vmetric;
24026 this.operatorListId = operatorListId;
24027 this.isSpace = isSpace;
24028 this.isInFont = isInFont;
24029 }
24030 get category() {
24031 return shadow(this, "category", getCharUnicodeCategory(this.unicode), true);
24032 }
24033}
24034function int16(b0, b1) {
24035 return (b0 << 8) + b1;
24036}
24037function writeSignedInt16(bytes, index, value) {
24038 bytes[index + 1] = value;
24039 bytes[index] = value >>> 8;
24040}
24041function signedInt16(b0, b1) {
24042 const value = (b0 << 8) + b1;
24043 return value & 1 << 15 ? value - 0x10000 : value;
24044}
24045function writeUint32(bytes, index, value) {
24046 bytes[index + 3] = value & 0xff;
24047 bytes[index + 2] = value >>> 8;
24048 bytes[index + 1] = value >>> 16;
24049 bytes[index] = value >>> 24;
24050}
24051function int32(b0, b1, b2, b3) {
24052 return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
24053}
24054function string16(value) {
24055 return String.fromCharCode(value >> 8 & 0xff, value & 0xff);
24056}
24057function safeString16(value) {
24058 if (value > 0x7fff) {
24059 value = 0x7fff;
24060 } else if (value < -0x8000) {
24061 value = -0x8000;
24062 }
24063 return String.fromCharCode(value >> 8 & 0xff, value & 0xff);
24064}
24065function isTrueTypeFile(file) {
24066 const header = file.peekBytes(4);
24067 return readUint32(header, 0) === 0x00010000 || bytesToString(header) === "true";
24068}
24069function isTrueTypeCollectionFile(file) {
24070 const header = file.peekBytes(4);
24071 return bytesToString(header) === "ttcf";
24072}
24073function isOpenTypeFile(file) {
24074 const header = file.peekBytes(4);
24075 return bytesToString(header) === "OTTO";
24076}
24077function isType1File(file) {
24078 const header = file.peekBytes(2);
24079 if (header[0] === 0x25 && header[1] === 0x21) {
24080 return true;
24081 }
24082 if (header[0] === 0x80 && header[1] === 0x01) {
24083 return true;
24084 }
24085 return false;
24086}
24087function isCFFFile(file) {
24088 const header = file.peekBytes(4);
24089 if (header[0] >= 1 && header[3] >= 1 && header[3] <= 4) {
24090 return true;
24091 }
24092 return false;
24093}
24094function getFontFileType(file, {
24095 type,
24096 subtype,
24097 composite
24098}) {
24099 let fileType, fileSubtype;
24100 if (isTrueTypeFile(file) || isTrueTypeCollectionFile(file)) {
24101 fileType = composite ? "CIDFontType2" : "TrueType";
24102 } else if (isOpenTypeFile(file)) {
24103 fileType = composite ? "CIDFontType2" : "OpenType";
24104 } else if (isType1File(file)) {
24105 if (composite) {
24106 fileType = "CIDFontType0";
24107 } else {
24108 fileType = type === "MMType1" ? "MMType1" : "Type1";
24109 }
24110 } else if (isCFFFile(file)) {
24111 if (composite) {
24112 fileType = "CIDFontType0";
24113 fileSubtype = "CIDFontType0C";
24114 } else {
24115 fileType = type === "MMType1" ? "MMType1" : "Type1";
24116 fileSubtype = "Type1C";
24117 }
24118 } else {
24119 warn("getFontFileType: Unable to detect correct font file Type/Subtype.");
24120 fileType = type;
24121 fileSubtype = subtype;
24122 }
24123 return [fileType, fileSubtype];
24124}
24125function applyStandardFontGlyphMap(map, glyphMap) {
24126 for (const charCode in glyphMap) {
24127 map[+charCode] = glyphMap[charCode];
24128 }
24129}
24130function buildToFontChar(encoding, glyphsUnicodeMap, differences) {
24131 const toFontChar = [];
24132 let unicode;
24133 for (let i = 0, ii = encoding.length; i < ii; i++) {
24134 unicode = getUnicodeForGlyph(encoding[i], glyphsUnicodeMap);
24135 if (unicode !== -1) {
24136 toFontChar[i] = unicode;
24137 }
24138 }
24139 for (const charCode in differences) {
24140 unicode = getUnicodeForGlyph(differences[charCode], glyphsUnicodeMap);
24141 if (unicode !== -1) {
24142 toFontChar[+charCode] = unicode;
24143 }
24144 }
24145 return toFontChar;
24146}
24147function isMacNameRecord(r) {
24148 return r.platform === 1 && r.encoding === 0 && r.language === 0;
24149}
24150function isWinNameRecord(r) {
24151 return r.platform === 3 && r.encoding === 1 && r.language === 0x409;
24152}
24153function convertCidString(charCode, cid, shouldThrow = false) {
24154 switch (cid.length) {
24155 case 1:
24156 return cid.charCodeAt(0);
24157 case 2:
24158 return cid.charCodeAt(0) << 8 | cid.charCodeAt(1);
24159 }
24160 const msg = `Unsupported CID string (charCode ${charCode}): "${cid}".`;
24161 if (shouldThrow) {
24162 throw new FormatError(msg);
24163 }
24164 warn(msg);
24165 return cid;
24166}
24167function adjustMapping(charCodeToGlyphId, hasGlyph, newGlyphZeroId, toUnicode) {
24168 const newMap = Object.create(null);
24169 const toUnicodeExtraMap = new Map();
24170 const toFontChar = [];
24171 const usedGlyphIds = new Set();
24172 let privateUseAreaIndex = 0;
24173 const privateUseOffetStart = PRIVATE_USE_AREAS[privateUseAreaIndex][0];
24174 let nextAvailableFontCharCode = privateUseOffetStart;
24175 let privateUseOffetEnd = PRIVATE_USE_AREAS[privateUseAreaIndex][1];
24176 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];
24177 for (let originalCharCode in charCodeToGlyphId) {
24178 originalCharCode |= 0;
24179 let glyphId = charCodeToGlyphId[originalCharCode];
24180 if (!hasGlyph(glyphId)) {
24181 continue;
24182 }
24183 if (nextAvailableFontCharCode > privateUseOffetEnd) {
24184 privateUseAreaIndex++;
24185 if (privateUseAreaIndex >= PRIVATE_USE_AREAS.length) {
24186 warn("Ran out of space in font private use area.");
24187 break;
24188 }
24189 nextAvailableFontCharCode = PRIVATE_USE_AREAS[privateUseAreaIndex][0];
24190 privateUseOffetEnd = PRIVATE_USE_AREAS[privateUseAreaIndex][1];
24191 }
24192 const fontCharCode = nextAvailableFontCharCode++;
24193 if (glyphId === 0) {
24194 glyphId = newGlyphZeroId;
24195 }
24196 let unicode = toUnicode.get(originalCharCode);
24197 if (typeof unicode === "string") {
24198 unicode = unicode.codePointAt(0);
24199 }
24200 if (unicode && !isInPrivateArea(unicode) && !usedGlyphIds.has(glyphId)) {
24201 toUnicodeExtraMap.set(unicode, glyphId);
24202 usedGlyphIds.add(glyphId);
24203 }
24204 newMap[fontCharCode] = glyphId;
24205 toFontChar[originalCharCode] = fontCharCode;
24206 }
24207 return {
24208 toFontChar,
24209 charCodeToGlyphId: newMap,
24210 toUnicodeExtraMap,
24211 nextAvailableFontCharCode
24212 };
24213}
24214function getRanges(glyphs, toUnicodeExtraMap, numGlyphs) {
24215 const codes = [];
24216 for (const charCode in glyphs) {
24217 if (glyphs[charCode] >= numGlyphs) {
24218 continue;
24219 }
24220 codes.push({
24221 fontCharCode: charCode | 0,
24222 glyphId: glyphs[charCode]
24223 });
24224 }
24225 if (toUnicodeExtraMap) {
24226 for (const [unicode, glyphId] of toUnicodeExtraMap) {
24227 if (glyphId >= numGlyphs) {
24228 continue;
24229 }
24230 codes.push({
24231 fontCharCode: unicode,
24232 glyphId
24233 });
24234 }
24235 }
24236 if (codes.length === 0) {
24237 codes.push({
24238 fontCharCode: 0,
24239 glyphId: 0
24240 });
24241 }
24242 codes.sort(function fontGetRangesSort(a, b) {
24243 return a.fontCharCode - b.fontCharCode;
24244 });
24245 const ranges = [];
24246 const length = codes.length;
24247 for (let n = 0; n < length;) {
24248 const start = codes[n].fontCharCode;
24249 const codeIndices = [codes[n].glyphId];
24250 ++n;
24251 let end = start;
24252 while (n < length && end + 1 === codes[n].fontCharCode) {
24253 codeIndices.push(codes[n].glyphId);
24254 ++end;
24255 ++n;
24256 if (end === 0xffff) {
24257 break;
24258 }
24259 }
24260 ranges.push([start, end, codeIndices]);
24261 }
24262 return ranges;
24263}
24264function createCmapTable(glyphs, toUnicodeExtraMap, numGlyphs) {
24265 const ranges = getRanges(glyphs, toUnicodeExtraMap, numGlyphs);
24266 const numTables = ranges.at(-1)[1] > 0xffff ? 2 : 1;
24267 let cmap = "\x00\x00" + string16(numTables) + "\x00\x03" + "\x00\x01" + string32(4 + numTables * 8);
24268 let i, ii, j, jj;
24269 for (i = ranges.length - 1; i >= 0; --i) {
24270 if (ranges[i][0] <= 0xffff) {
24271 break;
24272 }
24273 }
24274 const bmpLength = i + 1;
24275 if (ranges[i][0] < 0xffff && ranges[i][1] === 0xffff) {
24276 ranges[i][1] = 0xfffe;
24277 }
24278 const trailingRangesCount = ranges[i][1] < 0xffff ? 1 : 0;
24279 const segCount = bmpLength + trailingRangesCount;
24280 const searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
24281 let startCount = "";
24282 let endCount = "";
24283 let idDeltas = "";
24284 let idRangeOffsets = "";
24285 let glyphsIds = "";
24286 let bias = 0;
24287 let range, start, end, codes;
24288 for (i = 0, ii = bmpLength; i < ii; i++) {
24289 range = ranges[i];
24290 start = range[0];
24291 end = range[1];
24292 startCount += string16(start);
24293 endCount += string16(end);
24294 codes = range[2];
24295 let contiguous = true;
24296 for (j = 1, jj = codes.length; j < jj; ++j) {
24297 if (codes[j] !== codes[j - 1] + 1) {
24298 contiguous = false;
24299 break;
24300 }
24301 }
24302 if (!contiguous) {
24303 const offset = (segCount - i) * 2 + bias * 2;
24304 bias += end - start + 1;
24305 idDeltas += string16(0);
24306 idRangeOffsets += string16(offset);
24307 for (j = 0, jj = codes.length; j < jj; ++j) {
24308 glyphsIds += string16(codes[j]);
24309 }
24310 } else {
24311 const startCode = codes[0];
24312 idDeltas += string16(startCode - start & 0xffff);
24313 idRangeOffsets += string16(0);
24314 }
24315 }
24316 if (trailingRangesCount > 0) {
24317 endCount += "\xFF\xFF";
24318 startCount += "\xFF\xFF";
24319 idDeltas += "\x00\x01";
24320 idRangeOffsets += "\x00\x00";
24321 }
24322 const format314 = "\x00\x00" + string16(2 * segCount) + string16(searchParams.range) + string16(searchParams.entry) + string16(searchParams.rangeShift) + endCount + "\x00\x00" + startCount + idDeltas + idRangeOffsets + glyphsIds;
24323 let format31012 = "";
24324 let header31012 = "";
24325 if (numTables > 1) {
24326 cmap += "\x00\x03" + "\x00\x0A" + string32(4 + numTables * 8 + 4 + format314.length);
24327 format31012 = "";
24328 for (i = 0, ii = ranges.length; i < ii; i++) {
24329 range = ranges[i];
24330 start = range[0];
24331 codes = range[2];
24332 let code = codes[0];
24333 for (j = 1, jj = codes.length; j < jj; ++j) {
24334 if (codes[j] !== codes[j - 1] + 1) {
24335 end = range[0] + j - 1;
24336 format31012 += string32(start) + string32(end) + string32(code);
24337 start = end + 1;
24338 code = codes[j];
24339 }
24340 }
24341 format31012 += string32(start) + string32(range[1]) + string32(code);
24342 }
24343 header31012 = "\x00\x0C" + "\x00\x00" + string32(format31012.length + 16) + "\x00\x00\x00\x00" + string32(format31012.length / 12);
24344 }
24345 return cmap + "\x00\x04" + string16(format314.length + 4) + format314 + header31012 + format31012;
24346}
24347function validateOS2Table(os2, file) {
24348 file.pos = (file.start || 0) + os2.offset;
24349 const version = file.getUint16();
24350 file.skip(60);
24351 const selection = file.getUint16();
24352 if (version < 4 && selection & 0x0300) {
24353 return false;
24354 }
24355 const firstChar = file.getUint16();
24356 const lastChar = file.getUint16();
24357 if (firstChar > lastChar) {
24358 return false;
24359 }
24360 file.skip(6);
24361 const usWinAscent = file.getUint16();
24362 if (usWinAscent === 0) {
24363 return false;
24364 }
24365 os2.data[8] = os2.data[9] = 0;
24366 return true;
24367}
24368function createOS2Table(properties, charstrings, override) {
24369 override ||= {
24370 unitsPerEm: 0,
24371 yMax: 0,
24372 yMin: 0,
24373 ascent: 0,
24374 descent: 0
24375 };
24376 let ulUnicodeRange1 = 0;
24377 let ulUnicodeRange2 = 0;
24378 let ulUnicodeRange3 = 0;
24379 let ulUnicodeRange4 = 0;
24380 let firstCharIndex = null;
24381 let lastCharIndex = 0;
24382 let position = -1;
24383 if (charstrings) {
24384 for (let code in charstrings) {
24385 code |= 0;
24386 if (firstCharIndex > code || !firstCharIndex) {
24387 firstCharIndex = code;
24388 }
24389 if (lastCharIndex < code) {
24390 lastCharIndex = code;
24391 }
24392 position = getUnicodeRangeFor(code, position);
24393 if (position < 32) {
24394 ulUnicodeRange1 |= 1 << position;
24395 } else if (position < 64) {
24396 ulUnicodeRange2 |= 1 << position - 32;
24397 } else if (position < 96) {
24398 ulUnicodeRange3 |= 1 << position - 64;
24399 } else if (position < 123) {
24400 ulUnicodeRange4 |= 1 << position - 96;
24401 } else {
24402 throw new FormatError("Unicode ranges Bits > 123 are reserved for internal usage");
24403 }
24404 }
24405 if (lastCharIndex > 0xffff) {
24406 lastCharIndex = 0xffff;
24407 }
24408 } else {
24409 firstCharIndex = 0;
24410 lastCharIndex = 255;
24411 }
24412 const bbox = properties.bbox || [0, 0, 0, 0];
24413 const unitsPerEm = override.unitsPerEm || 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
24414 const scale = properties.ascentScaled ? 1.0 : unitsPerEm / PDF_GLYPH_SPACE_UNITS;
24415 const typoAscent = override.ascent || Math.round(scale * (properties.ascent || bbox[3]));
24416 let typoDescent = override.descent || Math.round(scale * (properties.descent || bbox[1]));
24417 if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
24418 typoDescent = -typoDescent;
24419 }
24420 const winAscent = override.yMax || typoAscent;
24421 const winDescent = -override.yMin || -typoDescent;
24422 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";
24423}
24424function createPostTable(properties) {
24425 const angle = Math.floor(properties.italicAngle * 2 ** 16);
24426 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";
24427}
24428function createPostscriptName(name) {
24429 return name.replaceAll(/[^\x21-\x7E]|[[\](){}<>/%]/g, "").slice(0, 63);
24430}
24431function createNameTable(name, proto) {
24432 if (!proto) {
24433 proto = [[], []];
24434 }
24435 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"];
24436 const stringsUnicode = [];
24437 let i, ii, j, jj, str;
24438 for (i = 0, ii = strings.length; i < ii; i++) {
24439 str = proto[1][i] || strings[i];
24440 const strBufUnicode = [];
24441 for (j = 0, jj = str.length; j < jj; j++) {
24442 strBufUnicode.push(string16(str.charCodeAt(j)));
24443 }
24444 stringsUnicode.push(strBufUnicode.join(""));
24445 }
24446 const names = [strings, stringsUnicode];
24447 const platforms = ["\x00\x01", "\x00\x03"];
24448 const encodings = ["\x00\x00", "\x00\x01"];
24449 const languages = ["\x00\x00", "\x04\x09"];
24450 const namesRecordCount = strings.length * platforms.length;
24451 let nameTable = "\x00\x00" + string16(namesRecordCount) + string16(namesRecordCount * 12 + 6);
24452 let strOffset = 0;
24453 for (i = 0, ii = platforms.length; i < ii; i++) {
24454 const strs = names[i];
24455 for (j = 0, jj = strs.length; j < jj; j++) {
24456 str = strs[j];
24457 const nameRecord = platforms[i] + encodings[i] + languages[i] + string16(j) + string16(str.length) + string16(strOffset);
24458 nameTable += nameRecord;
24459 strOffset += str.length;
24460 }
24461 }
24462 nameTable += strings.join("") + stringsUnicode.join("");
24463 return nameTable;
24464}
24465class Font {
24466 constructor(name, file, properties) {
24467 this.name = name;
24468 this.psName = null;
24469 this.mimetype = null;
24470 this.disableFontFace = false;
24471 this.loadedName = properties.loadedName;
24472 this.isType3Font = properties.isType3Font;
24473 this.missingFile = false;
24474 this.cssFontInfo = properties.cssFontInfo;
24475 this._charsCache = Object.create(null);
24476 this._glyphCache = Object.create(null);
24477 let isSerifFont = !!(properties.flags & FontFlags.Serif);
24478 if (!isSerifFont && !properties.isSimulatedFlags) {
24479 const baseName = name.replaceAll(/[,_]/g, "-").split("-", 1)[0],
24480 serifFonts = getSerifFonts();
24481 for (const namePart of baseName.split("+")) {
24482 if (serifFonts[namePart]) {
24483 isSerifFont = true;
24484 break;
24485 }
24486 }
24487 }
24488 this.isSerifFont = isSerifFont;
24489 this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
24490 this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
24491 let {
24492 type,
24493 subtype
24494 } = properties;
24495 this.type = type;
24496 this.subtype = subtype;
24497 this.systemFontInfo = properties.systemFontInfo;
24498 const matches = name.match(/^InvalidPDFjsFont_(.*)_\d+$/);
24499 this.isInvalidPDFjsFont = !!matches;
24500 if (this.isInvalidPDFjsFont) {
24501 this.fallbackName = matches[1];
24502 } else if (this.isMonospace) {
24503 this.fallbackName = "monospace";
24504 } else if (this.isSerifFont) {
24505 this.fallbackName = "serif";
24506 } else {
24507 this.fallbackName = "sans-serif";
24508 }
24509 if (this.systemFontInfo?.guessFallback) {
24510 this.systemFontInfo.guessFallback = false;
24511 this.systemFontInfo.css += `,${this.fallbackName}`;
24512 }
24513 this.differences = properties.differences;
24514 this.widths = properties.widths;
24515 this.defaultWidth = properties.defaultWidth;
24516 this.composite = properties.composite;
24517 this.cMap = properties.cMap;
24518 this.capHeight = properties.capHeight / PDF_GLYPH_SPACE_UNITS;
24519 this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
24520 this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
24521 this.lineHeight = this.ascent - this.descent;
24522 this.fontMatrix = properties.fontMatrix;
24523 this.bbox = properties.bbox;
24524 this.defaultEncoding = properties.defaultEncoding;
24525 this.toUnicode = properties.toUnicode;
24526 this.toFontChar = [];
24527 if (properties.type === "Type3") {
24528 for (let charCode = 0; charCode < 256; charCode++) {
24529 this.toFontChar[charCode] = this.differences[charCode] || properties.defaultEncoding[charCode];
24530 }
24531 return;
24532 }
24533 this.cidEncoding = properties.cidEncoding || "";
24534 this.vertical = !!properties.vertical;
24535 if (this.vertical) {
24536 this.vmetrics = properties.vmetrics;
24537 this.defaultVMetrics = properties.defaultVMetrics;
24538 }
24539 if (!file || file.isEmpty) {
24540 if (file) {
24541 warn('Font file is empty in "' + name + '" (' + this.loadedName + ")");
24542 }
24543 this.fallbackToSystemFont(properties);
24544 return;
24545 }
24546 [type, subtype] = getFontFileType(file, properties);
24547 if (type !== this.type || subtype !== this.subtype) {
24548 info("Inconsistent font file Type/SubType, expected: " + `${this.type}/${this.subtype} but found: ${type}/${subtype}.`);
24549 }
24550 let data;
24551 try {
24552 switch (type) {
24553 case "MMType1":
24554 info("MMType1 font (" + name + "), falling back to Type1.");
24555 case "Type1":
24556 case "CIDFontType0":
24557 this.mimetype = "font/opentype";
24558 const cff = subtype === "Type1C" || subtype === "CIDFontType0C" ? new CFFFont(file, properties) : new Type1Font(name, file, properties);
24559 adjustWidths(properties);
24560 data = this.convert(name, cff, properties);
24561 break;
24562 case "OpenType":
24563 case "TrueType":
24564 case "CIDFontType2":
24565 this.mimetype = "font/opentype";
24566 data = this.checkAndRepair(name, file, properties);
24567 if (this.isOpenType) {
24568 adjustWidths(properties);
24569 type = "OpenType";
24570 }
24571 break;
24572 default:
24573 throw new FormatError(`Font ${type} is not supported`);
24574 }
24575 } catch (e) {
24576 warn(e);
24577 this.fallbackToSystemFont(properties);
24578 return;
24579 }
24580 amendFallbackToUnicode(properties);
24581 this.data = data;
24582 this.type = type;
24583 this.subtype = subtype;
24584 this.fontMatrix = properties.fontMatrix;
24585 this.widths = properties.widths;
24586 this.defaultWidth = properties.defaultWidth;
24587 this.toUnicode = properties.toUnicode;
24588 this.seacMap = properties.seacMap;
24589 }
24590 get renderer() {
24591 const renderer = FontRendererFactory.create(this, SEAC_ANALYSIS_ENABLED);
24592 return shadow(this, "renderer", renderer);
24593 }
24594 exportData(extraProperties = false) {
24595 const exportDataProperties = extraProperties ? [...EXPORT_DATA_PROPERTIES, ...EXPORT_DATA_EXTRA_PROPERTIES] : EXPORT_DATA_PROPERTIES;
24596 const data = Object.create(null);
24597 let property, value;
24598 for (property of exportDataProperties) {
24599 value = this[property];
24600 if (value !== undefined) {
24601 data[property] = value;
24602 }
24603 }
24604 return data;
24605 }
24606 fallbackToSystemFont(properties) {
24607 this.missingFile = true;
24608 const {
24609 name,
24610 type
24611 } = this;
24612 let fontName = normalizeFontName(name);
24613 const stdFontMap = getStdFontMap(),
24614 nonStdFontMap = getNonStdFontMap();
24615 const isStandardFont = !!stdFontMap[fontName];
24616 const isMappedToStandardFont = !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
24617 fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
24618 const fontBasicMetricsMap = getFontBasicMetrics();
24619 const metrics = fontBasicMetricsMap[fontName];
24620 if (metrics) {
24621 if (isNaN(this.ascent)) {
24622 this.ascent = metrics.ascent / PDF_GLYPH_SPACE_UNITS;
24623 }
24624 if (isNaN(this.descent)) {
24625 this.descent = metrics.descent / PDF_GLYPH_SPACE_UNITS;
24626 }
24627 if (isNaN(this.capHeight)) {
24628 this.capHeight = metrics.capHeight / PDF_GLYPH_SPACE_UNITS;
24629 }
24630 }
24631 this.bold = /bold/gi.test(fontName);
24632 this.italic = /oblique|italic/gi.test(fontName);
24633 this.black = /Black/g.test(name);
24634 const isNarrow = /Narrow/g.test(name);
24635 this.remeasure = (!isStandardFont || isNarrow) && Object.keys(this.widths).length > 0;
24636 if ((isStandardFont || isMappedToStandardFont) && type === "CIDFontType2" && this.cidEncoding.startsWith("Identity-")) {
24637 const cidToGidMap = properties.cidToGidMap;
24638 const map = [];
24639 applyStandardFontGlyphMap(map, getGlyphMapForStandardFonts());
24640 if (/Arial-?Black/i.test(name)) {
24641 applyStandardFontGlyphMap(map, getSupplementalGlyphMapForArialBlack());
24642 } else if (/Calibri/i.test(name)) {
24643 applyStandardFontGlyphMap(map, getSupplementalGlyphMapForCalibri());
24644 }
24645 if (cidToGidMap) {
24646 for (const charCode in map) {
24647 const cid = map[charCode];
24648 if (cidToGidMap[cid] !== undefined) {
24649 map[+charCode] = cidToGidMap[cid];
24650 }
24651 }
24652 if (cidToGidMap.length !== this.toUnicode.length && properties.hasIncludedToUnicodeMap && this.toUnicode instanceof IdentityToUnicodeMap) {
24653 this.toUnicode.forEach(function (charCode, unicodeCharCode) {
24654 const cid = map[charCode];
24655 if (cidToGidMap[cid] === undefined) {
24656 map[+charCode] = unicodeCharCode;
24657 }
24658 });
24659 }
24660 }
24661 if (!(this.toUnicode instanceof IdentityToUnicodeMap)) {
24662 this.toUnicode.forEach(function (charCode, unicodeCharCode) {
24663 map[+charCode] = unicodeCharCode;
24664 });
24665 }
24666 this.toFontChar = map;
24667 this.toUnicode = new ToUnicodeMap(map);
24668 } else if (/Symbol/i.test(fontName)) {
24669 this.toFontChar = buildToFontChar(SymbolSetEncoding, getGlyphsUnicode(), this.differences);
24670 } else if (/Dingbats/i.test(fontName)) {
24671 this.toFontChar = buildToFontChar(ZapfDingbatsEncoding, getDingbatsGlyphsUnicode(), this.differences);
24672 } else if (isStandardFont) {
24673 const map = buildToFontChar(this.defaultEncoding, getGlyphsUnicode(), this.differences);
24674 if (type === "CIDFontType2" && !this.cidEncoding.startsWith("Identity-") && !(this.toUnicode instanceof IdentityToUnicodeMap)) {
24675 this.toUnicode.forEach(function (charCode, unicodeCharCode) {
24676 map[+charCode] = unicodeCharCode;
24677 });
24678 }
24679 this.toFontChar = map;
24680 } else {
24681 const glyphsUnicodeMap = getGlyphsUnicode();
24682 const map = [];
24683 this.toUnicode.forEach((charCode, unicodeCharCode) => {
24684 if (!this.composite) {
24685 const glyphName = this.differences[charCode] || this.defaultEncoding[charCode];
24686 const unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
24687 if (unicode !== -1) {
24688 unicodeCharCode = unicode;
24689 }
24690 }
24691 map[+charCode] = unicodeCharCode;
24692 });
24693 if (this.composite && this.toUnicode instanceof IdentityToUnicodeMap) {
24694 if (/Tahoma|Verdana/i.test(name)) {
24695 applyStandardFontGlyphMap(map, getGlyphMapForStandardFonts());
24696 }
24697 }
24698 this.toFontChar = map;
24699 }
24700 amendFallbackToUnicode(properties);
24701 this.loadedName = fontName.split("-", 1)[0];
24702 }
24703 checkAndRepair(name, font, properties) {
24704 const VALID_TABLES = ["OS/2", "cmap", "head", "hhea", "hmtx", "maxp", "name", "post", "loca", "glyf", "fpgm", "prep", "cvt ", "CFF "];
24705 function readTables(file, numTables) {
24706 const tables = Object.create(null);
24707 tables["OS/2"] = null;
24708 tables.cmap = null;
24709 tables.head = null;
24710 tables.hhea = null;
24711 tables.hmtx = null;
24712 tables.maxp = null;
24713 tables.name = null;
24714 tables.post = null;
24715 for (let i = 0; i < numTables; i++) {
24716 const table = readTableEntry(file);
24717 if (!VALID_TABLES.includes(table.tag)) {
24718 continue;
24719 }
24720 if (table.length === 0) {
24721 continue;
24722 }
24723 tables[table.tag] = table;
24724 }
24725 return tables;
24726 }
24727 function readTableEntry(file) {
24728 const tag = file.getString(4);
24729 const checksum = file.getInt32() >>> 0;
24730 const offset = file.getInt32() >>> 0;
24731 const length = file.getInt32() >>> 0;
24732 const previousPosition = file.pos;
24733 file.pos = file.start || 0;
24734 file.skip(offset);
24735 const data = file.getBytes(length);
24736 file.pos = previousPosition;
24737 if (tag === "head") {
24738 data[8] = data[9] = data[10] = data[11] = 0;
24739 data[17] |= 0x20;
24740 }
24741 return {
24742 tag,
24743 checksum,
24744 length,
24745 offset,
24746 data
24747 };
24748 }
24749 function readOpenTypeHeader(ttf) {
24750 return {
24751 version: ttf.getString(4),
24752 numTables: ttf.getUint16(),
24753 searchRange: ttf.getUint16(),
24754 entrySelector: ttf.getUint16(),
24755 rangeShift: ttf.getUint16()
24756 };
24757 }
24758 function readTrueTypeCollectionHeader(ttc) {
24759 const ttcTag = ttc.getString(4);
24760 assert(ttcTag === "ttcf", "Must be a TrueType Collection font.");
24761 const majorVersion = ttc.getUint16();
24762 const minorVersion = ttc.getUint16();
24763 const numFonts = ttc.getInt32() >>> 0;
24764 const offsetTable = [];
24765 for (let i = 0; i < numFonts; i++) {
24766 offsetTable.push(ttc.getInt32() >>> 0);
24767 }
24768 const header = {
24769 ttcTag,
24770 majorVersion,
24771 minorVersion,
24772 numFonts,
24773 offsetTable
24774 };
24775 switch (majorVersion) {
24776 case 1:
24777 return header;
24778 case 2:
24779 header.dsigTag = ttc.getInt32() >>> 0;
24780 header.dsigLength = ttc.getInt32() >>> 0;
24781 header.dsigOffset = ttc.getInt32() >>> 0;
24782 return header;
24783 }
24784 throw new FormatError(`Invalid TrueType Collection majorVersion: ${majorVersion}.`);
24785 }
24786 function readTrueTypeCollectionData(ttc, fontName) {
24787 const {
24788 numFonts,
24789 offsetTable
24790 } = readTrueTypeCollectionHeader(ttc);
24791 const fontNameParts = fontName.split("+");
24792 let fallbackData;
24793 for (let i = 0; i < numFonts; i++) {
24794 ttc.pos = (ttc.start || 0) + offsetTable[i];
24795 const potentialHeader = readOpenTypeHeader(ttc);
24796 const potentialTables = readTables(ttc, potentialHeader.numTables);
24797 if (!potentialTables.name) {
24798 throw new FormatError('TrueType Collection font must contain a "name" table.');
24799 }
24800 const [nameTable] = readNameTable(potentialTables.name);
24801 for (let j = 0, jj = nameTable.length; j < jj; j++) {
24802 for (let k = 0, kk = nameTable[j].length; k < kk; k++) {
24803 const nameEntry = nameTable[j][k]?.replaceAll(/\s/g, "");
24804 if (!nameEntry) {
24805 continue;
24806 }
24807 if (nameEntry === fontName) {
24808 return {
24809 header: potentialHeader,
24810 tables: potentialTables
24811 };
24812 }
24813 if (fontNameParts.length < 2) {
24814 continue;
24815 }
24816 for (const part of fontNameParts) {
24817 if (nameEntry === part) {
24818 fallbackData = {
24819 name: part,
24820 header: potentialHeader,
24821 tables: potentialTables
24822 };
24823 }
24824 }
24825 }
24826 }
24827 }
24828 if (fallbackData) {
24829 warn(`TrueType Collection does not contain "${fontName}" font, ` + `falling back to "${fallbackData.name}" font instead.`);
24830 return {
24831 header: fallbackData.header,
24832 tables: fallbackData.tables
24833 };
24834 }
24835 throw new FormatError(`TrueType Collection does not contain "${fontName}" font.`);
24836 }
24837 function readCmapTable(cmap, file, isSymbolicFont, hasEncoding) {
24838 if (!cmap) {
24839 warn("No cmap table available.");
24840 return {
24841 platformId: -1,
24842 encodingId: -1,
24843 mappings: [],
24844 hasShortCmap: false
24845 };
24846 }
24847 let segment;
24848 let start = (file.start || 0) + cmap.offset;
24849 file.pos = start;
24850 file.skip(2);
24851 const numTables = file.getUint16();
24852 let potentialTable;
24853 let canBreak = false;
24854 for (let i = 0; i < numTables; i++) {
24855 const platformId = file.getUint16();
24856 const encodingId = file.getUint16();
24857 const offset = file.getInt32() >>> 0;
24858 let useTable = false;
24859 if (potentialTable?.platformId === platformId && potentialTable?.encodingId === encodingId) {
24860 continue;
24861 }
24862 if (platformId === 0 && (encodingId === 0 || encodingId === 1 || encodingId === 3)) {
24863 useTable = true;
24864 } else if (platformId === 1 && encodingId === 0) {
24865 useTable = true;
24866 } else if (platformId === 3 && encodingId === 1 && (hasEncoding || !potentialTable)) {
24867 useTable = true;
24868 if (!isSymbolicFont) {
24869 canBreak = true;
24870 }
24871 } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
24872 useTable = true;
24873 let correctlySorted = true;
24874 if (i < numTables - 1) {
24875 const nextBytes = file.peekBytes(2),
24876 nextPlatformId = int16(nextBytes[0], nextBytes[1]);
24877 if (nextPlatformId < platformId) {
24878 correctlySorted = false;
24879 }
24880 }
24881 if (correctlySorted) {
24882 canBreak = true;
24883 }
24884 }
24885 if (useTable) {
24886 potentialTable = {
24887 platformId,
24888 encodingId,
24889 offset
24890 };
24891 }
24892 if (canBreak) {
24893 break;
24894 }
24895 }
24896 if (potentialTable) {
24897 file.pos = start + potentialTable.offset;
24898 }
24899 if (!potentialTable || file.peekByte() === -1) {
24900 warn("Could not find a preferred cmap table.");
24901 return {
24902 platformId: -1,
24903 encodingId: -1,
24904 mappings: [],
24905 hasShortCmap: false
24906 };
24907 }
24908 const format = file.getUint16();
24909 let hasShortCmap = false;
24910 const mappings = [];
24911 let j, glyphId;
24912 if (format === 0) {
24913 file.skip(2 + 2);
24914 for (j = 0; j < 256; j++) {
24915 const index = file.getByte();
24916 if (!index) {
24917 continue;
24918 }
24919 mappings.push({
24920 charCode: j,
24921 glyphId: index
24922 });
24923 }
24924 hasShortCmap = true;
24925 } else if (format === 2) {
24926 file.skip(2 + 2);
24927 const subHeaderKeys = [];
24928 let maxSubHeaderKey = 0;
24929 for (let i = 0; i < 256; i++) {
24930 const subHeaderKey = file.getUint16() >> 3;
24931 subHeaderKeys.push(subHeaderKey);
24932 maxSubHeaderKey = Math.max(subHeaderKey, maxSubHeaderKey);
24933 }
24934 const subHeaders = [];
24935 for (let i = 0; i <= maxSubHeaderKey; i++) {
24936 subHeaders.push({
24937 firstCode: file.getUint16(),
24938 entryCount: file.getUint16(),
24939 idDelta: signedInt16(file.getByte(), file.getByte()),
24940 idRangePos: file.pos + file.getUint16()
24941 });
24942 }
24943 for (let i = 0; i < 256; i++) {
24944 if (subHeaderKeys[i] === 0) {
24945 file.pos = subHeaders[0].idRangePos + 2 * i;
24946 glyphId = file.getUint16();
24947 mappings.push({
24948 charCode: i,
24949 glyphId
24950 });
24951 } else {
24952 const s = subHeaders[subHeaderKeys[i]];
24953 for (j = 0; j < s.entryCount; j++) {
24954 const charCode = (i << 8) + j + s.firstCode;
24955 file.pos = s.idRangePos + 2 * j;
24956 glyphId = file.getUint16();
24957 if (glyphId !== 0) {
24958 glyphId = (glyphId + s.idDelta) % 65536;
24959 }
24960 mappings.push({
24961 charCode,
24962 glyphId
24963 });
24964 }
24965 }
24966 }
24967 } else if (format === 4) {
24968 file.skip(2 + 2);
24969 const segCount = file.getUint16() >> 1;
24970 file.skip(6);
24971 const segments = [];
24972 let segIndex;
24973 for (segIndex = 0; segIndex < segCount; segIndex++) {
24974 segments.push({
24975 end: file.getUint16()
24976 });
24977 }
24978 file.skip(2);
24979 for (segIndex = 0; segIndex < segCount; segIndex++) {
24980 segments[segIndex].start = file.getUint16();
24981 }
24982 for (segIndex = 0; segIndex < segCount; segIndex++) {
24983 segments[segIndex].delta = file.getUint16();
24984 }
24985 let offsetsCount = 0,
24986 offsetIndex;
24987 for (segIndex = 0; segIndex < segCount; segIndex++) {
24988 segment = segments[segIndex];
24989 const rangeOffset = file.getUint16();
24990 if (!rangeOffset) {
24991 segment.offsetIndex = -1;
24992 continue;
24993 }
24994 offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
24995 segment.offsetIndex = offsetIndex;
24996 offsetsCount = Math.max(offsetsCount, offsetIndex + segment.end - segment.start + 1);
24997 }
24998 const offsets = [];
24999 for (j = 0; j < offsetsCount; j++) {
25000 offsets.push(file.getUint16());
25001 }
25002 for (segIndex = 0; segIndex < segCount; segIndex++) {
25003 segment = segments[segIndex];
25004 start = segment.start;
25005 const end = segment.end;
25006 const delta = segment.delta;
25007 offsetIndex = segment.offsetIndex;
25008 for (j = start; j <= end; j++) {
25009 if (j === 0xffff) {
25010 continue;
25011 }
25012 glyphId = offsetIndex < 0 ? j : offsets[offsetIndex + j - start];
25013 glyphId = glyphId + delta & 0xffff;
25014 mappings.push({
25015 charCode: j,
25016 glyphId
25017 });
25018 }
25019 }
25020 } else if (format === 6) {
25021 file.skip(2 + 2);
25022 const firstCode = file.getUint16();
25023 const entryCount = file.getUint16();
25024 for (j = 0; j < entryCount; j++) {
25025 glyphId = file.getUint16();
25026 const charCode = firstCode + j;
25027 mappings.push({
25028 charCode,
25029 glyphId
25030 });
25031 }
25032 } else if (format === 12) {
25033 file.skip(2 + 4 + 4);
25034 const nGroups = file.getInt32() >>> 0;
25035 for (j = 0; j < nGroups; j++) {
25036 const startCharCode = file.getInt32() >>> 0;
25037 const endCharCode = file.getInt32() >>> 0;
25038 let glyphCode = file.getInt32() >>> 0;
25039 for (let charCode = startCharCode; charCode <= endCharCode; charCode++) {
25040 mappings.push({
25041 charCode,
25042 glyphId: glyphCode++
25043 });
25044 }
25045 }
25046 } else {
25047 warn("cmap table has unsupported format: " + format);
25048 return {
25049 platformId: -1,
25050 encodingId: -1,
25051 mappings: [],
25052 hasShortCmap: false
25053 };
25054 }
25055 mappings.sort(function (a, b) {
25056 return a.charCode - b.charCode;
25057 });
25058 for (let i = 1; i < mappings.length; i++) {
25059 if (mappings[i - 1].charCode === mappings[i].charCode) {
25060 mappings.splice(i, 1);
25061 i--;
25062 }
25063 }
25064 return {
25065 platformId: potentialTable.platformId,
25066 encodingId: potentialTable.encodingId,
25067 mappings,
25068 hasShortCmap
25069 };
25070 }
25071 function sanitizeMetrics(file, header, metrics, headTable, numGlyphs, dupFirstEntry) {
25072 if (!header) {
25073 if (metrics) {
25074 metrics.data = null;
25075 }
25076 return;
25077 }
25078 file.pos = (file.start || 0) + header.offset;
25079 file.pos += 4;
25080 file.pos += 2;
25081 file.pos += 2;
25082 file.pos += 2;
25083 file.pos += 2;
25084 file.pos += 2;
25085 file.pos += 2;
25086 file.pos += 2;
25087 file.pos += 2;
25088 file.pos += 2;
25089 const caretOffset = file.getUint16();
25090 file.pos += 8;
25091 file.pos += 2;
25092 let numOfMetrics = file.getUint16();
25093 if (caretOffset !== 0) {
25094 const macStyle = int16(headTable.data[44], headTable.data[45]);
25095 if (!(macStyle & 2)) {
25096 header.data[22] = 0;
25097 header.data[23] = 0;
25098 }
25099 }
25100 if (numOfMetrics > numGlyphs) {
25101 info(`The numOfMetrics (${numOfMetrics}) should not be ` + `greater than the numGlyphs (${numGlyphs}).`);
25102 numOfMetrics = numGlyphs;
25103 header.data[34] = (numOfMetrics & 0xff00) >> 8;
25104 header.data[35] = numOfMetrics & 0x00ff;
25105 }
25106 const numOfSidebearings = numGlyphs - numOfMetrics;
25107 const numMissing = numOfSidebearings - (metrics.length - numOfMetrics * 4 >> 1);
25108 if (numMissing > 0) {
25109 const entries = new Uint8Array(metrics.length + numMissing * 2);
25110 entries.set(metrics.data);
25111 if (dupFirstEntry) {
25112 entries[metrics.length] = metrics.data[2];
25113 entries[metrics.length + 1] = metrics.data[3];
25114 }
25115 metrics.data = entries;
25116 }
25117 }
25118 function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart, hintsValid) {
25119 const glyphProfile = {
25120 length: 0,
25121 sizeOfInstructions: 0
25122 };
25123 if (sourceStart < 0 || sourceStart >= source.length || sourceEnd > source.length || sourceEnd - sourceStart <= 12) {
25124 return glyphProfile;
25125 }
25126 const glyf = source.subarray(sourceStart, sourceEnd);
25127 const xMin = signedInt16(glyf[2], glyf[3]);
25128 const yMin = signedInt16(glyf[4], glyf[5]);
25129 const xMax = signedInt16(glyf[6], glyf[7]);
25130 const yMax = signedInt16(glyf[8], glyf[9]);
25131 if (xMin > xMax) {
25132 writeSignedInt16(glyf, 2, xMax);
25133 writeSignedInt16(glyf, 6, xMin);
25134 }
25135 if (yMin > yMax) {
25136 writeSignedInt16(glyf, 4, yMax);
25137 writeSignedInt16(glyf, 8, yMin);
25138 }
25139 const contoursCount = signedInt16(glyf[0], glyf[1]);
25140 if (contoursCount < 0) {
25141 if (contoursCount < -1) {
25142 return glyphProfile;
25143 }
25144 dest.set(glyf, destStart);
25145 glyphProfile.length = glyf.length;
25146 return glyphProfile;
25147 }
25148 let i,
25149 j = 10,
25150 flagsCount = 0;
25151 for (i = 0; i < contoursCount; i++) {
25152 const endPoint = glyf[j] << 8 | glyf[j + 1];
25153 flagsCount = endPoint + 1;
25154 j += 2;
25155 }
25156 const instructionsStart = j;
25157 const instructionsLength = glyf[j] << 8 | glyf[j + 1];
25158 glyphProfile.sizeOfInstructions = instructionsLength;
25159 j += 2 + instructionsLength;
25160 const instructionsEnd = j;
25161 let coordinatesLength = 0;
25162 for (i = 0; i < flagsCount; i++) {
25163 const flag = glyf[j++];
25164 if (flag & 0xc0) {
25165 glyf[j - 1] = flag & 0x3f;
25166 }
25167 let xLength = 2;
25168 if (flag & 2) {
25169 xLength = 1;
25170 } else if (flag & 16) {
25171 xLength = 0;
25172 }
25173 let yLength = 2;
25174 if (flag & 4) {
25175 yLength = 1;
25176 } else if (flag & 32) {
25177 yLength = 0;
25178 }
25179 const xyLength = xLength + yLength;
25180 coordinatesLength += xyLength;
25181 if (flag & 8) {
25182 const repeat = glyf[j++];
25183 if (repeat === 0) {
25184 glyf[j - 1] ^= 8;
25185 }
25186 i += repeat;
25187 coordinatesLength += repeat * xyLength;
25188 }
25189 }
25190 if (coordinatesLength === 0) {
25191 return glyphProfile;
25192 }
25193 let glyphDataLength = j + coordinatesLength;
25194 if (glyphDataLength > glyf.length) {
25195 return glyphProfile;
25196 }
25197 if (!hintsValid && instructionsLength > 0) {
25198 dest.set(glyf.subarray(0, instructionsStart), destStart);
25199 dest.set([0, 0], destStart + instructionsStart);
25200 dest.set(glyf.subarray(instructionsEnd, glyphDataLength), destStart + instructionsStart + 2);
25201 glyphDataLength -= instructionsLength;
25202 if (glyf.length - glyphDataLength > 3) {
25203 glyphDataLength = glyphDataLength + 3 & ~3;
25204 }
25205 glyphProfile.length = glyphDataLength;
25206 return glyphProfile;
25207 }
25208 if (glyf.length - glyphDataLength > 3) {
25209 glyphDataLength = glyphDataLength + 3 & ~3;
25210 dest.set(glyf.subarray(0, glyphDataLength), destStart);
25211 glyphProfile.length = glyphDataLength;
25212 return glyphProfile;
25213 }
25214 dest.set(glyf, destStart);
25215 glyphProfile.length = glyf.length;
25216 return glyphProfile;
25217 }
25218 function sanitizeHead(head, numGlyphs, locaLength) {
25219 const data = head.data;
25220 const version = int32(data[0], data[1], data[2], data[3]);
25221 if (version >> 16 !== 1) {
25222 info("Attempting to fix invalid version in head table: " + version);
25223 data[0] = 0;
25224 data[1] = 1;
25225 data[2] = 0;
25226 data[3] = 0;
25227 }
25228 const indexToLocFormat = int16(data[50], data[51]);
25229 if (indexToLocFormat < 0 || indexToLocFormat > 1) {
25230 info("Attempting to fix invalid indexToLocFormat in head table: " + indexToLocFormat);
25231 const numGlyphsPlusOne = numGlyphs + 1;
25232 if (locaLength === numGlyphsPlusOne << 1) {
25233 data[50] = 0;
25234 data[51] = 0;
25235 } else if (locaLength === numGlyphsPlusOne << 2) {
25236 data[50] = 0;
25237 data[51] = 1;
25238 } else {
25239 throw new FormatError("Could not fix indexToLocFormat: " + indexToLocFormat);
25240 }
25241 }
25242 }
25243 function sanitizeGlyphLocations(loca, glyf, numGlyphs, isGlyphLocationsLong, hintsValid, dupFirstEntry, maxSizeOfInstructions) {
25244 let itemSize, itemDecode, itemEncode;
25245 if (isGlyphLocationsLong) {
25246 itemSize = 4;
25247 itemDecode = function fontItemDecodeLong(data, offset) {
25248 return data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3];
25249 };
25250 itemEncode = function fontItemEncodeLong(data, offset, value) {
25251 data[offset] = value >>> 24 & 0xff;
25252 data[offset + 1] = value >> 16 & 0xff;
25253 data[offset + 2] = value >> 8 & 0xff;
25254 data[offset + 3] = value & 0xff;
25255 };
25256 } else {
25257 itemSize = 2;
25258 itemDecode = function fontItemDecode(data, offset) {
25259 return data[offset] << 9 | data[offset + 1] << 1;
25260 };
25261 itemEncode = function fontItemEncode(data, offset, value) {
25262 data[offset] = value >> 9 & 0xff;
25263 data[offset + 1] = value >> 1 & 0xff;
25264 };
25265 }
25266 const numGlyphsOut = dupFirstEntry ? numGlyphs + 1 : numGlyphs;
25267 const locaDataSize = itemSize * (1 + numGlyphsOut);
25268 const locaData = new Uint8Array(locaDataSize);
25269 locaData.set(loca.data.subarray(0, locaDataSize));
25270 loca.data = locaData;
25271 const oldGlyfData = glyf.data;
25272 const oldGlyfDataLength = oldGlyfData.length;
25273 const newGlyfData = new Uint8Array(oldGlyfDataLength);
25274 let i, j;
25275 const locaEntries = [];
25276 for (i = 0, j = 0; i < numGlyphs + 1; i++, j += itemSize) {
25277 let offset = itemDecode(locaData, j);
25278 if (offset > oldGlyfDataLength) {
25279 offset = oldGlyfDataLength;
25280 }
25281 locaEntries.push({
25282 index: i,
25283 offset,
25284 endOffset: 0
25285 });
25286 }
25287 locaEntries.sort((a, b) => a.offset - b.offset);
25288 for (i = 0; i < numGlyphs; i++) {
25289 locaEntries[i].endOffset = locaEntries[i + 1].offset;
25290 }
25291 locaEntries.sort((a, b) => a.index - b.index);
25292 for (i = 0; i < numGlyphs; i++) {
25293 const {
25294 offset,
25295 endOffset
25296 } = locaEntries[i];
25297 if (offset !== 0 || endOffset !== 0) {
25298 break;
25299 }
25300 const nextOffset = locaEntries[i + 1].offset;
25301 if (nextOffset === 0) {
25302 continue;
25303 }
25304 locaEntries[i].endOffset = nextOffset;
25305 break;
25306 }
25307 const last = locaEntries.at(-2);
25308 if (last.offset !== 0 && last.endOffset === 0) {
25309 last.endOffset = oldGlyfDataLength;
25310 }
25311 const missingGlyphs = Object.create(null);
25312 let writeOffset = 0;
25313 itemEncode(locaData, 0, writeOffset);
25314 for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
25315 const glyphProfile = sanitizeGlyph(oldGlyfData, locaEntries[i].offset, locaEntries[i].endOffset, newGlyfData, writeOffset, hintsValid);
25316 const newLength = glyphProfile.length;
25317 if (newLength === 0) {
25318 missingGlyphs[i] = true;
25319 }
25320 if (glyphProfile.sizeOfInstructions > maxSizeOfInstructions) {
25321 maxSizeOfInstructions = glyphProfile.sizeOfInstructions;
25322 }
25323 writeOffset += newLength;
25324 itemEncode(locaData, j, writeOffset);
25325 }
25326 if (writeOffset === 0) {
25327 const simpleGlyph = new Uint8Array([0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
25328 for (i = 0, j = itemSize; i < numGlyphsOut; i++, j += itemSize) {
25329 itemEncode(locaData, j, simpleGlyph.length);
25330 }
25331 glyf.data = simpleGlyph;
25332 } else if (dupFirstEntry) {
25333 const firstEntryLength = itemDecode(locaData, itemSize);
25334 if (newGlyfData.length > firstEntryLength + writeOffset) {
25335 glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
25336 } else {
25337 glyf.data = new Uint8Array(firstEntryLength + writeOffset);
25338 glyf.data.set(newGlyfData.subarray(0, writeOffset));
25339 }
25340 glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
25341 itemEncode(loca.data, locaData.length - itemSize, writeOffset + firstEntryLength);
25342 } else {
25343 glyf.data = newGlyfData.subarray(0, writeOffset);
25344 }
25345 return {
25346 missingGlyphs,
25347 maxSizeOfInstructions
25348 };
25349 }
25350 function readPostScriptTable(post, propertiesObj, maxpNumGlyphs) {
25351 const start = (font.start || 0) + post.offset;
25352 font.pos = start;
25353 const length = post.length,
25354 end = start + length;
25355 const version = font.getInt32();
25356 font.skip(28);
25357 let glyphNames;
25358 let valid = true;
25359 let i;
25360 switch (version) {
25361 case 0x00010000:
25362 glyphNames = MacStandardGlyphOrdering;
25363 break;
25364 case 0x00020000:
25365 const numGlyphs = font.getUint16();
25366 if (numGlyphs !== maxpNumGlyphs) {
25367 valid = false;
25368 break;
25369 }
25370 const glyphNameIndexes = [];
25371 for (i = 0; i < numGlyphs; ++i) {
25372 const index = font.getUint16();
25373 if (index >= 32768) {
25374 valid = false;
25375 break;
25376 }
25377 glyphNameIndexes.push(index);
25378 }
25379 if (!valid) {
25380 break;
25381 }
25382 const customNames = [],
25383 strBuf = [];
25384 while (font.pos < end) {
25385 const stringLength = font.getByte();
25386 strBuf.length = stringLength;
25387 for (i = 0; i < stringLength; ++i) {
25388 strBuf[i] = String.fromCharCode(font.getByte());
25389 }
25390 customNames.push(strBuf.join(""));
25391 }
25392 glyphNames = [];
25393 for (i = 0; i < numGlyphs; ++i) {
25394 const j = glyphNameIndexes[i];
25395 if (j < 258) {
25396 glyphNames.push(MacStandardGlyphOrdering[j]);
25397 continue;
25398 }
25399 glyphNames.push(customNames[j - 258]);
25400 }
25401 break;
25402 case 0x00030000:
25403 break;
25404 default:
25405 warn("Unknown/unsupported post table version " + version);
25406 valid = false;
25407 if (propertiesObj.defaultEncoding) {
25408 glyphNames = propertiesObj.defaultEncoding;
25409 }
25410 break;
25411 }
25412 propertiesObj.glyphNames = glyphNames;
25413 return valid;
25414 }
25415 function readNameTable(nameTable) {
25416 const start = (font.start || 0) + nameTable.offset;
25417 font.pos = start;
25418 const names = [[], []],
25419 records = [];
25420 const length = nameTable.length,
25421 end = start + length;
25422 const format = font.getUint16();
25423 const FORMAT_0_HEADER_LENGTH = 6;
25424 if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
25425 return [names, records];
25426 }
25427 const numRecords = font.getUint16();
25428 const stringsStart = font.getUint16();
25429 const NAME_RECORD_LENGTH = 12;
25430 let i, ii;
25431 for (i = 0; i < numRecords && font.pos + NAME_RECORD_LENGTH <= end; i++) {
25432 const r = {
25433 platform: font.getUint16(),
25434 encoding: font.getUint16(),
25435 language: font.getUint16(),
25436 name: font.getUint16(),
25437 length: font.getUint16(),
25438 offset: font.getUint16()
25439 };
25440 if (isMacNameRecord(r) || isWinNameRecord(r)) {
25441 records.push(r);
25442 }
25443 }
25444 for (i = 0, ii = records.length; i < ii; i++) {
25445 const record = records[i];
25446 if (record.length <= 0) {
25447 continue;
25448 }
25449 const pos = start + stringsStart + record.offset;
25450 if (pos + record.length > end) {
25451 continue;
25452 }
25453 font.pos = pos;
25454 const nameIndex = record.name;
25455 if (record.encoding) {
25456 let str = "";
25457 for (let j = 0, jj = record.length; j < jj; j += 2) {
25458 str += String.fromCharCode(font.getUint16());
25459 }
25460 names[1][nameIndex] = str;
25461 } else {
25462 names[0][nameIndex] = font.getString(record.length);
25463 }
25464 }
25465 return [names, records];
25466 }
25467 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];
25468 function sanitizeTTProgram(table, ttContext) {
25469 let data = table.data;
25470 let i = 0,
25471 j,
25472 n,
25473 b,
25474 funcId,
25475 pc,
25476 lastEndf = 0,
25477 lastDeff = 0;
25478 const stack = [];
25479 const callstack = [];
25480 const functionsCalled = [];
25481 let tooComplexToFollowFunctions = ttContext.tooComplexToFollowFunctions;
25482 let inFDEF = false,
25483 ifLevel = 0,
25484 inELSE = 0;
25485 for (let ii = data.length; i < ii;) {
25486 const op = data[i++];
25487 if (op === 0x40) {
25488 n = data[i++];
25489 if (inFDEF || inELSE) {
25490 i += n;
25491 } else {
25492 for (j = 0; j < n; j++) {
25493 stack.push(data[i++]);
25494 }
25495 }
25496 } else if (op === 0x41) {
25497 n = data[i++];
25498 if (inFDEF || inELSE) {
25499 i += n * 2;
25500 } else {
25501 for (j = 0; j < n; j++) {
25502 b = data[i++];
25503 stack.push(b << 8 | data[i++]);
25504 }
25505 }
25506 } else if ((op & 0xf8) === 0xb0) {
25507 n = op - 0xb0 + 1;
25508 if (inFDEF || inELSE) {
25509 i += n;
25510 } else {
25511 for (j = 0; j < n; j++) {
25512 stack.push(data[i++]);
25513 }
25514 }
25515 } else if ((op & 0xf8) === 0xb8) {
25516 n = op - 0xb8 + 1;
25517 if (inFDEF || inELSE) {
25518 i += n * 2;
25519 } else {
25520 for (j = 0; j < n; j++) {
25521 b = data[i++];
25522 stack.push(b << 8 | data[i++]);
25523 }
25524 }
25525 } else if (op === 0x2b && !tooComplexToFollowFunctions) {
25526 if (!inFDEF && !inELSE) {
25527 funcId = stack.at(-1);
25528 if (isNaN(funcId)) {
25529 info("TT: CALL empty stack (or invalid entry).");
25530 } else {
25531 ttContext.functionsUsed[funcId] = true;
25532 if (funcId in ttContext.functionsStackDeltas) {
25533 const newStackLength = stack.length + ttContext.functionsStackDeltas[funcId];
25534 if (newStackLength < 0) {
25535 warn("TT: CALL invalid functions stack delta.");
25536 ttContext.hintsValid = false;
25537 return;
25538 }
25539 stack.length = newStackLength;
25540 } else if (funcId in ttContext.functionsDefined && !functionsCalled.includes(funcId)) {
25541 callstack.push({
25542 data,
25543 i,
25544 stackTop: stack.length - 1
25545 });
25546 functionsCalled.push(funcId);
25547 pc = ttContext.functionsDefined[funcId];
25548 if (!pc) {
25549 warn("TT: CALL non-existent function");
25550 ttContext.hintsValid = false;
25551 return;
25552 }
25553 data = pc.data;
25554 i = pc.i;
25555 }
25556 }
25557 }
25558 } else if (op === 0x2c && !tooComplexToFollowFunctions) {
25559 if (inFDEF || inELSE) {
25560 warn("TT: nested FDEFs not allowed");
25561 tooComplexToFollowFunctions = true;
25562 }
25563 inFDEF = true;
25564 lastDeff = i;
25565 funcId = stack.pop();
25566 ttContext.functionsDefined[funcId] = {
25567 data,
25568 i
25569 };
25570 } else if (op === 0x2d) {
25571 if (inFDEF) {
25572 inFDEF = false;
25573 lastEndf = i;
25574 } else {
25575 pc = callstack.pop();
25576 if (!pc) {
25577 warn("TT: ENDF bad stack");
25578 ttContext.hintsValid = false;
25579 return;
25580 }
25581 funcId = functionsCalled.pop();
25582 data = pc.data;
25583 i = pc.i;
25584 ttContext.functionsStackDeltas[funcId] = stack.length - pc.stackTop;
25585 }
25586 } else if (op === 0x89) {
25587 if (inFDEF || inELSE) {
25588 warn("TT: nested IDEFs not allowed");
25589 tooComplexToFollowFunctions = true;
25590 }
25591 inFDEF = true;
25592 lastDeff = i;
25593 } else if (op === 0x58) {
25594 ++ifLevel;
25595 } else if (op === 0x1b) {
25596 inELSE = ifLevel;
25597 } else if (op === 0x59) {
25598 if (inELSE === ifLevel) {
25599 inELSE = 0;
25600 }
25601 --ifLevel;
25602 } else if (op === 0x1c) {
25603 if (!inFDEF && !inELSE) {
25604 const offset = stack.at(-1);
25605 if (offset > 0) {
25606 i += offset - 1;
25607 }
25608 }
25609 }
25610 if (!inFDEF && !inELSE) {
25611 let stackDelta = 0;
25612 if (op <= 0x8e) {
25613 stackDelta = TTOpsStackDeltas[op];
25614 } else if (op >= 0xc0 && op <= 0xdf) {
25615 stackDelta = -1;
25616 } else if (op >= 0xe0) {
25617 stackDelta = -2;
25618 }
25619 if (op >= 0x71 && op <= 0x75) {
25620 n = stack.pop();
25621 if (!isNaN(n)) {
25622 stackDelta = -n * 2;
25623 }
25624 }
25625 while (stackDelta < 0 && stack.length > 0) {
25626 stack.pop();
25627 stackDelta++;
25628 }
25629 while (stackDelta > 0) {
25630 stack.push(NaN);
25631 stackDelta--;
25632 }
25633 }
25634 }
25635 ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
25636 const content = [data];
25637 if (i > data.length) {
25638 content.push(new Uint8Array(i - data.length));
25639 }
25640 if (lastDeff > lastEndf) {
25641 warn("TT: complementing a missing function tail");
25642 content.push(new Uint8Array([0x22, 0x2d]));
25643 }
25644 foldTTTable(table, content);
25645 }
25646 function checkInvalidFunctions(ttContext, maxFunctionDefs) {
25647 if (ttContext.tooComplexToFollowFunctions) {
25648 return;
25649 }
25650 if (ttContext.functionsDefined.length > maxFunctionDefs) {
25651 warn("TT: more functions defined than expected");
25652 ttContext.hintsValid = false;
25653 return;
25654 }
25655 for (let j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
25656 if (j > maxFunctionDefs) {
25657 warn("TT: invalid function id: " + j);
25658 ttContext.hintsValid = false;
25659 return;
25660 }
25661 if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
25662 warn("TT: undefined function: " + j);
25663 ttContext.hintsValid = false;
25664 return;
25665 }
25666 }
25667 }
25668 function foldTTTable(table, content) {
25669 if (content.length > 1) {
25670 let newLength = 0;
25671 let j, jj;
25672 for (j = 0, jj = content.length; j < jj; j++) {
25673 newLength += content[j].length;
25674 }
25675 newLength = newLength + 3 & ~3;
25676 const result = new Uint8Array(newLength);
25677 let pos = 0;
25678 for (j = 0, jj = content.length; j < jj; j++) {
25679 result.set(content[j], pos);
25680 pos += content[j].length;
25681 }
25682 table.data = result;
25683 table.length = newLength;
25684 }
25685 }
25686 function sanitizeTTPrograms(fpgm, prep, cvt, maxFunctionDefs) {
25687 const ttContext = {
25688 functionsDefined: [],
25689 functionsUsed: [],
25690 functionsStackDeltas: [],
25691 tooComplexToFollowFunctions: false,
25692 hintsValid: true
25693 };
25694 if (fpgm) {
25695 sanitizeTTProgram(fpgm, ttContext);
25696 }
25697 if (prep) {
25698 sanitizeTTProgram(prep, ttContext);
25699 }
25700 if (fpgm) {
25701 checkInvalidFunctions(ttContext, maxFunctionDefs);
25702 }
25703 if (cvt && cvt.length & 1) {
25704 const cvtData = new Uint8Array(cvt.length + 1);
25705 cvtData.set(cvt.data);
25706 cvt.data = cvtData;
25707 }
25708 return ttContext.hintsValid;
25709 }
25710 font = new Stream(new Uint8Array(font.getBytes()));
25711 let header, tables;
25712 if (isTrueTypeCollectionFile(font)) {
25713 const ttcData = readTrueTypeCollectionData(font, this.name);
25714 header = ttcData.header;
25715 tables = ttcData.tables;
25716 } else {
25717 header = readOpenTypeHeader(font);
25718 tables = readTables(font, header.numTables);
25719 }
25720 let cff, cffFile;
25721 const isTrueType = !tables["CFF "];
25722 if (!isTrueType) {
25723 const isComposite = properties.composite && (properties.cidToGidMap?.length > 0 || !(properties.cMap instanceof IdentityCMap));
25724 if (header.version === "OTTO" && !isComposite || !tables.head || !tables.hhea || !tables.maxp || !tables.post) {
25725 cffFile = new Stream(tables["CFF "].data);
25726 cff = new CFFFont(cffFile, properties);
25727 adjustWidths(properties);
25728 return this.convert(name, cff, properties);
25729 }
25730 delete tables.glyf;
25731 delete tables.loca;
25732 delete tables.fpgm;
25733 delete tables.prep;
25734 delete tables["cvt "];
25735 this.isOpenType = true;
25736 } else {
25737 if (!tables.loca) {
25738 throw new FormatError('Required "loca" table is not found');
25739 }
25740 if (!tables.glyf) {
25741 warn('Required "glyf" table is not found -- trying to recover.');
25742 tables.glyf = {
25743 tag: "glyf",
25744 data: new Uint8Array(0)
25745 };
25746 }
25747 this.isOpenType = false;
25748 }
25749 if (!tables.maxp) {
25750 throw new FormatError('Required "maxp" table is not found');
25751 }
25752 font.pos = (font.start || 0) + tables.maxp.offset;
25753 let version = font.getInt32();
25754 const numGlyphs = font.getUint16();
25755 if (version !== 0x00010000 && version !== 0x00005000) {
25756 if (tables.maxp.length === 6) {
25757 version = 0x0005000;
25758 } else if (tables.maxp.length >= 32) {
25759 version = 0x00010000;
25760 } else {
25761 throw new FormatError(`"maxp" table has a wrong version number`);
25762 }
25763 writeUint32(tables.maxp.data, 0, version);
25764 }
25765 if (properties.scaleFactors?.length === numGlyphs && isTrueType) {
25766 const {
25767 scaleFactors
25768 } = properties;
25769 const isGlyphLocationsLong = int16(tables.head.data[50], tables.head.data[51]);
25770 const glyphs = new GlyfTable({
25771 glyfTable: tables.glyf.data,
25772 isGlyphLocationsLong,
25773 locaTable: tables.loca.data,
25774 numGlyphs
25775 });
25776 glyphs.scale(scaleFactors);
25777 const {
25778 glyf,
25779 loca,
25780 isLocationLong
25781 } = glyphs.write();
25782 tables.glyf.data = glyf;
25783 tables.loca.data = loca;
25784 if (isLocationLong !== !!isGlyphLocationsLong) {
25785 tables.head.data[50] = 0;
25786 tables.head.data[51] = isLocationLong ? 1 : 0;
25787 }
25788 const metrics = tables.hmtx.data;
25789 for (let i = 0; i < numGlyphs; i++) {
25790 const j = 4 * i;
25791 const advanceWidth = Math.round(scaleFactors[i] * int16(metrics[j], metrics[j + 1]));
25792 metrics[j] = advanceWidth >> 8 & 0xff;
25793 metrics[j + 1] = advanceWidth & 0xff;
25794 const lsb = Math.round(scaleFactors[i] * signedInt16(metrics[j + 2], metrics[j + 3]));
25795 writeSignedInt16(metrics, j + 2, lsb);
25796 }
25797 }
25798 let numGlyphsOut = numGlyphs + 1;
25799 let dupFirstEntry = true;
25800 if (numGlyphsOut > 0xffff) {
25801 dupFirstEntry = false;
25802 numGlyphsOut = numGlyphs;
25803 warn("Not enough space in glyfs to duplicate first glyph.");
25804 }
25805 let maxFunctionDefs = 0;
25806 let maxSizeOfInstructions = 0;
25807 if (version >= 0x00010000 && tables.maxp.length >= 32) {
25808 font.pos += 8;
25809 const maxZones = font.getUint16();
25810 if (maxZones > 2) {
25811 tables.maxp.data[14] = 0;
25812 tables.maxp.data[15] = 2;
25813 }
25814 font.pos += 4;
25815 maxFunctionDefs = font.getUint16();
25816 font.pos += 4;
25817 maxSizeOfInstructions = font.getUint16();
25818 }
25819 tables.maxp.data[4] = numGlyphsOut >> 8;
25820 tables.maxp.data[5] = numGlyphsOut & 255;
25821 const hintsValid = sanitizeTTPrograms(tables.fpgm, tables.prep, tables["cvt "], maxFunctionDefs);
25822 if (!hintsValid) {
25823 delete tables.fpgm;
25824 delete tables.prep;
25825 delete tables["cvt "];
25826 }
25827 sanitizeMetrics(font, tables.hhea, tables.hmtx, tables.head, numGlyphsOut, dupFirstEntry);
25828 if (!tables.head) {
25829 throw new FormatError('Required "head" table is not found');
25830 }
25831 sanitizeHead(tables.head, numGlyphs, isTrueType ? tables.loca.length : 0);
25832 let missingGlyphs = Object.create(null);
25833 if (isTrueType) {
25834 const isGlyphLocationsLong = int16(tables.head.data[50], tables.head.data[51]);
25835 const glyphsInfo = sanitizeGlyphLocations(tables.loca, tables.glyf, numGlyphs, isGlyphLocationsLong, hintsValid, dupFirstEntry, maxSizeOfInstructions);
25836 missingGlyphs = glyphsInfo.missingGlyphs;
25837 if (version >= 0x00010000 && tables.maxp.length >= 32) {
25838 tables.maxp.data[26] = glyphsInfo.maxSizeOfInstructions >> 8;
25839 tables.maxp.data[27] = glyphsInfo.maxSizeOfInstructions & 255;
25840 }
25841 }
25842 if (!tables.hhea) {
25843 throw new FormatError('Required "hhea" table is not found');
25844 }
25845 if (tables.hhea.data[10] === 0 && tables.hhea.data[11] === 0) {
25846 tables.hhea.data[10] = 0xff;
25847 tables.hhea.data[11] = 0xff;
25848 }
25849 const metricsOverride = {
25850 unitsPerEm: int16(tables.head.data[18], tables.head.data[19]),
25851 yMax: signedInt16(tables.head.data[42], tables.head.data[43]),
25852 yMin: signedInt16(tables.head.data[38], tables.head.data[39]),
25853 ascent: signedInt16(tables.hhea.data[4], tables.hhea.data[5]),
25854 descent: signedInt16(tables.hhea.data[6], tables.hhea.data[7]),
25855 lineGap: signedInt16(tables.hhea.data[8], tables.hhea.data[9])
25856 };
25857 this.ascent = metricsOverride.ascent / metricsOverride.unitsPerEm;
25858 this.descent = metricsOverride.descent / metricsOverride.unitsPerEm;
25859 this.lineGap = metricsOverride.lineGap / metricsOverride.unitsPerEm;
25860 if (this.cssFontInfo?.lineHeight) {
25861 this.lineHeight = this.cssFontInfo.metrics.lineHeight;
25862 this.lineGap = this.cssFontInfo.metrics.lineGap;
25863 } else {
25864 this.lineHeight = this.ascent - this.descent + this.lineGap;
25865 }
25866 if (tables.post) {
25867 readPostScriptTable(tables.post, properties, numGlyphs);
25868 }
25869 tables.post = {
25870 tag: "post",
25871 data: createPostTable(properties)
25872 };
25873 const charCodeToGlyphId = [];
25874 function hasGlyph(glyphId) {
25875 return !missingGlyphs[glyphId];
25876 }
25877 if (properties.composite) {
25878 const cidToGidMap = properties.cidToGidMap || [];
25879 const isCidToGidMapEmpty = cidToGidMap.length === 0;
25880 properties.cMap.forEach(function (charCode, cid) {
25881 if (typeof cid === "string") {
25882 cid = convertCidString(charCode, cid, true);
25883 }
25884 if (cid > 0xffff) {
25885 throw new FormatError("Max size of CID is 65,535");
25886 }
25887 let glyphId = -1;
25888 if (isCidToGidMapEmpty) {
25889 glyphId = cid;
25890 } else if (cidToGidMap[cid] !== undefined) {
25891 glyphId = cidToGidMap[cid];
25892 }
25893 if (glyphId >= 0 && glyphId < numGlyphs && hasGlyph(glyphId)) {
25894 charCodeToGlyphId[charCode] = glyphId;
25895 }
25896 });
25897 } else {
25898 const cmapTable = readCmapTable(tables.cmap, font, this.isSymbolicFont, properties.hasEncoding);
25899 const cmapPlatformId = cmapTable.platformId;
25900 const cmapEncodingId = cmapTable.encodingId;
25901 const cmapMappings = cmapTable.mappings;
25902 let baseEncoding = [],
25903 forcePostTable = false;
25904 if (properties.hasEncoding && (properties.baseEncodingName === "MacRomanEncoding" || properties.baseEncodingName === "WinAnsiEncoding")) {
25905 baseEncoding = getEncoding(properties.baseEncodingName);
25906 }
25907 if (properties.hasEncoding && !this.isSymbolicFont && (cmapPlatformId === 3 && cmapEncodingId === 1 || cmapPlatformId === 1 && cmapEncodingId === 0)) {
25908 const glyphsUnicodeMap = getGlyphsUnicode();
25909 for (let charCode = 0; charCode < 256; charCode++) {
25910 let glyphName;
25911 if (this.differences[charCode] !== undefined) {
25912 glyphName = this.differences[charCode];
25913 } else if (baseEncoding.length && baseEncoding[charCode] !== "") {
25914 glyphName = baseEncoding[charCode];
25915 } else {
25916 glyphName = StandardEncoding[charCode];
25917 }
25918 if (!glyphName) {
25919 continue;
25920 }
25921 const standardGlyphName = recoverGlyphName(glyphName, glyphsUnicodeMap);
25922 let unicodeOrCharCode;
25923 if (cmapPlatformId === 3 && cmapEncodingId === 1) {
25924 unicodeOrCharCode = glyphsUnicodeMap[standardGlyphName];
25925 } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
25926 unicodeOrCharCode = MacRomanEncoding.indexOf(standardGlyphName);
25927 }
25928 if (unicodeOrCharCode === undefined) {
25929 if (!properties.glyphNames && properties.hasIncludedToUnicodeMap && !(this.toUnicode instanceof IdentityToUnicodeMap)) {
25930 const unicode = this.toUnicode.get(charCode);
25931 if (unicode) {
25932 unicodeOrCharCode = unicode.codePointAt(0);
25933 }
25934 }
25935 if (unicodeOrCharCode === undefined) {
25936 continue;
25937 }
25938 }
25939 for (const mapping of cmapMappings) {
25940 if (mapping.charCode !== unicodeOrCharCode) {
25941 continue;
25942 }
25943 charCodeToGlyphId[charCode] = mapping.glyphId;
25944 break;
25945 }
25946 }
25947 } else if (cmapPlatformId === 0) {
25948 for (const mapping of cmapMappings) {
25949 charCodeToGlyphId[mapping.charCode] = mapping.glyphId;
25950 }
25951 forcePostTable = true;
25952 } else if (cmapPlatformId === 3 && cmapEncodingId === 0) {
25953 for (const mapping of cmapMappings) {
25954 let charCode = mapping.charCode;
25955 if (charCode >= 0xf000 && charCode <= 0xf0ff) {
25956 charCode &= 0xff;
25957 }
25958 charCodeToGlyphId[charCode] = mapping.glyphId;
25959 }
25960 } else {
25961 for (const mapping of cmapMappings) {
25962 charCodeToGlyphId[mapping.charCode] = mapping.glyphId;
25963 }
25964 }
25965 if (properties.glyphNames && (baseEncoding.length || this.differences.length)) {
25966 for (let i = 0; i < 256; ++i) {
25967 if (!forcePostTable && charCodeToGlyphId[i] !== undefined) {
25968 continue;
25969 }
25970 const glyphName = this.differences[i] || baseEncoding[i];
25971 if (!glyphName) {
25972 continue;
25973 }
25974 const glyphId = properties.glyphNames.indexOf(glyphName);
25975 if (glyphId > 0 && hasGlyph(glyphId)) {
25976 charCodeToGlyphId[i] = glyphId;
25977 }
25978 }
25979 }
25980 }
25981 if (charCodeToGlyphId.length === 0) {
25982 charCodeToGlyphId[0] = 0;
25983 }
25984 let glyphZeroId = numGlyphsOut - 1;
25985 if (!dupFirstEntry) {
25986 glyphZeroId = 0;
25987 }
25988 if (!properties.cssFontInfo) {
25989 const newMapping = adjustMapping(charCodeToGlyphId, hasGlyph, glyphZeroId, this.toUnicode);
25990 this.toFontChar = newMapping.toFontChar;
25991 tables.cmap = {
25992 tag: "cmap",
25993 data: createCmapTable(newMapping.charCodeToGlyphId, newMapping.toUnicodeExtraMap, numGlyphsOut)
25994 };
25995 if (!tables["OS/2"] || !validateOS2Table(tables["OS/2"], font)) {
25996 tables["OS/2"] = {
25997 tag: "OS/2",
25998 data: createOS2Table(properties, newMapping.charCodeToGlyphId, metricsOverride)
25999 };
26000 }
26001 }
26002 if (!isTrueType) {
26003 try {
26004 cffFile = new Stream(tables["CFF "].data);
26005 const parser = new CFFParser(cffFile, properties, SEAC_ANALYSIS_ENABLED);
26006 cff = parser.parse();
26007 cff.duplicateFirstGlyph();
26008 const compiler = new CFFCompiler(cff);
26009 tables["CFF "].data = compiler.compile();
26010 } catch {
26011 warn("Failed to compile font " + properties.loadedName);
26012 }
26013 }
26014 if (!tables.name) {
26015 tables.name = {
26016 tag: "name",
26017 data: createNameTable(this.name)
26018 };
26019 } else {
26020 const [namePrototype, nameRecords] = readNameTable(tables.name);
26021 tables.name.data = createNameTable(name, namePrototype);
26022 this.psName = namePrototype[0][6] || null;
26023 if (!properties.composite) {
26024 adjustTrueTypeToUnicode(properties, this.isSymbolicFont, nameRecords);
26025 }
26026 }
26027 const builder = new OpenTypeFileBuilder(header.version);
26028 for (const tableTag in tables) {
26029 builder.addTable(tableTag, tables[tableTag].data);
26030 }
26031 return builder.toArray();
26032 }
26033 convert(fontName, font, properties) {
26034 properties.fixedPitch = false;
26035 if (properties.builtInEncoding) {
26036 adjustType1ToUnicode(properties, properties.builtInEncoding);
26037 }
26038 let glyphZeroId = 1;
26039 if (font instanceof CFFFont) {
26040 glyphZeroId = font.numGlyphs - 1;
26041 }
26042 const mapping = font.getGlyphMapping(properties);
26043 let newMapping = null;
26044 let newCharCodeToGlyphId = mapping;
26045 let toUnicodeExtraMap = null;
26046 if (!properties.cssFontInfo) {
26047 newMapping = adjustMapping(mapping, font.hasGlyphId.bind(font), glyphZeroId, this.toUnicode);
26048 this.toFontChar = newMapping.toFontChar;
26049 newCharCodeToGlyphId = newMapping.charCodeToGlyphId;
26050 toUnicodeExtraMap = newMapping.toUnicodeExtraMap;
26051 }
26052 const numGlyphs = font.numGlyphs;
26053 function getCharCodes(charCodeToGlyphId, glyphId) {
26054 let charCodes = null;
26055 for (const charCode in charCodeToGlyphId) {
26056 if (glyphId === charCodeToGlyphId[charCode]) {
26057 (charCodes ||= []).push(charCode | 0);
26058 }
26059 }
26060 return charCodes;
26061 }
26062 function createCharCode(charCodeToGlyphId, glyphId) {
26063 for (const charCode in charCodeToGlyphId) {
26064 if (glyphId === charCodeToGlyphId[charCode]) {
26065 return charCode | 0;
26066 }
26067 }
26068 newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] = glyphId;
26069 return newMapping.nextAvailableFontCharCode++;
26070 }
26071 const seacs = font.seacs;
26072 if (newMapping && SEAC_ANALYSIS_ENABLED && seacs?.length) {
26073 const matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
26074 const charset = font.getCharset();
26075 const seacMap = Object.create(null);
26076 for (let glyphId in seacs) {
26077 glyphId |= 0;
26078 const seac = seacs[glyphId];
26079 const baseGlyphName = StandardEncoding[seac[2]];
26080 const accentGlyphName = StandardEncoding[seac[3]];
26081 const baseGlyphId = charset.indexOf(baseGlyphName);
26082 const accentGlyphId = charset.indexOf(accentGlyphName);
26083 if (baseGlyphId < 0 || accentGlyphId < 0) {
26084 continue;
26085 }
26086 const accentOffset = {
26087 x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
26088 y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
26089 };
26090 const charCodes = getCharCodes(mapping, glyphId);
26091 if (!charCodes) {
26092 continue;
26093 }
26094 for (const charCode of charCodes) {
26095 const charCodeToGlyphId = newMapping.charCodeToGlyphId;
26096 const baseFontCharCode = createCharCode(charCodeToGlyphId, baseGlyphId);
26097 const accentFontCharCode = createCharCode(charCodeToGlyphId, accentGlyphId);
26098 seacMap[charCode] = {
26099 baseFontCharCode,
26100 accentFontCharCode,
26101 accentOffset
26102 };
26103 }
26104 }
26105 properties.seacMap = seacMap;
26106 }
26107 const unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
26108 const builder = new OpenTypeFileBuilder("\x4F\x54\x54\x4F");
26109 builder.addTable("CFF ", font.data);
26110 builder.addTable("OS/2", createOS2Table(properties, newCharCodeToGlyphId));
26111 builder.addTable("cmap", createCmapTable(newCharCodeToGlyphId, toUnicodeExtraMap, numGlyphs));
26112 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");
26113 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));
26114 builder.addTable("hmtx", function fontFieldsHmtx() {
26115 const charstrings = font.charstrings;
26116 const cffWidths = font.cff ? font.cff.widths : null;
26117 let hmtx = "\x00\x00\x00\x00";
26118 for (let i = 1, ii = numGlyphs; i < ii; i++) {
26119 let width = 0;
26120 if (charstrings) {
26121 const charstring = charstrings[i - 1];
26122 width = "width" in charstring ? charstring.width : 0;
26123 } else if (cffWidths) {
26124 width = Math.ceil(cffWidths[i] || 0);
26125 }
26126 hmtx += string16(width) + string16(0);
26127 }
26128 return hmtx;
26129 }());
26130 builder.addTable("maxp", "\x00\x00\x50\x00" + string16(numGlyphs));
26131 builder.addTable("name", createNameTable(fontName));
26132 builder.addTable("post", createPostTable(properties));
26133 return builder.toArray();
26134 }
26135 get spaceWidth() {
26136 const possibleSpaceReplacements = ["space", "minus", "one", "i", "I"];
26137 let width;
26138 for (const glyphName of possibleSpaceReplacements) {
26139 if (glyphName in this.widths) {
26140 width = this.widths[glyphName];
26141 break;
26142 }
26143 const glyphsUnicodeMap = getGlyphsUnicode();
26144 const glyphUnicode = glyphsUnicodeMap[glyphName];
26145 let charcode = 0;
26146 if (this.composite && this.cMap.contains(glyphUnicode)) {
26147 charcode = this.cMap.lookup(glyphUnicode);
26148 if (typeof charcode === "string") {
26149 charcode = convertCidString(glyphUnicode, charcode);
26150 }
26151 }
26152 if (!charcode && this.toUnicode) {
26153 charcode = this.toUnicode.charCodeOf(glyphUnicode);
26154 }
26155 if (charcode <= 0) {
26156 charcode = glyphUnicode;
26157 }
26158 width = this.widths[charcode];
26159 if (width) {
26160 break;
26161 }
26162 }
26163 return shadow(this, "spaceWidth", width || this.defaultWidth);
26164 }
26165 _charToGlyph(charcode, isSpace = false) {
26166 let glyph = this._glyphCache[charcode];
26167 if (glyph?.isSpace === isSpace) {
26168 return glyph;
26169 }
26170 let fontCharCode, width, operatorListId;
26171 let widthCode = charcode;
26172 if (this.cMap?.contains(charcode)) {
26173 widthCode = this.cMap.lookup(charcode);
26174 if (typeof widthCode === "string") {
26175 widthCode = convertCidString(charcode, widthCode);
26176 }
26177 }
26178 width = this.widths[widthCode];
26179 if (typeof width !== "number") {
26180 width = this.defaultWidth;
26181 }
26182 const vmetric = this.vmetrics?.[widthCode];
26183 let unicode = this.toUnicode.get(charcode) || charcode;
26184 if (typeof unicode === "number") {
26185 unicode = String.fromCharCode(unicode);
26186 }
26187 let isInFont = this.toFontChar[charcode] !== undefined;
26188 fontCharCode = this.toFontChar[charcode] || charcode;
26189 if (this.missingFile) {
26190 const glyphName = this.differences[charcode] || this.defaultEncoding[charcode];
26191 if ((glyphName === ".notdef" || glyphName === "") && this.type === "Type1") {
26192 fontCharCode = 0x20;
26193 }
26194 fontCharCode = mapSpecialUnicodeValues(fontCharCode);
26195 }
26196 if (this.isType3Font) {
26197 operatorListId = fontCharCode;
26198 }
26199 let accent = null;
26200 if (this.seacMap?.[charcode]) {
26201 isInFont = true;
26202 const seac = this.seacMap[charcode];
26203 fontCharCode = seac.baseFontCharCode;
26204 accent = {
26205 fontChar: String.fromCodePoint(seac.accentFontCharCode),
26206 offset: seac.accentOffset
26207 };
26208 }
26209 let fontChar = "";
26210 if (typeof fontCharCode === "number") {
26211 if (fontCharCode <= 0x10ffff) {
26212 fontChar = String.fromCodePoint(fontCharCode);
26213 } else {
26214 warn(`charToGlyph - invalid fontCharCode: ${fontCharCode}`);
26215 }
26216 }
26217 glyph = new fonts_Glyph(charcode, fontChar, unicode, accent, width, vmetric, operatorListId, isSpace, isInFont);
26218 return this._glyphCache[charcode] = glyph;
26219 }
26220 charsToGlyphs(chars) {
26221 let glyphs = this._charsCache[chars];
26222 if (glyphs) {
26223 return glyphs;
26224 }
26225 glyphs = [];
26226 if (this.cMap) {
26227 const c = Object.create(null),
26228 ii = chars.length;
26229 let i = 0;
26230 while (i < ii) {
26231 this.cMap.readCharCode(chars, i, c);
26232 const {
26233 charcode,
26234 length
26235 } = c;
26236 i += length;
26237 const glyph = this._charToGlyph(charcode, length === 1 && chars.charCodeAt(i - 1) === 0x20);
26238 glyphs.push(glyph);
26239 }
26240 } else {
26241 for (let i = 0, ii = chars.length; i < ii; ++i) {
26242 const charcode = chars.charCodeAt(i);
26243 const glyph = this._charToGlyph(charcode, charcode === 0x20);
26244 glyphs.push(glyph);
26245 }
26246 }
26247 return this._charsCache[chars] = glyphs;
26248 }
26249 getCharPositions(chars) {
26250 const positions = [];
26251 if (this.cMap) {
26252 const c = Object.create(null);
26253 let i = 0;
26254 while (i < chars.length) {
26255 this.cMap.readCharCode(chars, i, c);
26256 const length = c.length;
26257 positions.push([i, i + length]);
26258 i += length;
26259 }
26260 } else {
26261 for (let i = 0, ii = chars.length; i < ii; ++i) {
26262 positions.push([i, i + 1]);
26263 }
26264 }
26265 return positions;
26266 }
26267 get glyphCacheValues() {
26268 return Object.values(this._glyphCache);
26269 }
26270 encodeString(str) {
26271 const buffers = [];
26272 const currentBuf = [];
26273 const hasCurrentBufErrors = () => buffers.length % 2 === 1;
26274 const getCharCode = this.toUnicode instanceof IdentityToUnicodeMap ? unicode => this.toUnicode.charCodeOf(unicode) : unicode => this.toUnicode.charCodeOf(String.fromCodePoint(unicode));
26275 for (let i = 0, ii = str.length; i < ii; i++) {
26276 const unicode = str.codePointAt(i);
26277 if (unicode > 0xd7ff && (unicode < 0xe000 || unicode > 0xfffd)) {
26278 i++;
26279 }
26280 if (this.toUnicode) {
26281 const charCode = getCharCode(unicode);
26282 if (charCode !== -1) {
26283 if (hasCurrentBufErrors()) {
26284 buffers.push(currentBuf.join(""));
26285 currentBuf.length = 0;
26286 }
26287 const charCodeLength = this.cMap ? this.cMap.getCharCodeLength(charCode) : 1;
26288 for (let j = charCodeLength - 1; j >= 0; j--) {
26289 currentBuf.push(String.fromCharCode(charCode >> 8 * j & 0xff));
26290 }
26291 continue;
26292 }
26293 }
26294 if (!hasCurrentBufErrors()) {
26295 buffers.push(currentBuf.join(""));
26296 currentBuf.length = 0;
26297 }
26298 currentBuf.push(String.fromCodePoint(unicode));
26299 }
26300 buffers.push(currentBuf.join(""));
26301 return buffers;
26302 }
26303}
26304class ErrorFont {
26305 constructor(error) {
26306 this.error = error;
26307 this.loadedName = "g_font_error";
26308 this.missingFile = true;
26309 }
26310 charsToGlyphs() {
26311 return [];
26312 }
26313 encodeString(chars) {
26314 return [chars];
26315 }
26316 exportData(extraProperties = false) {
26317 return {
26318 error: this.error
26319 };
26320 }
26321}
26322
26323;// CONCATENATED MODULE: ./src/core/pattern.js
26324
26325
26326
26327
26328const ShadingType = {
26329 FUNCTION_BASED: 1,
26330 AXIAL: 2,
26331 RADIAL: 3,
26332 FREE_FORM_MESH: 4,
26333 LATTICE_FORM_MESH: 5,
26334 COONS_PATCH_MESH: 6,
26335 TENSOR_PATCH_MESH: 7
26336};
26337class Pattern {
26338 constructor() {
26339 unreachable("Cannot initialize Pattern.");
26340 }
26341 static parseShading(shading, xref, res, pdfFunctionFactory, localColorSpaceCache) {
26342 const dict = shading instanceof BaseStream ? shading.dict : shading;
26343 const type = dict.get("ShadingType");
26344 try {
26345 switch (type) {
26346 case ShadingType.AXIAL:
26347 case ShadingType.RADIAL:
26348 return new RadialAxialShading(dict, xref, res, pdfFunctionFactory, localColorSpaceCache);
26349 case ShadingType.FREE_FORM_MESH:
26350 case ShadingType.LATTICE_FORM_MESH:
26351 case ShadingType.COONS_PATCH_MESH:
26352 case ShadingType.TENSOR_PATCH_MESH:
26353 return new MeshShading(shading, xref, res, pdfFunctionFactory, localColorSpaceCache);
26354 default:
26355 throw new FormatError("Unsupported ShadingType: " + type);
26356 }
26357 } catch (ex) {
26358 if (ex instanceof MissingDataException) {
26359 throw ex;
26360 }
26361 warn(ex);
26362 return new DummyShading();
26363 }
26364 }
26365}
26366class BaseShading {
26367 static SMALL_NUMBER = 1e-6;
26368 constructor() {
26369 if (this.constructor === BaseShading) {
26370 unreachable("Cannot initialize BaseShading.");
26371 }
26372 }
26373 getIR() {
26374 unreachable("Abstract method `getIR` called.");
26375 }
26376}
26377class RadialAxialShading extends BaseShading {
26378 constructor(dict, xref, resources, pdfFunctionFactory, localColorSpaceCache) {
26379 super();
26380 this.coordsArr = dict.getArray("Coords");
26381 this.shadingType = dict.get("ShadingType");
26382 const cs = ColorSpace.parse({
26383 cs: dict.getRaw("CS") || dict.getRaw("ColorSpace"),
26384 xref,
26385 resources,
26386 pdfFunctionFactory,
26387 localColorSpaceCache
26388 });
26389 const bbox = dict.getArray("BBox");
26390 this.bbox = Array.isArray(bbox) && bbox.length === 4 ? Util.normalizeRect(bbox) : null;
26391 let t0 = 0.0,
26392 t1 = 1.0;
26393 if (dict.has("Domain")) {
26394 const domainArr = dict.getArray("Domain");
26395 t0 = domainArr[0];
26396 t1 = domainArr[1];
26397 }
26398 let extendStart = false,
26399 extendEnd = false;
26400 if (dict.has("Extend")) {
26401 const extendArr = dict.getArray("Extend");
26402 extendStart = extendArr[0];
26403 extendEnd = extendArr[1];
26404 }
26405 if (this.shadingType === ShadingType.RADIAL && (!extendStart || !extendEnd)) {
26406 const [x1, y1, r1, x2, y2, r2] = this.coordsArr;
26407 const distance = Math.hypot(x1 - x2, y1 - y2);
26408 if (r1 <= r2 + distance && r2 <= r1 + distance) {
26409 warn("Unsupported radial gradient.");
26410 }
26411 }
26412 this.extendStart = extendStart;
26413 this.extendEnd = extendEnd;
26414 const fnObj = dict.getRaw("Function");
26415 const fn = pdfFunctionFactory.createFromArray(fnObj);
26416 const NUMBER_OF_SAMPLES = 840;
26417 const step = (t1 - t0) / NUMBER_OF_SAMPLES;
26418 const colorStops = this.colorStops = [];
26419 if (t0 >= t1 || step <= 0) {
26420 info("Bad shading domain.");
26421 return;
26422 }
26423 const color = new Float32Array(cs.numComps),
26424 ratio = new Float32Array(1);
26425 let rgbColor;
26426 let iBase = 0;
26427 ratio[0] = t0;
26428 fn(ratio, 0, color, 0);
26429 let rgbBase = cs.getRgb(color, 0);
26430 const cssColorBase = Util.makeHexColor(rgbBase[0], rgbBase[1], rgbBase[2]);
26431 colorStops.push([0, cssColorBase]);
26432 let iPrev = 1;
26433 ratio[0] = t0 + step;
26434 fn(ratio, 0, color, 0);
26435 let rgbPrev = cs.getRgb(color, 0);
26436 let maxSlopeR = rgbPrev[0] - rgbBase[0] + 1;
26437 let maxSlopeG = rgbPrev[1] - rgbBase[1] + 1;
26438 let maxSlopeB = rgbPrev[2] - rgbBase[2] + 1;
26439 let minSlopeR = rgbPrev[0] - rgbBase[0] - 1;
26440 let minSlopeG = rgbPrev[1] - rgbBase[1] - 1;
26441 let minSlopeB = rgbPrev[2] - rgbBase[2] - 1;
26442 for (let i = 2; i < NUMBER_OF_SAMPLES; i++) {
26443 ratio[0] = t0 + i * step;
26444 fn(ratio, 0, color, 0);
26445 rgbColor = cs.getRgb(color, 0);
26446 const run = i - iBase;
26447 maxSlopeR = Math.min(maxSlopeR, (rgbColor[0] - rgbBase[0] + 1) / run);
26448 maxSlopeG = Math.min(maxSlopeG, (rgbColor[1] - rgbBase[1] + 1) / run);
26449 maxSlopeB = Math.min(maxSlopeB, (rgbColor[2] - rgbBase[2] + 1) / run);
26450 minSlopeR = Math.max(minSlopeR, (rgbColor[0] - rgbBase[0] - 1) / run);
26451 minSlopeG = Math.max(minSlopeG, (rgbColor[1] - rgbBase[1] - 1) / run);
26452 minSlopeB = Math.max(minSlopeB, (rgbColor[2] - rgbBase[2] - 1) / run);
26453 const slopesExist = minSlopeR <= maxSlopeR && minSlopeG <= maxSlopeG && minSlopeB <= maxSlopeB;
26454 if (!slopesExist) {
26455 const cssColor = Util.makeHexColor(rgbPrev[0], rgbPrev[1], rgbPrev[2]);
26456 colorStops.push([iPrev / NUMBER_OF_SAMPLES, cssColor]);
26457 maxSlopeR = rgbColor[0] - rgbPrev[0] + 1;
26458 maxSlopeG = rgbColor[1] - rgbPrev[1] + 1;
26459 maxSlopeB = rgbColor[2] - rgbPrev[2] + 1;
26460 minSlopeR = rgbColor[0] - rgbPrev[0] - 1;
26461 minSlopeG = rgbColor[1] - rgbPrev[1] - 1;
26462 minSlopeB = rgbColor[2] - rgbPrev[2] - 1;
26463 iBase = iPrev;
26464 rgbBase = rgbPrev;
26465 }
26466 iPrev = i;
26467 rgbPrev = rgbColor;
26468 }
26469 const cssColor = Util.makeHexColor(rgbPrev[0], rgbPrev[1], rgbPrev[2]);
26470 colorStops.push([1, cssColor]);
26471 let background = "transparent";
26472 if (dict.has("Background")) {
26473 rgbColor = cs.getRgb(dict.get("Background"), 0);
26474 background = Util.makeHexColor(rgbColor[0], rgbColor[1], rgbColor[2]);
26475 }
26476 if (!extendStart) {
26477 colorStops.unshift([0, background]);
26478 colorStops[1][0] += BaseShading.SMALL_NUMBER;
26479 }
26480 if (!extendEnd) {
26481 colorStops.at(-1)[0] -= BaseShading.SMALL_NUMBER;
26482 colorStops.push([1, background]);
26483 }
26484 this.colorStops = colorStops;
26485 }
26486 getIR() {
26487 const coordsArr = this.coordsArr;
26488 const shadingType = this.shadingType;
26489 let type, p0, p1, r0, r1;
26490 if (shadingType === ShadingType.AXIAL) {
26491 p0 = [coordsArr[0], coordsArr[1]];
26492 p1 = [coordsArr[2], coordsArr[3]];
26493 r0 = null;
26494 r1 = null;
26495 type = "axial";
26496 } else if (shadingType === ShadingType.RADIAL) {
26497 p0 = [coordsArr[0], coordsArr[1]];
26498 p1 = [coordsArr[3], coordsArr[4]];
26499 r0 = coordsArr[2];
26500 r1 = coordsArr[5];
26501 type = "radial";
26502 } else {
26503 unreachable(`getPattern type unknown: ${shadingType}`);
26504 }
26505 return ["RadialAxial", type, this.bbox, this.colorStops, p0, p1, r0, r1];
26506 }
26507}
26508class MeshStreamReader {
26509 constructor(stream, context) {
26510 this.stream = stream;
26511 this.context = context;
26512 this.buffer = 0;
26513 this.bufferLength = 0;
26514 const numComps = context.numComps;
26515 this.tmpCompsBuf = new Float32Array(numComps);
26516 const csNumComps = context.colorSpace.numComps;
26517 this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) : this.tmpCompsBuf;
26518 }
26519 get hasData() {
26520 if (this.stream.end) {
26521 return this.stream.pos < this.stream.end;
26522 }
26523 if (this.bufferLength > 0) {
26524 return true;
26525 }
26526 const nextByte = this.stream.getByte();
26527 if (nextByte < 0) {
26528 return false;
26529 }
26530 this.buffer = nextByte;
26531 this.bufferLength = 8;
26532 return true;
26533 }
26534 readBits(n) {
26535 let buffer = this.buffer;
26536 let bufferLength = this.bufferLength;
26537 if (n === 32) {
26538 if (bufferLength === 0) {
26539 return (this.stream.getByte() << 24 | this.stream.getByte() << 16 | this.stream.getByte() << 8 | this.stream.getByte()) >>> 0;
26540 }
26541 buffer = buffer << 24 | this.stream.getByte() << 16 | this.stream.getByte() << 8 | this.stream.getByte();
26542 const nextByte = this.stream.getByte();
26543 this.buffer = nextByte & (1 << bufferLength) - 1;
26544 return (buffer << 8 - bufferLength | (nextByte & 0xff) >> bufferLength) >>> 0;
26545 }
26546 if (n === 8 && bufferLength === 0) {
26547 return this.stream.getByte();
26548 }
26549 while (bufferLength < n) {
26550 buffer = buffer << 8 | this.stream.getByte();
26551 bufferLength += 8;
26552 }
26553 bufferLength -= n;
26554 this.bufferLength = bufferLength;
26555 this.buffer = buffer & (1 << bufferLength) - 1;
26556 return buffer >> bufferLength;
26557 }
26558 align() {
26559 this.buffer = 0;
26560 this.bufferLength = 0;
26561 }
26562 readFlag() {
26563 return this.readBits(this.context.bitsPerFlag);
26564 }
26565 readCoordinate() {
26566 const bitsPerCoordinate = this.context.bitsPerCoordinate;
26567 const xi = this.readBits(bitsPerCoordinate);
26568 const yi = this.readBits(bitsPerCoordinate);
26569 const decode = this.context.decode;
26570 const scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) : 2.3283064365386963e-10;
26571 return [xi * scale * (decode[1] - decode[0]) + decode[0], yi * scale * (decode[3] - decode[2]) + decode[2]];
26572 }
26573 readComponents() {
26574 const numComps = this.context.numComps;
26575 const bitsPerComponent = this.context.bitsPerComponent;
26576 const scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) : 2.3283064365386963e-10;
26577 const decode = this.context.decode;
26578 const components = this.tmpCompsBuf;
26579 for (let i = 0, j = 4; i < numComps; i++, j += 2) {
26580 const ci = this.readBits(bitsPerComponent);
26581 components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
26582 }
26583 const color = this.tmpCsCompsBuf;
26584 if (this.context.colorFn) {
26585 this.context.colorFn(components, 0, color, 0);
26586 }
26587 return this.context.colorSpace.getRgb(color, 0);
26588 }
26589}
26590let bCache = Object.create(null);
26591function buildB(count) {
26592 const lut = [];
26593 for (let i = 0; i <= count; i++) {
26594 const t = i / count,
26595 t_ = 1 - t;
26596 lut.push(new Float32Array([t_ ** 3, 3 * t * t_ ** 2, 3 * t ** 2 * t_, t ** 3]));
26597 }
26598 return lut;
26599}
26600function getB(count) {
26601 return bCache[count] ||= buildB(count);
26602}
26603function clearPatternCaches() {
26604 bCache = Object.create(null);
26605}
26606class MeshShading extends BaseShading {
26607 static MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
26608 static MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
26609 static TRIANGLE_DENSITY = 20;
26610 constructor(stream, xref, resources, pdfFunctionFactory, localColorSpaceCache) {
26611 super();
26612 if (!(stream instanceof BaseStream)) {
26613 throw new FormatError("Mesh data is not a stream");
26614 }
26615 const dict = stream.dict;
26616 this.shadingType = dict.get("ShadingType");
26617 const bbox = dict.getArray("BBox");
26618 this.bbox = Array.isArray(bbox) && bbox.length === 4 ? Util.normalizeRect(bbox) : null;
26619 const cs = ColorSpace.parse({
26620 cs: dict.getRaw("CS") || dict.getRaw("ColorSpace"),
26621 xref,
26622 resources,
26623 pdfFunctionFactory,
26624 localColorSpaceCache
26625 });
26626 this.background = dict.has("Background") ? cs.getRgb(dict.get("Background"), 0) : null;
26627 const fnObj = dict.getRaw("Function");
26628 const fn = fnObj ? pdfFunctionFactory.createFromArray(fnObj) : null;
26629 this.coords = [];
26630 this.colors = [];
26631 this.figures = [];
26632 const decodeContext = {
26633 bitsPerCoordinate: dict.get("BitsPerCoordinate"),
26634 bitsPerComponent: dict.get("BitsPerComponent"),
26635 bitsPerFlag: dict.get("BitsPerFlag"),
26636 decode: dict.getArray("Decode"),
26637 colorFn: fn,
26638 colorSpace: cs,
26639 numComps: fn ? 1 : cs.numComps
26640 };
26641 const reader = new MeshStreamReader(stream, decodeContext);
26642 let patchMesh = false;
26643 switch (this.shadingType) {
26644 case ShadingType.FREE_FORM_MESH:
26645 this._decodeType4Shading(reader);
26646 break;
26647 case ShadingType.LATTICE_FORM_MESH:
26648 const verticesPerRow = dict.get("VerticesPerRow") | 0;
26649 if (verticesPerRow < 2) {
26650 throw new FormatError("Invalid VerticesPerRow");
26651 }
26652 this._decodeType5Shading(reader, verticesPerRow);
26653 break;
26654 case ShadingType.COONS_PATCH_MESH:
26655 this._decodeType6Shading(reader);
26656 patchMesh = true;
26657 break;
26658 case ShadingType.TENSOR_PATCH_MESH:
26659 this._decodeType7Shading(reader);
26660 patchMesh = true;
26661 break;
26662 default:
26663 unreachable("Unsupported mesh type.");
26664 break;
26665 }
26666 if (patchMesh) {
26667 this._updateBounds();
26668 for (let i = 0, ii = this.figures.length; i < ii; i++) {
26669 this._buildFigureFromPatch(i);
26670 }
26671 }
26672 this._updateBounds();
26673 this._packData();
26674 }
26675 _decodeType4Shading(reader) {
26676 const coords = this.coords;
26677 const colors = this.colors;
26678 const operators = [];
26679 const ps = [];
26680 let verticesLeft = 0;
26681 while (reader.hasData) {
26682 const f = reader.readFlag();
26683 const coord = reader.readCoordinate();
26684 const color = reader.readComponents();
26685 if (verticesLeft === 0) {
26686 if (!(0 <= f && f <= 2)) {
26687 throw new FormatError("Unknown type4 flag");
26688 }
26689 switch (f) {
26690 case 0:
26691 verticesLeft = 3;
26692 break;
26693 case 1:
26694 ps.push(ps.at(-2), ps.at(-1));
26695 verticesLeft = 1;
26696 break;
26697 case 2:
26698 ps.push(ps.at(-3), ps.at(-1));
26699 verticesLeft = 1;
26700 break;
26701 }
26702 operators.push(f);
26703 }
26704 ps.push(coords.length);
26705 coords.push(coord);
26706 colors.push(color);
26707 verticesLeft--;
26708 reader.align();
26709 }
26710 this.figures.push({
26711 type: "triangles",
26712 coords: new Int32Array(ps),
26713 colors: new Int32Array(ps)
26714 });
26715 }
26716 _decodeType5Shading(reader, verticesPerRow) {
26717 const coords = this.coords;
26718 const colors = this.colors;
26719 const ps = [];
26720 while (reader.hasData) {
26721 const coord = reader.readCoordinate();
26722 const color = reader.readComponents();
26723 ps.push(coords.length);
26724 coords.push(coord);
26725 colors.push(color);
26726 }
26727 this.figures.push({
26728 type: "lattice",
26729 coords: new Int32Array(ps),
26730 colors: new Int32Array(ps),
26731 verticesPerRow
26732 });
26733 }
26734 _decodeType6Shading(reader) {
26735 const coords = this.coords;
26736 const colors = this.colors;
26737 const ps = new Int32Array(16);
26738 const cs = new Int32Array(4);
26739 while (reader.hasData) {
26740 const f = reader.readFlag();
26741 if (!(0 <= f && f <= 3)) {
26742 throw new FormatError("Unknown type6 flag");
26743 }
26744 const pi = coords.length;
26745 for (let i = 0, ii = f !== 0 ? 8 : 12; i < ii; i++) {
26746 coords.push(reader.readCoordinate());
26747 }
26748 const ci = colors.length;
26749 for (let i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) {
26750 colors.push(reader.readComponents());
26751 }
26752 let tmp1, tmp2, tmp3, tmp4;
26753 switch (f) {
26754 case 0:
26755 ps[12] = pi + 3;
26756 ps[13] = pi + 4;
26757 ps[14] = pi + 5;
26758 ps[15] = pi + 6;
26759 ps[8] = pi + 2;
26760 ps[11] = pi + 7;
26761 ps[4] = pi + 1;
26762 ps[7] = pi + 8;
26763 ps[0] = pi;
26764 ps[1] = pi + 11;
26765 ps[2] = pi + 10;
26766 ps[3] = pi + 9;
26767 cs[2] = ci + 1;
26768 cs[3] = ci + 2;
26769 cs[0] = ci;
26770 cs[1] = ci + 3;
26771 break;
26772 case 1:
26773 tmp1 = ps[12];
26774 tmp2 = ps[13];
26775 tmp3 = ps[14];
26776 tmp4 = ps[15];
26777 ps[12] = tmp4;
26778 ps[13] = pi + 0;
26779 ps[14] = pi + 1;
26780 ps[15] = pi + 2;
26781 ps[8] = tmp3;
26782 ps[11] = pi + 3;
26783 ps[4] = tmp2;
26784 ps[7] = pi + 4;
26785 ps[0] = tmp1;
26786 ps[1] = pi + 7;
26787 ps[2] = pi + 6;
26788 ps[3] = pi + 5;
26789 tmp1 = cs[2];
26790 tmp2 = cs[3];
26791 cs[2] = tmp2;
26792 cs[3] = ci;
26793 cs[0] = tmp1;
26794 cs[1] = ci + 1;
26795 break;
26796 case 2:
26797 tmp1 = ps[15];
26798 tmp2 = ps[11];
26799 ps[12] = ps[3];
26800 ps[13] = pi + 0;
26801 ps[14] = pi + 1;
26802 ps[15] = pi + 2;
26803 ps[8] = ps[7];
26804 ps[11] = pi + 3;
26805 ps[4] = tmp2;
26806 ps[7] = pi + 4;
26807 ps[0] = tmp1;
26808 ps[1] = pi + 7;
26809 ps[2] = pi + 6;
26810 ps[3] = pi + 5;
26811 tmp1 = cs[3];
26812 cs[2] = cs[1];
26813 cs[3] = ci;
26814 cs[0] = tmp1;
26815 cs[1] = ci + 1;
26816 break;
26817 case 3:
26818 ps[12] = ps[0];
26819 ps[13] = pi + 0;
26820 ps[14] = pi + 1;
26821 ps[15] = pi + 2;
26822 ps[8] = ps[1];
26823 ps[11] = pi + 3;
26824 ps[4] = ps[2];
26825 ps[7] = pi + 4;
26826 ps[0] = ps[3];
26827 ps[1] = pi + 7;
26828 ps[2] = pi + 6;
26829 ps[3] = pi + 5;
26830 cs[2] = cs[0];
26831 cs[3] = ci;
26832 cs[0] = cs[1];
26833 cs[1] = ci + 1;
26834 break;
26835 }
26836 ps[5] = coords.length;
26837 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]);
26838 ps[6] = coords.length;
26839 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]);
26840 ps[9] = coords.length;
26841 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]);
26842 ps[10] = coords.length;
26843 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]);
26844 this.figures.push({
26845 type: "patch",
26846 coords: new Int32Array(ps),
26847 colors: new Int32Array(cs)
26848 });
26849 }
26850 }
26851 _decodeType7Shading(reader) {
26852 const coords = this.coords;
26853 const colors = this.colors;
26854 const ps = new Int32Array(16);
26855 const cs = new Int32Array(4);
26856 while (reader.hasData) {
26857 const f = reader.readFlag();
26858 if (!(0 <= f && f <= 3)) {
26859 throw new FormatError("Unknown type7 flag");
26860 }
26861 const pi = coords.length;
26862 for (let i = 0, ii = f !== 0 ? 12 : 16; i < ii; i++) {
26863 coords.push(reader.readCoordinate());
26864 }
26865 const ci = colors.length;
26866 for (let i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) {
26867 colors.push(reader.readComponents());
26868 }
26869 let tmp1, tmp2, tmp3, tmp4;
26870 switch (f) {
26871 case 0:
26872 ps[12] = pi + 3;
26873 ps[13] = pi + 4;
26874 ps[14] = pi + 5;
26875 ps[15] = pi + 6;
26876 ps[8] = pi + 2;
26877 ps[9] = pi + 13;
26878 ps[10] = pi + 14;
26879 ps[11] = pi + 7;
26880 ps[4] = pi + 1;
26881 ps[5] = pi + 12;
26882 ps[6] = pi + 15;
26883 ps[7] = pi + 8;
26884 ps[0] = pi;
26885 ps[1] = pi + 11;
26886 ps[2] = pi + 10;
26887 ps[3] = pi + 9;
26888 cs[2] = ci + 1;
26889 cs[3] = ci + 2;
26890 cs[0] = ci;
26891 cs[1] = ci + 3;
26892 break;
26893 case 1:
26894 tmp1 = ps[12];
26895 tmp2 = ps[13];
26896 tmp3 = ps[14];
26897 tmp4 = ps[15];
26898 ps[12] = tmp4;
26899 ps[13] = pi + 0;
26900 ps[14] = pi + 1;
26901 ps[15] = pi + 2;
26902 ps[8] = tmp3;
26903 ps[9] = pi + 9;
26904 ps[10] = pi + 10;
26905 ps[11] = pi + 3;
26906 ps[4] = tmp2;
26907 ps[5] = pi + 8;
26908 ps[6] = pi + 11;
26909 ps[7] = pi + 4;
26910 ps[0] = tmp1;
26911 ps[1] = pi + 7;
26912 ps[2] = pi + 6;
26913 ps[3] = pi + 5;
26914 tmp1 = cs[2];
26915 tmp2 = cs[3];
26916 cs[2] = tmp2;
26917 cs[3] = ci;
26918 cs[0] = tmp1;
26919 cs[1] = ci + 1;
26920 break;
26921 case 2:
26922 tmp1 = ps[15];
26923 tmp2 = ps[11];
26924 ps[12] = ps[3];
26925 ps[13] = pi + 0;
26926 ps[14] = pi + 1;
26927 ps[15] = pi + 2;
26928 ps[8] = ps[7];
26929 ps[9] = pi + 9;
26930 ps[10] = pi + 10;
26931 ps[11] = pi + 3;
26932 ps[4] = tmp2;
26933 ps[5] = pi + 8;
26934 ps[6] = pi + 11;
26935 ps[7] = pi + 4;
26936 ps[0] = tmp1;
26937 ps[1] = pi + 7;
26938 ps[2] = pi + 6;
26939 ps[3] = pi + 5;
26940 tmp1 = cs[3];
26941 cs[2] = cs[1];
26942 cs[3] = ci;
26943 cs[0] = tmp1;
26944 cs[1] = ci + 1;
26945 break;
26946 case 3:
26947 ps[12] = ps[0];
26948 ps[13] = pi + 0;
26949 ps[14] = pi + 1;
26950 ps[15] = pi + 2;
26951 ps[8] = ps[1];
26952 ps[9] = pi + 9;
26953 ps[10] = pi + 10;
26954 ps[11] = pi + 3;
26955 ps[4] = ps[2];
26956 ps[5] = pi + 8;
26957 ps[6] = pi + 11;
26958 ps[7] = pi + 4;
26959 ps[0] = ps[3];
26960 ps[1] = pi + 7;
26961 ps[2] = pi + 6;
26962 ps[3] = pi + 5;
26963 cs[2] = cs[0];
26964 cs[3] = ci;
26965 cs[0] = cs[1];
26966 cs[1] = ci + 1;
26967 break;
26968 }
26969 this.figures.push({
26970 type: "patch",
26971 coords: new Int32Array(ps),
26972 colors: new Int32Array(cs)
26973 });
26974 }
26975 }
26976 _buildFigureFromPatch(index) {
26977 const figure = this.figures[index];
26978 assert(figure.type === "patch", "Unexpected patch mesh figure");
26979 const coords = this.coords,
26980 colors = this.colors;
26981 const pi = figure.coords;
26982 const ci = figure.colors;
26983 const figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0], coords[pi[12]][0], coords[pi[15]][0]);
26984 const figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1], coords[pi[12]][1], coords[pi[15]][1]);
26985 const figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0], coords[pi[12]][0], coords[pi[15]][0]);
26986 const figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1], coords[pi[12]][1], coords[pi[15]][1]);
26987 let splitXBy = Math.ceil((figureMaxX - figureMinX) * MeshShading.TRIANGLE_DENSITY / (this.bounds[2] - this.bounds[0]));
26988 splitXBy = Math.max(MeshShading.MIN_SPLIT_PATCH_CHUNKS_AMOUNT, Math.min(MeshShading.MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
26989 let splitYBy = Math.ceil((figureMaxY - figureMinY) * MeshShading.TRIANGLE_DENSITY / (this.bounds[3] - this.bounds[1]));
26990 splitYBy = Math.max(MeshShading.MIN_SPLIT_PATCH_CHUNKS_AMOUNT, Math.min(MeshShading.MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
26991 const verticesPerRow = splitXBy + 1;
26992 const figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
26993 const figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
26994 let k = 0;
26995 const cl = new Uint8Array(3),
26996 cr = new Uint8Array(3);
26997 const c0 = colors[ci[0]],
26998 c1 = colors[ci[1]],
26999 c2 = colors[ci[2]],
27000 c3 = colors[ci[3]];
27001 const bRow = getB(splitYBy),
27002 bCol = getB(splitXBy);
27003 for (let row = 0; row <= splitYBy; row++) {
27004 cl[0] = (c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy | 0;
27005 cl[1] = (c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy | 0;
27006 cl[2] = (c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy | 0;
27007 cr[0] = (c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy | 0;
27008 cr[1] = (c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy | 0;
27009 cr[2] = (c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy | 0;
27010 for (let col = 0; col <= splitXBy; col++, k++) {
27011 if ((row === 0 || row === splitYBy) && (col === 0 || col === splitXBy)) {
27012 continue;
27013 }
27014 let x = 0,
27015 y = 0;
27016 let q = 0;
27017 for (let i = 0; i <= 3; i++) {
27018 for (let j = 0; j <= 3; j++, q++) {
27019 const m = bRow[row][i] * bCol[col][j];
27020 x += coords[pi[q]][0] * m;
27021 y += coords[pi[q]][1] * m;
27022 }
27023 }
27024 figureCoords[k] = coords.length;
27025 coords.push([x, y]);
27026 figureColors[k] = colors.length;
27027 const newColor = new Uint8Array(3);
27028 newColor[0] = (cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy | 0;
27029 newColor[1] = (cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy | 0;
27030 newColor[2] = (cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy | 0;
27031 colors.push(newColor);
27032 }
27033 }
27034 figureCoords[0] = pi[0];
27035 figureColors[0] = ci[0];
27036 figureCoords[splitXBy] = pi[3];
27037 figureColors[splitXBy] = ci[1];
27038 figureCoords[verticesPerRow * splitYBy] = pi[12];
27039 figureColors[verticesPerRow * splitYBy] = ci[2];
27040 figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
27041 figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
27042 this.figures[index] = {
27043 type: "lattice",
27044 coords: figureCoords,
27045 colors: figureColors,
27046 verticesPerRow
27047 };
27048 }
27049 _updateBounds() {
27050 let minX = this.coords[0][0],
27051 minY = this.coords[0][1],
27052 maxX = minX,
27053 maxY = minY;
27054 for (let i = 1, ii = this.coords.length; i < ii; i++) {
27055 const x = this.coords[i][0],
27056 y = this.coords[i][1];
27057 minX = minX > x ? x : minX;
27058 minY = minY > y ? y : minY;
27059 maxX = maxX < x ? x : maxX;
27060 maxY = maxY < y ? y : maxY;
27061 }
27062 this.bounds = [minX, minY, maxX, maxY];
27063 }
27064 _packData() {
27065 let i, ii, j, jj;
27066 const coords = this.coords;
27067 const coordsPacked = new Float32Array(coords.length * 2);
27068 for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
27069 const xy = coords[i];
27070 coordsPacked[j++] = xy[0];
27071 coordsPacked[j++] = xy[1];
27072 }
27073 this.coords = coordsPacked;
27074 const colors = this.colors;
27075 const colorsPacked = new Uint8Array(colors.length * 3);
27076 for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
27077 const c = colors[i];
27078 colorsPacked[j++] = c[0];
27079 colorsPacked[j++] = c[1];
27080 colorsPacked[j++] = c[2];
27081 }
27082 this.colors = colorsPacked;
27083 const figures = this.figures;
27084 for (i = 0, ii = figures.length; i < ii; i++) {
27085 const figure = figures[i],
27086 ps = figure.coords,
27087 cs = figure.colors;
27088 for (j = 0, jj = ps.length; j < jj; j++) {
27089 ps[j] *= 2;
27090 cs[j] *= 3;
27091 }
27092 }
27093 }
27094 getIR() {
27095 const {
27096 bounds
27097 } = this;
27098 if (bounds[2] - bounds[0] === 0 || bounds[3] - bounds[1] === 0) {
27099 throw new FormatError(`Invalid MeshShading bounds: [${bounds}].`);
27100 }
27101 return ["Mesh", this.shadingType, this.coords, this.colors, this.figures, bounds, this.bbox, this.background];
27102 }
27103}
27104class DummyShading extends BaseShading {
27105 getIR() {
27106 return ["Dummy"];
27107 }
27108}
27109function getTilingPatternIR(operatorList, dict, color) {
27110 const matrix = dict.getArray("Matrix");
27111 const bbox = Util.normalizeRect(dict.getArray("BBox"));
27112 const xstep = dict.get("XStep");
27113 const ystep = dict.get("YStep");
27114 const paintType = dict.get("PaintType");
27115 const tilingType = dict.get("TilingType");
27116 if (bbox[2] - bbox[0] === 0 || bbox[3] - bbox[1] === 0) {
27117 throw new FormatError(`Invalid getTilingPatternIR /BBox array: [${bbox}].`);
27118 }
27119 return ["TilingPattern", color, operatorList, matrix, bbox, xstep, ystep, paintType, tilingType];
27120}
27121
27122;// CONCATENATED MODULE: ./src/core/calibri_factors.js
27123const 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, 0.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];
27124const CalibriBoldMetrics = {
27125 lineHeight: 1.2207,
27126 lineGap: 0.2207
27127};
27128const 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, 0.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.77312, 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];
27129const CalibriBoldItalicMetrics = {
27130 lineHeight: 1.2207,
27131 lineGap: 0.2207
27132};
27133const 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, 0.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.0176, 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];
27134const CalibriItalicMetrics = {
27135 lineHeight: 1.2207,
27136 lineGap: 0.2207
27137};
27138const 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, 0.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.0176, 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];
27139const CalibriRegularMetrics = {
27140 lineHeight: 1.2207,
27141 lineGap: 0.2207
27142};
27143
27144;// CONCATENATED MODULE: ./src/core/helvetica_factors.js
27145const 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];
27146const HelveticaBoldMetrics = {
27147 lineHeight: 1.2,
27148 lineGap: 0.2
27149};
27150const 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];
27151const HelveticaBoldItalicMetrics = {
27152 lineHeight: 1.35,
27153 lineGap: 0.2
27154};
27155const 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];
27156const HelveticaItalicMetrics = {
27157 lineHeight: 1.35,
27158 lineGap: 0.2
27159};
27160const 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];
27161const HelveticaRegularMetrics = {
27162 lineHeight: 1.2,
27163 lineGap: 0.2
27164};
27165
27166;// CONCATENATED MODULE: ./src/core/liberationsans_widths.js
27167const 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];
27168const 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];
27169const 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];
27170const 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];
27171const 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];
27172const 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];
27173const 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];
27174const 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];
27175
27176;// CONCATENATED MODULE: ./src/core/myriadpro_factors.js
27177const 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];
27178const MyriadProBoldMetrics = {
27179 lineHeight: 1.2,
27180 lineGap: 0.2
27181};
27182const 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.98621, 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.91677, 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];
27183const MyriadProBoldItalicMetrics = {
27184 lineHeight: 1.2,
27185 lineGap: 0.2
27186};
27187const 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];
27188const MyriadProItalicMetrics = {
27189 lineHeight: 1.2,
27190 lineGap: 0.2
27191};
27192const 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];
27193const MyriadProRegularMetrics = {
27194 lineHeight: 1.2,
27195 lineGap: 0.2
27196};
27197
27198;// CONCATENATED MODULE: ./src/core/segoeui_factors.js
27199const 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];
27200const SegoeuiBoldMetrics = {
27201 lineHeight: 1.33008,
27202 lineGap: 0
27203};
27204const 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];
27205const SegoeuiBoldItalicMetrics = {
27206 lineHeight: 1.33008,
27207 lineGap: 0
27208};
27209const 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];
27210const SegoeuiItalicMetrics = {
27211 lineHeight: 1.33008,
27212 lineGap: 0
27213};
27214const 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];
27215const SegoeuiRegularMetrics = {
27216 lineHeight: 1.33008,
27217 lineGap: 0
27218};
27219
27220;// CONCATENATED MODULE: ./src/core/xfa_fonts.js
27221
27222
27223
27224
27225
27226
27227
27228
27229const getXFAFontMap = getLookupTableFactory(function (t) {
27230 t["MyriadPro-Regular"] = t["PdfJS-Fallback-Regular"] = {
27231 name: "LiberationSans-Regular",
27232 factors: MyriadProRegularFactors,
27233 baseWidths: LiberationSansRegularWidths,
27234 baseMapping: LiberationSansRegularMapping,
27235 metrics: MyriadProRegularMetrics
27236 };
27237 t["MyriadPro-Bold"] = t["PdfJS-Fallback-Bold"] = {
27238 name: "LiberationSans-Bold",
27239 factors: MyriadProBoldFactors,
27240 baseWidths: LiberationSansBoldWidths,
27241 baseMapping: LiberationSansBoldMapping,
27242 metrics: MyriadProBoldMetrics
27243 };
27244 t["MyriadPro-It"] = t["MyriadPro-Italic"] = t["PdfJS-Fallback-Italic"] = {
27245 name: "LiberationSans-Italic",
27246 factors: MyriadProItalicFactors,
27247 baseWidths: LiberationSansItalicWidths,
27248 baseMapping: LiberationSansItalicMapping,
27249 metrics: MyriadProItalicMetrics
27250 };
27251 t["MyriadPro-BoldIt"] = t["MyriadPro-BoldItalic"] = t["PdfJS-Fallback-BoldItalic"] = {
27252 name: "LiberationSans-BoldItalic",
27253 factors: MyriadProBoldItalicFactors,
27254 baseWidths: LiberationSansBoldItalicWidths,
27255 baseMapping: LiberationSansBoldItalicMapping,
27256 metrics: MyriadProBoldItalicMetrics
27257 };
27258 t.ArialMT = t.Arial = t["Arial-Regular"] = {
27259 name: "LiberationSans-Regular",
27260 baseWidths: LiberationSansRegularWidths,
27261 baseMapping: LiberationSansRegularMapping
27262 };
27263 t["Arial-BoldMT"] = t["Arial-Bold"] = {
27264 name: "LiberationSans-Bold",
27265 baseWidths: LiberationSansBoldWidths,
27266 baseMapping: LiberationSansBoldMapping
27267 };
27268 t["Arial-ItalicMT"] = t["Arial-Italic"] = {
27269 name: "LiberationSans-Italic",
27270 baseWidths: LiberationSansItalicWidths,
27271 baseMapping: LiberationSansItalicMapping
27272 };
27273 t["Arial-BoldItalicMT"] = t["Arial-BoldItalic"] = {
27274 name: "LiberationSans-BoldItalic",
27275 baseWidths: LiberationSansBoldItalicWidths,
27276 baseMapping: LiberationSansBoldItalicMapping
27277 };
27278 t["Calibri-Regular"] = {
27279 name: "LiberationSans-Regular",
27280 factors: CalibriRegularFactors,
27281 baseWidths: LiberationSansRegularWidths,
27282 baseMapping: LiberationSansRegularMapping,
27283 metrics: CalibriRegularMetrics
27284 };
27285 t["Calibri-Bold"] = {
27286 name: "LiberationSans-Bold",
27287 factors: CalibriBoldFactors,
27288 baseWidths: LiberationSansBoldWidths,
27289 baseMapping: LiberationSansBoldMapping,
27290 metrics: CalibriBoldMetrics
27291 };
27292 t["Calibri-Italic"] = {
27293 name: "LiberationSans-Italic",
27294 factors: CalibriItalicFactors,
27295 baseWidths: LiberationSansItalicWidths,
27296 baseMapping: LiberationSansItalicMapping,
27297 metrics: CalibriItalicMetrics
27298 };
27299 t["Calibri-BoldItalic"] = {
27300 name: "LiberationSans-BoldItalic",
27301 factors: CalibriBoldItalicFactors,
27302 baseWidths: LiberationSansBoldItalicWidths,
27303 baseMapping: LiberationSansBoldItalicMapping,
27304 metrics: CalibriBoldItalicMetrics
27305 };
27306 t["Segoeui-Regular"] = {
27307 name: "LiberationSans-Regular",
27308 factors: SegoeuiRegularFactors,
27309 baseWidths: LiberationSansRegularWidths,
27310 baseMapping: LiberationSansRegularMapping,
27311 metrics: SegoeuiRegularMetrics
27312 };
27313 t["Segoeui-Bold"] = {
27314 name: "LiberationSans-Bold",
27315 factors: SegoeuiBoldFactors,
27316 baseWidths: LiberationSansBoldWidths,
27317 baseMapping: LiberationSansBoldMapping,
27318 metrics: SegoeuiBoldMetrics
27319 };
27320 t["Segoeui-Italic"] = {
27321 name: "LiberationSans-Italic",
27322 factors: SegoeuiItalicFactors,
27323 baseWidths: LiberationSansItalicWidths,
27324 baseMapping: LiberationSansItalicMapping,
27325 metrics: SegoeuiItalicMetrics
27326 };
27327 t["Segoeui-BoldItalic"] = {
27328 name: "LiberationSans-BoldItalic",
27329 factors: SegoeuiBoldItalicFactors,
27330 baseWidths: LiberationSansBoldItalicWidths,
27331 baseMapping: LiberationSansBoldItalicMapping,
27332 metrics: SegoeuiBoldItalicMetrics
27333 };
27334 t["Helvetica-Regular"] = t.Helvetica = {
27335 name: "LiberationSans-Regular",
27336 factors: HelveticaRegularFactors,
27337 baseWidths: LiberationSansRegularWidths,
27338 baseMapping: LiberationSansRegularMapping,
27339 metrics: HelveticaRegularMetrics
27340 };
27341 t["Helvetica-Bold"] = {
27342 name: "LiberationSans-Bold",
27343 factors: HelveticaBoldFactors,
27344 baseWidths: LiberationSansBoldWidths,
27345 baseMapping: LiberationSansBoldMapping,
27346 metrics: HelveticaBoldMetrics
27347 };
27348 t["Helvetica-Italic"] = {
27349 name: "LiberationSans-Italic",
27350 factors: HelveticaItalicFactors,
27351 baseWidths: LiberationSansItalicWidths,
27352 baseMapping: LiberationSansItalicMapping,
27353 metrics: HelveticaItalicMetrics
27354 };
27355 t["Helvetica-BoldItalic"] = {
27356 name: "LiberationSans-BoldItalic",
27357 factors: HelveticaBoldItalicFactors,
27358 baseWidths: LiberationSansBoldItalicWidths,
27359 baseMapping: LiberationSansBoldItalicMapping,
27360 metrics: HelveticaBoldItalicMetrics
27361 };
27362});
27363function getXfaFontName(name) {
27364 const fontName = normalizeFontName(name);
27365 const fontMap = getXFAFontMap();
27366 return fontMap[fontName];
27367}
27368function getXfaFontWidths(name) {
27369 const info = getXfaFontName(name);
27370 if (!info) {
27371 return null;
27372 }
27373 const {
27374 baseWidths,
27375 baseMapping,
27376 factors
27377 } = info;
27378 const rescaledBaseWidths = !factors ? baseWidths : baseWidths.map((w, i) => w * factors[i]);
27379 let currentCode = -2;
27380 let currentArray;
27381 const newWidths = [];
27382 for (const [unicode, glyphIndex] of baseMapping.map((charUnicode, index) => [charUnicode, index]).sort(([unicode1], [unicode2]) => unicode1 - unicode2)) {
27383 if (unicode === -1) {
27384 continue;
27385 }
27386 if (unicode === currentCode + 1) {
27387 currentArray.push(rescaledBaseWidths[glyphIndex]);
27388 currentCode += 1;
27389 } else {
27390 currentCode = unicode;
27391 currentArray = [rescaledBaseWidths[glyphIndex]];
27392 newWidths.push(unicode, currentArray);
27393 }
27394 }
27395 return newWidths;
27396}
27397function getXfaFontDict(name) {
27398 const widths = getXfaFontWidths(name);
27399 const dict = new Dict(null);
27400 dict.set("BaseFont", Name.get(name));
27401 dict.set("Type", Name.get("Font"));
27402 dict.set("Subtype", Name.get("CIDFontType2"));
27403 dict.set("Encoding", Name.get("Identity-H"));
27404 dict.set("CIDToGIDMap", Name.get("Identity"));
27405 dict.set("W", widths);
27406 dict.set("FirstChar", widths[0]);
27407 dict.set("LastChar", widths.at(-2) + widths.at(-1).length - 1);
27408 const descriptor = new Dict(null);
27409 dict.set("FontDescriptor", descriptor);
27410 const systemInfo = new Dict(null);
27411 systemInfo.set("Ordering", "Identity");
27412 systemInfo.set("Registry", "Adobe");
27413 systemInfo.set("Supplement", 0);
27414 dict.set("CIDSystemInfo", systemInfo);
27415 return dict;
27416}
27417
27418;// CONCATENATED MODULE: ./src/core/ps_parser.js
27419
27420
27421
27422class PostScriptParser {
27423 constructor(lexer) {
27424 this.lexer = lexer;
27425 this.operators = [];
27426 this.token = null;
27427 this.prev = null;
27428 }
27429 nextToken() {
27430 this.prev = this.token;
27431 this.token = this.lexer.getToken();
27432 }
27433 accept(type) {
27434 if (this.token.type === type) {
27435 this.nextToken();
27436 return true;
27437 }
27438 return false;
27439 }
27440 expect(type) {
27441 if (this.accept(type)) {
27442 return true;
27443 }
27444 throw new FormatError(`Unexpected symbol: found ${this.token.type} expected ${type}.`);
27445 }
27446 parse() {
27447 this.nextToken();
27448 this.expect(PostScriptTokenTypes.LBRACE);
27449 this.parseBlock();
27450 this.expect(PostScriptTokenTypes.RBRACE);
27451 return this.operators;
27452 }
27453 parseBlock() {
27454 while (true) {
27455 if (this.accept(PostScriptTokenTypes.NUMBER)) {
27456 this.operators.push(this.prev.value);
27457 } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
27458 this.operators.push(this.prev.value);
27459 } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
27460 this.parseCondition();
27461 } else {
27462 return;
27463 }
27464 }
27465 }
27466 parseCondition() {
27467 const conditionLocation = this.operators.length;
27468 this.operators.push(null, null);
27469 this.parseBlock();
27470 this.expect(PostScriptTokenTypes.RBRACE);
27471 if (this.accept(PostScriptTokenTypes.IF)) {
27472 this.operators[conditionLocation] = this.operators.length;
27473 this.operators[conditionLocation + 1] = "jz";
27474 } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
27475 const jumpLocation = this.operators.length;
27476 this.operators.push(null, null);
27477 const endOfTrue = this.operators.length;
27478 this.parseBlock();
27479 this.expect(PostScriptTokenTypes.RBRACE);
27480 this.expect(PostScriptTokenTypes.IFELSE);
27481 this.operators[jumpLocation] = this.operators.length;
27482 this.operators[jumpLocation + 1] = "j";
27483 this.operators[conditionLocation] = endOfTrue;
27484 this.operators[conditionLocation + 1] = "jz";
27485 } else {
27486 throw new FormatError("PS Function: error parsing conditional.");
27487 }
27488 }
27489}
27490const PostScriptTokenTypes = {
27491 LBRACE: 0,
27492 RBRACE: 1,
27493 NUMBER: 2,
27494 OPERATOR: 3,
27495 IF: 4,
27496 IFELSE: 5
27497};
27498class PostScriptToken {
27499 static get opCache() {
27500 return shadow(this, "opCache", Object.create(null));
27501 }
27502 constructor(type, value) {
27503 this.type = type;
27504 this.value = value;
27505 }
27506 static getOperator(op) {
27507 return PostScriptToken.opCache[op] ||= new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
27508 }
27509 static get LBRACE() {
27510 return shadow(this, "LBRACE", new PostScriptToken(PostScriptTokenTypes.LBRACE, "{"));
27511 }
27512 static get RBRACE() {
27513 return shadow(this, "RBRACE", new PostScriptToken(PostScriptTokenTypes.RBRACE, "}"));
27514 }
27515 static get IF() {
27516 return shadow(this, "IF", new PostScriptToken(PostScriptTokenTypes.IF, "IF"));
27517 }
27518 static get IFELSE() {
27519 return shadow(this, "IFELSE", new PostScriptToken(PostScriptTokenTypes.IFELSE, "IFELSE"));
27520 }
27521}
27522class PostScriptLexer {
27523 constructor(stream) {
27524 this.stream = stream;
27525 this.nextChar();
27526 this.strBuf = [];
27527 }
27528 nextChar() {
27529 return this.currentChar = this.stream.getByte();
27530 }
27531 getToken() {
27532 let comment = false;
27533 let ch = this.currentChar;
27534 while (true) {
27535 if (ch < 0) {
27536 return EOF;
27537 }
27538 if (comment) {
27539 if (ch === 0x0a || ch === 0x0d) {
27540 comment = false;
27541 }
27542 } else if (ch === 0x25) {
27543 comment = true;
27544 } else if (!isWhiteSpace(ch)) {
27545 break;
27546 }
27547 ch = this.nextChar();
27548 }
27549 switch (ch | 0) {
27550 case 0x30:
27551 case 0x31:
27552 case 0x32:
27553 case 0x33:
27554 case 0x34:
27555 case 0x35:
27556 case 0x36:
27557 case 0x37:
27558 case 0x38:
27559 case 0x39:
27560 case 0x2b:
27561 case 0x2d:
27562 case 0x2e:
27563 return new PostScriptToken(PostScriptTokenTypes.NUMBER, this.getNumber());
27564 case 0x7b:
27565 this.nextChar();
27566 return PostScriptToken.LBRACE;
27567 case 0x7d:
27568 this.nextChar();
27569 return PostScriptToken.RBRACE;
27570 }
27571 const strBuf = this.strBuf;
27572 strBuf.length = 0;
27573 strBuf[0] = String.fromCharCode(ch);
27574 while ((ch = this.nextChar()) >= 0 && (ch >= 0x41 && ch <= 0x5a || ch >= 0x61 && ch <= 0x7a)) {
27575 strBuf.push(String.fromCharCode(ch));
27576 }
27577 const str = strBuf.join("");
27578 switch (str.toLowerCase()) {
27579 case "if":
27580 return PostScriptToken.IF;
27581 case "ifelse":
27582 return PostScriptToken.IFELSE;
27583 default:
27584 return PostScriptToken.getOperator(str);
27585 }
27586 }
27587 getNumber() {
27588 let ch = this.currentChar;
27589 const strBuf = this.strBuf;
27590 strBuf.length = 0;
27591 strBuf[0] = String.fromCharCode(ch);
27592 while ((ch = this.nextChar()) >= 0) {
27593 if (ch >= 0x30 && ch <= 0x39 || ch === 0x2d || ch === 0x2e) {
27594 strBuf.push(String.fromCharCode(ch));
27595 } else {
27596 break;
27597 }
27598 }
27599 const value = parseFloat(strBuf.join(""));
27600 if (isNaN(value)) {
27601 throw new FormatError(`Invalid floating point number: ${value}`);
27602 }
27603 return value;
27604 }
27605}
27606
27607;// CONCATENATED MODULE: ./src/core/image_utils.js
27608
27609
27610class BaseLocalCache {
27611 constructor(options) {
27612 if (this.constructor === BaseLocalCache) {
27613 unreachable("Cannot initialize BaseLocalCache.");
27614 }
27615 this._onlyRefs = options?.onlyRefs === true;
27616 if (!this._onlyRefs) {
27617 this._nameRefMap = new Map();
27618 this._imageMap = new Map();
27619 }
27620 this._imageCache = new RefSetCache();
27621 }
27622 getByName(name) {
27623 if (this._onlyRefs) {
27624 unreachable("Should not call `getByName` method.");
27625 }
27626 const ref = this._nameRefMap.get(name);
27627 if (ref) {
27628 return this.getByRef(ref);
27629 }
27630 return this._imageMap.get(name) || null;
27631 }
27632 getByRef(ref) {
27633 return this._imageCache.get(ref) || null;
27634 }
27635 set(name, ref, data) {
27636 unreachable("Abstract method `set` called.");
27637 }
27638}
27639class LocalImageCache extends BaseLocalCache {
27640 set(name, ref = null, data) {
27641 if (typeof name !== "string") {
27642 throw new Error('LocalImageCache.set - expected "name" argument.');
27643 }
27644 if (ref) {
27645 if (this._imageCache.has(ref)) {
27646 return;
27647 }
27648 this._nameRefMap.set(name, ref);
27649 this._imageCache.put(ref, data);
27650 return;
27651 }
27652 if (this._imageMap.has(name)) {
27653 return;
27654 }
27655 this._imageMap.set(name, data);
27656 }
27657}
27658class LocalColorSpaceCache extends BaseLocalCache {
27659 set(name = null, ref = null, data) {
27660 if (typeof name !== "string" && !ref) {
27661 throw new Error('LocalColorSpaceCache.set - expected "name" and/or "ref" argument.');
27662 }
27663 if (ref) {
27664 if (this._imageCache.has(ref)) {
27665 return;
27666 }
27667 if (name !== null) {
27668 this._nameRefMap.set(name, ref);
27669 }
27670 this._imageCache.put(ref, data);
27671 return;
27672 }
27673 if (this._imageMap.has(name)) {
27674 return;
27675 }
27676 this._imageMap.set(name, data);
27677 }
27678}
27679class LocalFunctionCache extends BaseLocalCache {
27680 constructor(options) {
27681 super({
27682 onlyRefs: true
27683 });
27684 }
27685 set(name = null, ref, data) {
27686 if (!ref) {
27687 throw new Error('LocalFunctionCache.set - expected "ref" argument.');
27688 }
27689 if (this._imageCache.has(ref)) {
27690 return;
27691 }
27692 this._imageCache.put(ref, data);
27693 }
27694}
27695class LocalGStateCache extends BaseLocalCache {
27696 set(name, ref = null, data) {
27697 if (typeof name !== "string") {
27698 throw new Error('LocalGStateCache.set - expected "name" argument.');
27699 }
27700 if (ref) {
27701 if (this._imageCache.has(ref)) {
27702 return;
27703 }
27704 this._nameRefMap.set(name, ref);
27705 this._imageCache.put(ref, data);
27706 return;
27707 }
27708 if (this._imageMap.has(name)) {
27709 return;
27710 }
27711 this._imageMap.set(name, data);
27712 }
27713}
27714class LocalTilingPatternCache extends BaseLocalCache {
27715 constructor(options) {
27716 super({
27717 onlyRefs: true
27718 });
27719 }
27720 set(name = null, ref, data) {
27721 if (!ref) {
27722 throw new Error('LocalTilingPatternCache.set - expected "ref" argument.');
27723 }
27724 if (this._imageCache.has(ref)) {
27725 return;
27726 }
27727 this._imageCache.put(ref, data);
27728 }
27729}
27730class RegionalImageCache extends BaseLocalCache {
27731 constructor(options) {
27732 super({
27733 onlyRefs: true
27734 });
27735 }
27736 set(name = null, ref, data) {
27737 if (!ref) {
27738 throw new Error('RegionalImageCache.set - expected "ref" argument.');
27739 }
27740 if (this._imageCache.has(ref)) {
27741 return;
27742 }
27743 this._imageCache.put(ref, data);
27744 }
27745}
27746class GlobalImageCache {
27747 static NUM_PAGES_THRESHOLD = 2;
27748 static MIN_IMAGES_TO_CACHE = 10;
27749 static MAX_BYTE_SIZE = 5 * MAX_IMAGE_SIZE_TO_CACHE;
27750 constructor() {
27751 this._refCache = new RefSetCache();
27752 this._imageCache = new RefSetCache();
27753 }
27754 get _byteSize() {
27755 let byteSize = 0;
27756 for (const imageData of this._imageCache) {
27757 byteSize += imageData.byteSize;
27758 }
27759 return byteSize;
27760 }
27761 get _cacheLimitReached() {
27762 if (this._imageCache.size < GlobalImageCache.MIN_IMAGES_TO_CACHE) {
27763 return false;
27764 }
27765 if (this._byteSize < GlobalImageCache.MAX_BYTE_SIZE) {
27766 return false;
27767 }
27768 return true;
27769 }
27770 shouldCache(ref, pageIndex) {
27771 let pageIndexSet = this._refCache.get(ref);
27772 if (!pageIndexSet) {
27773 pageIndexSet = new Set();
27774 this._refCache.put(ref, pageIndexSet);
27775 }
27776 pageIndexSet.add(pageIndex);
27777 if (pageIndexSet.size < GlobalImageCache.NUM_PAGES_THRESHOLD) {
27778 return false;
27779 }
27780 if (!this._imageCache.has(ref) && this._cacheLimitReached) {
27781 return false;
27782 }
27783 return true;
27784 }
27785 addByteSize(ref, byteSize) {
27786 const imageData = this._imageCache.get(ref);
27787 if (!imageData) {
27788 return;
27789 }
27790 if (imageData.byteSize) {
27791 return;
27792 }
27793 imageData.byteSize = byteSize;
27794 }
27795 getData(ref, pageIndex) {
27796 const pageIndexSet = this._refCache.get(ref);
27797 if (!pageIndexSet) {
27798 return null;
27799 }
27800 if (pageIndexSet.size < GlobalImageCache.NUM_PAGES_THRESHOLD) {
27801 return null;
27802 }
27803 const imageData = this._imageCache.get(ref);
27804 if (!imageData) {
27805 return null;
27806 }
27807 pageIndexSet.add(pageIndex);
27808 return imageData;
27809 }
27810 setData(ref, data) {
27811 if (!this._refCache.has(ref)) {
27812 throw new Error('GlobalImageCache.setData - expected "shouldCache" to have been called.');
27813 }
27814 if (this._imageCache.has(ref)) {
27815 return;
27816 }
27817 if (this._cacheLimitReached) {
27818 warn("GlobalImageCache.setData - cache limit reached.");
27819 return;
27820 }
27821 this._imageCache.put(ref, data);
27822 }
27823 clear(onlyData = false) {
27824 if (!onlyData) {
27825 this._refCache.clear();
27826 }
27827 this._imageCache.clear();
27828 }
27829}
27830
27831;// CONCATENATED MODULE: ./src/core/function.js
27832
27833
27834
27835
27836
27837class PDFFunctionFactory {
27838 constructor({
27839 xref,
27840 isEvalSupported = true
27841 }) {
27842 this.xref = xref;
27843 this.isEvalSupported = isEvalSupported !== false;
27844 }
27845 create(fn) {
27846 const cachedFunction = this.getCached(fn);
27847 if (cachedFunction) {
27848 return cachedFunction;
27849 }
27850 const parsedFunction = PDFFunction.parse({
27851 xref: this.xref,
27852 isEvalSupported: this.isEvalSupported,
27853 fn: fn instanceof Ref ? this.xref.fetch(fn) : fn
27854 });
27855 this._cache(fn, parsedFunction);
27856 return parsedFunction;
27857 }
27858 createFromArray(fnObj) {
27859 const cachedFunction = this.getCached(fnObj);
27860 if (cachedFunction) {
27861 return cachedFunction;
27862 }
27863 const parsedFunction = PDFFunction.parseArray({
27864 xref: this.xref,
27865 isEvalSupported: this.isEvalSupported,
27866 fnObj: fnObj instanceof Ref ? this.xref.fetch(fnObj) : fnObj
27867 });
27868 this._cache(fnObj, parsedFunction);
27869 return parsedFunction;
27870 }
27871 getCached(cacheKey) {
27872 let fnRef;
27873 if (cacheKey instanceof Ref) {
27874 fnRef = cacheKey;
27875 } else if (cacheKey instanceof Dict) {
27876 fnRef = cacheKey.objId;
27877 } else if (cacheKey instanceof BaseStream) {
27878 fnRef = cacheKey.dict?.objId;
27879 }
27880 if (fnRef) {
27881 const localFunction = this._localFunctionCache.getByRef(fnRef);
27882 if (localFunction) {
27883 return localFunction;
27884 }
27885 }
27886 return null;
27887 }
27888 _cache(cacheKey, parsedFunction) {
27889 if (!parsedFunction) {
27890 throw new Error('PDFFunctionFactory._cache - expected "parsedFunction" argument.');
27891 }
27892 let fnRef;
27893 if (cacheKey instanceof Ref) {
27894 fnRef = cacheKey;
27895 } else if (cacheKey instanceof Dict) {
27896 fnRef = cacheKey.objId;
27897 } else if (cacheKey instanceof BaseStream) {
27898 fnRef = cacheKey.dict?.objId;
27899 }
27900 if (fnRef) {
27901 this._localFunctionCache.set(null, fnRef, parsedFunction);
27902 }
27903 }
27904 get _localFunctionCache() {
27905 return shadow(this, "_localFunctionCache", new LocalFunctionCache());
27906 }
27907}
27908function toNumberArray(arr) {
27909 if (!Array.isArray(arr)) {
27910 return null;
27911 }
27912 const length = arr.length;
27913 for (let i = 0; i < length; i++) {
27914 if (typeof arr[i] !== "number") {
27915 const result = new Array(length);
27916 for (let j = 0; j < length; j++) {
27917 result[j] = +arr[j];
27918 }
27919 return result;
27920 }
27921 }
27922 return arr;
27923}
27924class PDFFunction {
27925 static getSampleArray(size, outputSize, bps, stream) {
27926 let i, ii;
27927 let length = 1;
27928 for (i = 0, ii = size.length; i < ii; i++) {
27929 length *= size[i];
27930 }
27931 length *= outputSize;
27932 const array = new Array(length);
27933 let codeSize = 0;
27934 let codeBuf = 0;
27935 const sampleMul = 1.0 / (2.0 ** bps - 1);
27936 const strBytes = stream.getBytes((length * bps + 7) / 8);
27937 let strIdx = 0;
27938 for (i = 0; i < length; i++) {
27939 while (codeSize < bps) {
27940 codeBuf <<= 8;
27941 codeBuf |= strBytes[strIdx++];
27942 codeSize += 8;
27943 }
27944 codeSize -= bps;
27945 array[i] = (codeBuf >> codeSize) * sampleMul;
27946 codeBuf &= (1 << codeSize) - 1;
27947 }
27948 return array;
27949 }
27950 static parse({
27951 xref,
27952 isEvalSupported,
27953 fn
27954 }) {
27955 const dict = fn.dict || fn;
27956 const typeNum = dict.get("FunctionType");
27957 switch (typeNum) {
27958 case 0:
27959 return this.constructSampled({
27960 xref,
27961 isEvalSupported,
27962 fn,
27963 dict
27964 });
27965 case 1:
27966 break;
27967 case 2:
27968 return this.constructInterpolated({
27969 xref,
27970 isEvalSupported,
27971 dict
27972 });
27973 case 3:
27974 return this.constructStiched({
27975 xref,
27976 isEvalSupported,
27977 dict
27978 });
27979 case 4:
27980 return this.constructPostScript({
27981 xref,
27982 isEvalSupported,
27983 fn,
27984 dict
27985 });
27986 }
27987 throw new FormatError("Unknown type of function");
27988 }
27989 static parseArray({
27990 xref,
27991 isEvalSupported,
27992 fnObj
27993 }) {
27994 if (!Array.isArray(fnObj)) {
27995 return this.parse({
27996 xref,
27997 isEvalSupported,
27998 fn: fnObj
27999 });
28000 }
28001 const fnArray = [];
28002 for (const fn of fnObj) {
28003 fnArray.push(this.parse({
28004 xref,
28005 isEvalSupported,
28006 fn: xref.fetchIfRef(fn)
28007 }));
28008 }
28009 return function (src, srcOffset, dest, destOffset) {
28010 for (let i = 0, ii = fnArray.length; i < ii; i++) {
28011 fnArray[i](src, srcOffset, dest, destOffset + i);
28012 }
28013 };
28014 }
28015 static constructSampled({
28016 xref,
28017 isEvalSupported,
28018 fn,
28019 dict
28020 }) {
28021 function toMultiArray(arr) {
28022 const inputLength = arr.length;
28023 const out = [];
28024 let index = 0;
28025 for (let i = 0; i < inputLength; i += 2) {
28026 out[index++] = [arr[i], arr[i + 1]];
28027 }
28028 return out;
28029 }
28030 function interpolate(x, xmin, xmax, ymin, ymax) {
28031 return ymin + (x - xmin) * ((ymax - ymin) / (xmax - xmin));
28032 }
28033 let domain = toNumberArray(dict.getArray("Domain"));
28034 let range = toNumberArray(dict.getArray("Range"));
28035 if (!domain || !range) {
28036 throw new FormatError("No domain or range");
28037 }
28038 const inputSize = domain.length / 2;
28039 const outputSize = range.length / 2;
28040 domain = toMultiArray(domain);
28041 range = toMultiArray(range);
28042 const size = toNumberArray(dict.getArray("Size"));
28043 const bps = dict.get("BitsPerSample");
28044 const order = dict.get("Order") || 1;
28045 if (order !== 1) {
28046 info("No support for cubic spline interpolation: " + order);
28047 }
28048 let encode = toNumberArray(dict.getArray("Encode"));
28049 if (!encode) {
28050 encode = [];
28051 for (let i = 0; i < inputSize; ++i) {
28052 encode.push([0, size[i] - 1]);
28053 }
28054 } else {
28055 encode = toMultiArray(encode);
28056 }
28057 let decode = toNumberArray(dict.getArray("Decode"));
28058 decode = !decode ? range : toMultiArray(decode);
28059 const samples = this.getSampleArray(size, outputSize, bps, fn);
28060 return function constructSampledFn(src, srcOffset, dest, destOffset) {
28061 const cubeVertices = 1 << inputSize;
28062 const cubeN = new Float64Array(cubeVertices);
28063 const cubeVertex = new Uint32Array(cubeVertices);
28064 let i, j;
28065 for (j = 0; j < cubeVertices; j++) {
28066 cubeN[j] = 1;
28067 }
28068 let k = outputSize,
28069 pos = 1;
28070 for (i = 0; i < inputSize; ++i) {
28071 const domain_2i = domain[i][0];
28072 const domain_2i_1 = domain[i][1];
28073 const xi = Math.min(Math.max(src[srcOffset + i], domain_2i), domain_2i_1);
28074 let e = interpolate(xi, domain_2i, domain_2i_1, encode[i][0], encode[i][1]);
28075 const size_i = size[i];
28076 e = Math.min(Math.max(e, 0), size_i - 1);
28077 const e0 = e < size_i - 1 ? Math.floor(e) : e - 1;
28078 const n0 = e0 + 1 - e;
28079 const n1 = e - e0;
28080 const offset0 = e0 * k;
28081 const offset1 = offset0 + k;
28082 for (j = 0; j < cubeVertices; j++) {
28083 if (j & pos) {
28084 cubeN[j] *= n1;
28085 cubeVertex[j] += offset1;
28086 } else {
28087 cubeN[j] *= n0;
28088 cubeVertex[j] += offset0;
28089 }
28090 }
28091 k *= size_i;
28092 pos <<= 1;
28093 }
28094 for (j = 0; j < outputSize; ++j) {
28095 let rj = 0;
28096 for (i = 0; i < cubeVertices; i++) {
28097 rj += samples[cubeVertex[i] + j] * cubeN[i];
28098 }
28099 rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
28100 dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]), range[j][1]);
28101 }
28102 };
28103 }
28104 static constructInterpolated({
28105 xref,
28106 isEvalSupported,
28107 dict
28108 }) {
28109 const c0 = toNumberArray(dict.getArray("C0")) || [0];
28110 const c1 = toNumberArray(dict.getArray("C1")) || [1];
28111 const n = dict.get("N");
28112 const diff = [];
28113 for (let i = 0, ii = c0.length; i < ii; ++i) {
28114 diff.push(c1[i] - c0[i]);
28115 }
28116 const length = diff.length;
28117 return function constructInterpolatedFn(src, srcOffset, dest, destOffset) {
28118 const x = n === 1 ? src[srcOffset] : src[srcOffset] ** n;
28119 for (let j = 0; j < length; ++j) {
28120 dest[destOffset + j] = c0[j] + x * diff[j];
28121 }
28122 };
28123 }
28124 static constructStiched({
28125 xref,
28126 isEvalSupported,
28127 dict
28128 }) {
28129 const domain = toNumberArray(dict.getArray("Domain"));
28130 if (!domain) {
28131 throw new FormatError("No domain");
28132 }
28133 const inputSize = domain.length / 2;
28134 if (inputSize !== 1) {
28135 throw new FormatError("Bad domain for stiched function");
28136 }
28137 const fns = [];
28138 for (const fn of dict.get("Functions")) {
28139 fns.push(this.parse({
28140 xref,
28141 isEvalSupported,
28142 fn: xref.fetchIfRef(fn)
28143 }));
28144 }
28145 const bounds = toNumberArray(dict.getArray("Bounds"));
28146 const encode = toNumberArray(dict.getArray("Encode"));
28147 const tmpBuf = new Float32Array(1);
28148 return function constructStichedFn(src, srcOffset, dest, destOffset) {
28149 const clip = function constructStichedFromIRClip(v, min, max) {
28150 if (v > max) {
28151 v = max;
28152 } else if (v < min) {
28153 v = min;
28154 }
28155 return v;
28156 };
28157 const v = clip(src[srcOffset], domain[0], domain[1]);
28158 const length = bounds.length;
28159 let i;
28160 for (i = 0; i < length; ++i) {
28161 if (v < bounds[i]) {
28162 break;
28163 }
28164 }
28165 let dmin = domain[0];
28166 if (i > 0) {
28167 dmin = bounds[i - 1];
28168 }
28169 let dmax = domain[1];
28170 if (i < bounds.length) {
28171 dmax = bounds[i];
28172 }
28173 const rmin = encode[2 * i];
28174 const rmax = encode[2 * i + 1];
28175 tmpBuf[0] = dmin === dmax ? rmin : rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
28176 fns[i](tmpBuf, 0, dest, destOffset);
28177 };
28178 }
28179 static constructPostScript({
28180 xref,
28181 isEvalSupported,
28182 fn,
28183 dict
28184 }) {
28185 const domain = toNumberArray(dict.getArray("Domain"));
28186 const range = toNumberArray(dict.getArray("Range"));
28187 if (!domain) {
28188 throw new FormatError("No domain.");
28189 }
28190 if (!range) {
28191 throw new FormatError("No range.");
28192 }
28193 const lexer = new PostScriptLexer(fn);
28194 const parser = new PostScriptParser(lexer);
28195 const code = parser.parse();
28196 if (isEvalSupported && FeatureTest.isEvalSupported) {
28197 const compiled = new PostScriptCompiler().compile(code, domain, range);
28198 if (compiled) {
28199 return new Function("src", "srcOffset", "dest", "destOffset", compiled);
28200 }
28201 }
28202 info("Unable to compile PS function");
28203 const numOutputs = range.length >> 1;
28204 const numInputs = domain.length >> 1;
28205 const evaluator = new PostScriptEvaluator(code);
28206 const cache = Object.create(null);
28207 const MAX_CACHE_SIZE = 2048 * 4;
28208 let cache_available = MAX_CACHE_SIZE;
28209 const tmpBuf = new Float32Array(numInputs);
28210 return function constructPostScriptFn(src, srcOffset, dest, destOffset) {
28211 let i, value;
28212 let key = "";
28213 const input = tmpBuf;
28214 for (i = 0; i < numInputs; i++) {
28215 value = src[srcOffset + i];
28216 input[i] = value;
28217 key += value + "_";
28218 }
28219 const cachedValue = cache[key];
28220 if (cachedValue !== undefined) {
28221 dest.set(cachedValue, destOffset);
28222 return;
28223 }
28224 const output = new Float32Array(numOutputs);
28225 const stack = evaluator.execute(input);
28226 const stackIndex = stack.length - numOutputs;
28227 for (i = 0; i < numOutputs; i++) {
28228 value = stack[stackIndex + i];
28229 let bound = range[i * 2];
28230 if (value < bound) {
28231 value = bound;
28232 } else {
28233 bound = range[i * 2 + 1];
28234 if (value > bound) {
28235 value = bound;
28236 }
28237 }
28238 output[i] = value;
28239 }
28240 if (cache_available > 0) {
28241 cache_available--;
28242 cache[key] = output;
28243 }
28244 dest.set(output, destOffset);
28245 };
28246 }
28247}
28248function isPDFFunction(v) {
28249 let fnDict;
28250 if (v instanceof Dict) {
28251 fnDict = v;
28252 } else if (v instanceof BaseStream) {
28253 fnDict = v.dict;
28254 } else {
28255 return false;
28256 }
28257 return fnDict.has("FunctionType");
28258}
28259class PostScriptStack {
28260 static MAX_STACK_SIZE = 100;
28261 constructor(initialStack) {
28262 this.stack = initialStack ? Array.from(initialStack) : [];
28263 }
28264 push(value) {
28265 if (this.stack.length >= PostScriptStack.MAX_STACK_SIZE) {
28266 throw new Error("PostScript function stack overflow.");
28267 }
28268 this.stack.push(value);
28269 }
28270 pop() {
28271 if (this.stack.length <= 0) {
28272 throw new Error("PostScript function stack underflow.");
28273 }
28274 return this.stack.pop();
28275 }
28276 copy(n) {
28277 if (this.stack.length + n >= PostScriptStack.MAX_STACK_SIZE) {
28278 throw new Error("PostScript function stack overflow.");
28279 }
28280 const stack = this.stack;
28281 for (let i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
28282 stack.push(stack[i]);
28283 }
28284 }
28285 index(n) {
28286 this.push(this.stack[this.stack.length - n - 1]);
28287 }
28288 roll(n, p) {
28289 const stack = this.stack;
28290 const l = stack.length - n;
28291 const r = stack.length - 1;
28292 const c = l + (p - Math.floor(p / n) * n);
28293 for (let i = l, j = r; i < j; i++, j--) {
28294 const t = stack[i];
28295 stack[i] = stack[j];
28296 stack[j] = t;
28297 }
28298 for (let i = l, j = c - 1; i < j; i++, j--) {
28299 const t = stack[i];
28300 stack[i] = stack[j];
28301 stack[j] = t;
28302 }
28303 for (let i = c, j = r; i < j; i++, j--) {
28304 const t = stack[i];
28305 stack[i] = stack[j];
28306 stack[j] = t;
28307 }
28308 }
28309}
28310class PostScriptEvaluator {
28311 constructor(operators) {
28312 this.operators = operators;
28313 }
28314 execute(initialStack) {
28315 const stack = new PostScriptStack(initialStack);
28316 let counter = 0;
28317 const operators = this.operators;
28318 const length = operators.length;
28319 let operator, a, b;
28320 while (counter < length) {
28321 operator = operators[counter++];
28322 if (typeof operator === "number") {
28323 stack.push(operator);
28324 continue;
28325 }
28326 switch (operator) {
28327 case "jz":
28328 b = stack.pop();
28329 a = stack.pop();
28330 if (!a) {
28331 counter = b;
28332 }
28333 break;
28334 case "j":
28335 a = stack.pop();
28336 counter = a;
28337 break;
28338 case "abs":
28339 a = stack.pop();
28340 stack.push(Math.abs(a));
28341 break;
28342 case "add":
28343 b = stack.pop();
28344 a = stack.pop();
28345 stack.push(a + b);
28346 break;
28347 case "and":
28348 b = stack.pop();
28349 a = stack.pop();
28350 if (typeof a === "boolean" && typeof b === "boolean") {
28351 stack.push(a && b);
28352 } else {
28353 stack.push(a & b);
28354 }
28355 break;
28356 case "atan":
28357 b = stack.pop();
28358 a = stack.pop();
28359 a = Math.atan2(a, b) / Math.PI * 180;
28360 if (a < 0) {
28361 a += 360;
28362 }
28363 stack.push(a);
28364 break;
28365 case "bitshift":
28366 b = stack.pop();
28367 a = stack.pop();
28368 if (a > 0) {
28369 stack.push(a << b);
28370 } else {
28371 stack.push(a >> b);
28372 }
28373 break;
28374 case "ceiling":
28375 a = stack.pop();
28376 stack.push(Math.ceil(a));
28377 break;
28378 case "copy":
28379 a = stack.pop();
28380 stack.copy(a);
28381 break;
28382 case "cos":
28383 a = stack.pop();
28384 stack.push(Math.cos(a % 360 / 180 * Math.PI));
28385 break;
28386 case "cvi":
28387 a = stack.pop() | 0;
28388 stack.push(a);
28389 break;
28390 case "cvr":
28391 break;
28392 case "div":
28393 b = stack.pop();
28394 a = stack.pop();
28395 stack.push(a / b);
28396 break;
28397 case "dup":
28398 stack.copy(1);
28399 break;
28400 case "eq":
28401 b = stack.pop();
28402 a = stack.pop();
28403 stack.push(a === b);
28404 break;
28405 case "exch":
28406 stack.roll(2, 1);
28407 break;
28408 case "exp":
28409 b = stack.pop();
28410 a = stack.pop();
28411 stack.push(a ** b);
28412 break;
28413 case "false":
28414 stack.push(false);
28415 break;
28416 case "floor":
28417 a = stack.pop();
28418 stack.push(Math.floor(a));
28419 break;
28420 case "ge":
28421 b = stack.pop();
28422 a = stack.pop();
28423 stack.push(a >= b);
28424 break;
28425 case "gt":
28426 b = stack.pop();
28427 a = stack.pop();
28428 stack.push(a > b);
28429 break;
28430 case "idiv":
28431 b = stack.pop();
28432 a = stack.pop();
28433 stack.push(a / b | 0);
28434 break;
28435 case "index":
28436 a = stack.pop();
28437 stack.index(a);
28438 break;
28439 case "le":
28440 b = stack.pop();
28441 a = stack.pop();
28442 stack.push(a <= b);
28443 break;
28444 case "ln":
28445 a = stack.pop();
28446 stack.push(Math.log(a));
28447 break;
28448 case "log":
28449 a = stack.pop();
28450 stack.push(Math.log10(a));
28451 break;
28452 case "lt":
28453 b = stack.pop();
28454 a = stack.pop();
28455 stack.push(a < b);
28456 break;
28457 case "mod":
28458 b = stack.pop();
28459 a = stack.pop();
28460 stack.push(a % b);
28461 break;
28462 case "mul":
28463 b = stack.pop();
28464 a = stack.pop();
28465 stack.push(a * b);
28466 break;
28467 case "ne":
28468 b = stack.pop();
28469 a = stack.pop();
28470 stack.push(a !== b);
28471 break;
28472 case "neg":
28473 a = stack.pop();
28474 stack.push(-a);
28475 break;
28476 case "not":
28477 a = stack.pop();
28478 if (typeof a === "boolean") {
28479 stack.push(!a);
28480 } else {
28481 stack.push(~a);
28482 }
28483 break;
28484 case "or":
28485 b = stack.pop();
28486 a = stack.pop();
28487 if (typeof a === "boolean" && typeof b === "boolean") {
28488 stack.push(a || b);
28489 } else {
28490 stack.push(a | b);
28491 }
28492 break;
28493 case "pop":
28494 stack.pop();
28495 break;
28496 case "roll":
28497 b = stack.pop();
28498 a = stack.pop();
28499 stack.roll(a, b);
28500 break;
28501 case "round":
28502 a = stack.pop();
28503 stack.push(Math.round(a));
28504 break;
28505 case "sin":
28506 a = stack.pop();
28507 stack.push(Math.sin(a % 360 / 180 * Math.PI));
28508 break;
28509 case "sqrt":
28510 a = stack.pop();
28511 stack.push(Math.sqrt(a));
28512 break;
28513 case "sub":
28514 b = stack.pop();
28515 a = stack.pop();
28516 stack.push(a - b);
28517 break;
28518 case "true":
28519 stack.push(true);
28520 break;
28521 case "truncate":
28522 a = stack.pop();
28523 a = a < 0 ? Math.ceil(a) : Math.floor(a);
28524 stack.push(a);
28525 break;
28526 case "xor":
28527 b = stack.pop();
28528 a = stack.pop();
28529 if (typeof a === "boolean" && typeof b === "boolean") {
28530 stack.push(a !== b);
28531 } else {
28532 stack.push(a ^ b);
28533 }
28534 break;
28535 default:
28536 throw new FormatError(`Unknown operator ${operator}`);
28537 }
28538 }
28539 return stack.stack;
28540 }
28541}
28542class AstNode {
28543 constructor(type) {
28544 this.type = type;
28545 }
28546 visit(visitor) {
28547 unreachable("abstract method");
28548 }
28549}
28550class AstArgument extends AstNode {
28551 constructor(index, min, max) {
28552 super("args");
28553 this.index = index;
28554 this.min = min;
28555 this.max = max;
28556 }
28557 visit(visitor) {
28558 visitor.visitArgument(this);
28559 }
28560}
28561class AstLiteral extends AstNode {
28562 constructor(number) {
28563 super("literal");
28564 this.number = number;
28565 this.min = number;
28566 this.max = number;
28567 }
28568 visit(visitor) {
28569 visitor.visitLiteral(this);
28570 }
28571}
28572class AstBinaryOperation extends AstNode {
28573 constructor(op, arg1, arg2, min, max) {
28574 super("binary");
28575 this.op = op;
28576 this.arg1 = arg1;
28577 this.arg2 = arg2;
28578 this.min = min;
28579 this.max = max;
28580 }
28581 visit(visitor) {
28582 visitor.visitBinaryOperation(this);
28583 }
28584}
28585class AstMin extends AstNode {
28586 constructor(arg, max) {
28587 super("max");
28588 this.arg = arg;
28589 this.min = arg.min;
28590 this.max = max;
28591 }
28592 visit(visitor) {
28593 visitor.visitMin(this);
28594 }
28595}
28596class AstVariable extends AstNode {
28597 constructor(index, min, max) {
28598 super("var");
28599 this.index = index;
28600 this.min = min;
28601 this.max = max;
28602 }
28603 visit(visitor) {
28604 visitor.visitVariable(this);
28605 }
28606}
28607class AstVariableDefinition extends AstNode {
28608 constructor(variable, arg) {
28609 super("definition");
28610 this.variable = variable;
28611 this.arg = arg;
28612 }
28613 visit(visitor) {
28614 visitor.visitVariableDefinition(this);
28615 }
28616}
28617class ExpressionBuilderVisitor {
28618 constructor() {
28619 this.parts = [];
28620 }
28621 visitArgument(arg) {
28622 this.parts.push("Math.max(", arg.min, ", Math.min(", arg.max, ", src[srcOffset + ", arg.index, "]))");
28623 }
28624 visitVariable(variable) {
28625 this.parts.push("v", variable.index);
28626 }
28627 visitLiteral(literal) {
28628 this.parts.push(literal.number);
28629 }
28630 visitBinaryOperation(operation) {
28631 this.parts.push("(");
28632 operation.arg1.visit(this);
28633 this.parts.push(" ", operation.op, " ");
28634 operation.arg2.visit(this);
28635 this.parts.push(")");
28636 }
28637 visitVariableDefinition(definition) {
28638 this.parts.push("var ");
28639 definition.variable.visit(this);
28640 this.parts.push(" = ");
28641 definition.arg.visit(this);
28642 this.parts.push(";");
28643 }
28644 visitMin(max) {
28645 this.parts.push("Math.min(");
28646 max.arg.visit(this);
28647 this.parts.push(", ", max.max, ")");
28648 }
28649 toString() {
28650 return this.parts.join("");
28651 }
28652}
28653function buildAddOperation(num1, num2) {
28654 if (num2.type === "literal" && num2.number === 0) {
28655 return num1;
28656 }
28657 if (num1.type === "literal" && num1.number === 0) {
28658 return num2;
28659 }
28660 if (num2.type === "literal" && num1.type === "literal") {
28661 return new AstLiteral(num1.number + num2.number);
28662 }
28663 return new AstBinaryOperation("+", num1, num2, num1.min + num2.min, num1.max + num2.max);
28664}
28665function buildMulOperation(num1, num2) {
28666 if (num2.type === "literal") {
28667 if (num2.number === 0) {
28668 return new AstLiteral(0);
28669 } else if (num2.number === 1) {
28670 return num1;
28671 } else if (num1.type === "literal") {
28672 return new AstLiteral(num1.number * num2.number);
28673 }
28674 }
28675 if (num1.type === "literal") {
28676 if (num1.number === 0) {
28677 return new AstLiteral(0);
28678 } else if (num1.number === 1) {
28679 return num2;
28680 }
28681 }
28682 const min = Math.min(num1.min * num2.min, num1.min * num2.max, num1.max * num2.min, num1.max * num2.max);
28683 const max = Math.max(num1.min * num2.min, num1.min * num2.max, num1.max * num2.min, num1.max * num2.max);
28684 return new AstBinaryOperation("*", num1, num2, min, max);
28685}
28686function buildSubOperation(num1, num2) {
28687 if (num2.type === "literal") {
28688 if (num2.number === 0) {
28689 return num1;
28690 } else if (num1.type === "literal") {
28691 return new AstLiteral(num1.number - num2.number);
28692 }
28693 }
28694 if (num2.type === "binary" && num2.op === "-" && num1.type === "literal" && num1.number === 1 && num2.arg1.type === "literal" && num2.arg1.number === 1) {
28695 return num2.arg2;
28696 }
28697 return new AstBinaryOperation("-", num1, num2, num1.min - num2.max, num1.max - num2.min);
28698}
28699function buildMinOperation(num1, max) {
28700 if (num1.min >= max) {
28701 return new AstLiteral(max);
28702 } else if (num1.max <= max) {
28703 return num1;
28704 }
28705 return new AstMin(num1, max);
28706}
28707class PostScriptCompiler {
28708 compile(code, domain, range) {
28709 const stack = [];
28710 const instructions = [];
28711 const inputSize = domain.length >> 1,
28712 outputSize = range.length >> 1;
28713 let lastRegister = 0;
28714 let n, j;
28715 let num1, num2, ast1, ast2, tmpVar, item;
28716 for (let i = 0; i < inputSize; i++) {
28717 stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
28718 }
28719 for (let i = 0, ii = code.length; i < ii; i++) {
28720 item = code[i];
28721 if (typeof item === "number") {
28722 stack.push(new AstLiteral(item));
28723 continue;
28724 }
28725 switch (item) {
28726 case "add":
28727 if (stack.length < 2) {
28728 return null;
28729 }
28730 num2 = stack.pop();
28731 num1 = stack.pop();
28732 stack.push(buildAddOperation(num1, num2));
28733 break;
28734 case "cvr":
28735 if (stack.length < 1) {
28736 return null;
28737 }
28738 break;
28739 case "mul":
28740 if (stack.length < 2) {
28741 return null;
28742 }
28743 num2 = stack.pop();
28744 num1 = stack.pop();
28745 stack.push(buildMulOperation(num1, num2));
28746 break;
28747 case "sub":
28748 if (stack.length < 2) {
28749 return null;
28750 }
28751 num2 = stack.pop();
28752 num1 = stack.pop();
28753 stack.push(buildSubOperation(num1, num2));
28754 break;
28755 case "exch":
28756 if (stack.length < 2) {
28757 return null;
28758 }
28759 ast1 = stack.pop();
28760 ast2 = stack.pop();
28761 stack.push(ast1, ast2);
28762 break;
28763 case "pop":
28764 if (stack.length < 1) {
28765 return null;
28766 }
28767 stack.pop();
28768 break;
28769 case "index":
28770 if (stack.length < 1) {
28771 return null;
28772 }
28773 num1 = stack.pop();
28774 if (num1.type !== "literal") {
28775 return null;
28776 }
28777 n = num1.number;
28778 if (n < 0 || !Number.isInteger(n) || stack.length < n) {
28779 return null;
28780 }
28781 ast1 = stack[stack.length - n - 1];
28782 if (ast1.type === "literal" || ast1.type === "var") {
28783 stack.push(ast1);
28784 break;
28785 }
28786 tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
28787 stack[stack.length - n - 1] = tmpVar;
28788 stack.push(tmpVar);
28789 instructions.push(new AstVariableDefinition(tmpVar, ast1));
28790 break;
28791 case "dup":
28792 if (stack.length < 1) {
28793 return null;
28794 }
28795 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]) {
28796 num1 = stack.pop();
28797 stack.push(buildMinOperation(num1, code[i + 1]));
28798 i += 6;
28799 break;
28800 }
28801 ast1 = stack.at(-1);
28802 if (ast1.type === "literal" || ast1.type === "var") {
28803 stack.push(ast1);
28804 break;
28805 }
28806 tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
28807 stack[stack.length - 1] = tmpVar;
28808 stack.push(tmpVar);
28809 instructions.push(new AstVariableDefinition(tmpVar, ast1));
28810 break;
28811 case "roll":
28812 if (stack.length < 2) {
28813 return null;
28814 }
28815 num2 = stack.pop();
28816 num1 = stack.pop();
28817 if (num2.type !== "literal" || num1.type !== "literal") {
28818 return null;
28819 }
28820 j = num2.number;
28821 n = num1.number;
28822 if (n <= 0 || !Number.isInteger(n) || !Number.isInteger(j) || stack.length < n) {
28823 return null;
28824 }
28825 j = (j % n + n) % n;
28826 if (j === 0) {
28827 break;
28828 }
28829 stack.push(...stack.splice(stack.length - n, n - j));
28830 break;
28831 default:
28832 return null;
28833 }
28834 }
28835 if (stack.length !== outputSize) {
28836 return null;
28837 }
28838 const result = [];
28839 for (const instruction of instructions) {
28840 const statementBuilder = new ExpressionBuilderVisitor();
28841 instruction.visit(statementBuilder);
28842 result.push(statementBuilder.toString());
28843 }
28844 for (let i = 0, ii = stack.length; i < ii; i++) {
28845 const expr = stack[i],
28846 statementBuilder = new ExpressionBuilderVisitor();
28847 expr.visit(statementBuilder);
28848 const min = range[i * 2],
28849 max = range[i * 2 + 1];
28850 const out = [statementBuilder.toString()];
28851 if (min > expr.min) {
28852 out.unshift("Math.max(", min, ", ");
28853 out.push(")");
28854 }
28855 if (max < expr.max) {
28856 out.unshift("Math.min(", max, ", ");
28857 out.push(")");
28858 }
28859 out.unshift("dest[destOffset + ", i, "] = ");
28860 out.push(";");
28861 result.push(out.join(""));
28862 }
28863 return result.join("\n");
28864 }
28865}
28866
28867;// CONCATENATED MODULE: ./src/core/bidi.js
28868
28869const 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"];
28870const 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"];
28871function isOdd(i) {
28872 return (i & 1) !== 0;
28873}
28874function isEven(i) {
28875 return (i & 1) === 0;
28876}
28877function findUnequal(arr, start, value) {
28878 let j, jj;
28879 for (j = start, jj = arr.length; j < jj; ++j) {
28880 if (arr[j] !== value) {
28881 return j;
28882 }
28883 }
28884 return j;
28885}
28886function setValues(arr, start, end, value) {
28887 for (let j = start; j < end; ++j) {
28888 arr[j] = value;
28889 }
28890}
28891function reverseValues(arr, start, end) {
28892 for (let i = start, j = end - 1; i < j; ++i, --j) {
28893 const temp = arr[i];
28894 arr[i] = arr[j];
28895 arr[j] = temp;
28896 }
28897}
28898function createBidiText(str, isLTR, vertical = false) {
28899 let dir = "ltr";
28900 if (vertical) {
28901 dir = "ttb";
28902 } else if (!isLTR) {
28903 dir = "rtl";
28904 }
28905 return {
28906 str,
28907 dir
28908 };
28909}
28910const chars = [];
28911const types = [];
28912function bidi(str, startLevel = -1, vertical = false) {
28913 let isLTR = true;
28914 const strLength = str.length;
28915 if (strLength === 0 || vertical) {
28916 return createBidiText(str, isLTR, vertical);
28917 }
28918 chars.length = strLength;
28919 types.length = strLength;
28920 let numBidi = 0;
28921 let i, ii;
28922 for (i = 0; i < strLength; ++i) {
28923 chars[i] = str.charAt(i);
28924 const charCode = str.charCodeAt(i);
28925 let charType = "L";
28926 if (charCode <= 0x00ff) {
28927 charType = baseTypes[charCode];
28928 } else if (0x0590 <= charCode && charCode <= 0x05f4) {
28929 charType = "R";
28930 } else if (0x0600 <= charCode && charCode <= 0x06ff) {
28931 charType = arabicTypes[charCode & 0xff];
28932 if (!charType) {
28933 warn("Bidi: invalid Unicode character " + charCode.toString(16));
28934 }
28935 } else if (0x0700 <= charCode && charCode <= 0x08ac || 0xfb50 <= charCode && charCode <= 0xfdff || 0xfe70 <= charCode && charCode <= 0xfeff) {
28936 charType = "AL";
28937 }
28938 if (charType === "R" || charType === "AL" || charType === "AN") {
28939 numBidi++;
28940 }
28941 types[i] = charType;
28942 }
28943 if (numBidi === 0) {
28944 isLTR = true;
28945 return createBidiText(str, isLTR);
28946 }
28947 if (startLevel === -1) {
28948 if (numBidi / strLength < 0.3 && strLength > 4) {
28949 isLTR = true;
28950 startLevel = 0;
28951 } else {
28952 isLTR = false;
28953 startLevel = 1;
28954 }
28955 }
28956 const levels = [];
28957 for (i = 0; i < strLength; ++i) {
28958 levels[i] = startLevel;
28959 }
28960 const e = isOdd(startLevel) ? "R" : "L";
28961 const sor = e;
28962 const eor = sor;
28963 let lastType = sor;
28964 for (i = 0; i < strLength; ++i) {
28965 if (types[i] === "NSM") {
28966 types[i] = lastType;
28967 } else {
28968 lastType = types[i];
28969 }
28970 }
28971 lastType = sor;
28972 let t;
28973 for (i = 0; i < strLength; ++i) {
28974 t = types[i];
28975 if (t === "EN") {
28976 types[i] = lastType === "AL" ? "AN" : "EN";
28977 } else if (t === "R" || t === "L" || t === "AL") {
28978 lastType = t;
28979 }
28980 }
28981 for (i = 0; i < strLength; ++i) {
28982 t = types[i];
28983 if (t === "AL") {
28984 types[i] = "R";
28985 }
28986 }
28987 for (i = 1; i < strLength - 1; ++i) {
28988 if (types[i] === "ES" && types[i - 1] === "EN" && types[i + 1] === "EN") {
28989 types[i] = "EN";
28990 }
28991 if (types[i] === "CS" && (types[i - 1] === "EN" || types[i - 1] === "AN") && types[i + 1] === types[i - 1]) {
28992 types[i] = types[i - 1];
28993 }
28994 }
28995 for (i = 0; i < strLength; ++i) {
28996 if (types[i] === "EN") {
28997 for (let j = i - 1; j >= 0; --j) {
28998 if (types[j] !== "ET") {
28999 break;
29000 }
29001 types[j] = "EN";
29002 }
29003 for (let j = i + 1; j < strLength; ++j) {
29004 if (types[j] !== "ET") {
29005 break;
29006 }
29007 types[j] = "EN";
29008 }
29009 }
29010 }
29011 for (i = 0; i < strLength; ++i) {
29012 t = types[i];
29013 if (t === "WS" || t === "ES" || t === "ET" || t === "CS") {
29014 types[i] = "ON";
29015 }
29016 }
29017 lastType = sor;
29018 for (i = 0; i < strLength; ++i) {
29019 t = types[i];
29020 if (t === "EN") {
29021 types[i] = lastType === "L" ? "L" : "EN";
29022 } else if (t === "R" || t === "L") {
29023 lastType = t;
29024 }
29025 }
29026 for (i = 0; i < strLength; ++i) {
29027 if (types[i] === "ON") {
29028 const end = findUnequal(types, i + 1, "ON");
29029 let before = sor;
29030 if (i > 0) {
29031 before = types[i - 1];
29032 }
29033 let after = eor;
29034 if (end + 1 < strLength) {
29035 after = types[end + 1];
29036 }
29037 if (before !== "L") {
29038 before = "R";
29039 }
29040 if (after !== "L") {
29041 after = "R";
29042 }
29043 if (before === after) {
29044 setValues(types, i, end, before);
29045 }
29046 i = end - 1;
29047 }
29048 }
29049 for (i = 0; i < strLength; ++i) {
29050 if (types[i] === "ON") {
29051 types[i] = e;
29052 }
29053 }
29054 for (i = 0; i < strLength; ++i) {
29055 t = types[i];
29056 if (isEven(levels[i])) {
29057 if (t === "R") {
29058 levels[i] += 1;
29059 } else if (t === "AN" || t === "EN") {
29060 levels[i] += 2;
29061 }
29062 } else if (t === "L" || t === "AN" || t === "EN") {
29063 levels[i] += 1;
29064 }
29065 }
29066 let highestLevel = -1;
29067 let lowestOddLevel = 99;
29068 let level;
29069 for (i = 0, ii = levels.length; i < ii; ++i) {
29070 level = levels[i];
29071 if (highestLevel < level) {
29072 highestLevel = level;
29073 }
29074 if (lowestOddLevel > level && isOdd(level)) {
29075 lowestOddLevel = level;
29076 }
29077 }
29078 for (level = highestLevel; level >= lowestOddLevel; --level) {
29079 let start = -1;
29080 for (i = 0, ii = levels.length; i < ii; ++i) {
29081 if (levels[i] < level) {
29082 if (start >= 0) {
29083 reverseValues(chars, start, i);
29084 start = -1;
29085 }
29086 } else if (start < 0) {
29087 start = i;
29088 }
29089 }
29090 if (start >= 0) {
29091 reverseValues(chars, start, levels.length);
29092 }
29093 }
29094 for (i = 0, ii = chars.length; i < ii; ++i) {
29095 const ch = chars[i];
29096 if (ch === "<" || ch === ">") {
29097 chars[i] = "";
29098 }
29099 }
29100 return createBidiText(chars.join(""), isLTR);
29101}
29102
29103;// CONCATENATED MODULE: ./src/core/font_substitutions.js
29104
29105
29106const NORMAL = {
29107 style: "normal",
29108 weight: "normal"
29109};
29110const BOLD = {
29111 style: "normal",
29112 weight: "bold"
29113};
29114const ITALIC = {
29115 style: "italic",
29116 weight: "normal"
29117};
29118const BOLDITALIC = {
29119 style: "italic",
29120 weight: "bold"
29121};
29122const substitutionMap = new Map([["Times-Roman", {
29123 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"],
29124 style: NORMAL,
29125 ultimate: "serif"
29126}], ["Times-Bold", {
29127 alias: "Times-Roman",
29128 style: BOLD,
29129 ultimate: "serif"
29130}], ["Times-Italic", {
29131 alias: "Times-Roman",
29132 style: ITALIC,
29133 ultimate: "serif"
29134}], ["Times-BoldItalic", {
29135 alias: "Times-Roman",
29136 style: BOLDITALIC,
29137 ultimate: "serif"
29138}], ["Helvetica", {
29139 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"],
29140 path: "LiberationSans-Regular.ttf",
29141 style: NORMAL,
29142 ultimate: "sans-serif"
29143}], ["Helvetica-Bold", {
29144 alias: "Helvetica",
29145 path: "LiberationSans-Bold.ttf",
29146 style: BOLD,
29147 ultimate: "sans-serif"
29148}], ["Helvetica-Oblique", {
29149 alias: "Helvetica",
29150 path: "LiberationSans-Italic.ttf",
29151 style: ITALIC,
29152 ultimate: "sans-serif"
29153}], ["Helvetica-BoldOblique", {
29154 alias: "Helvetica",
29155 path: "LiberationSans-BoldItalic.ttf",
29156 style: BOLDITALIC,
29157 ultimate: "sans-serif"
29158}], ["Courier", {
29159 local: ["Courier", "Courier New", "Liberation Mono", "Nimbus Mono", "Nimbus Mono L", "Cousine", "Cumberland", "TeX Gyre Cursor", "FreeMono", "Linux Libertine Mono O", "Libertinus Mono"],
29160 style: NORMAL,
29161 ultimate: "monospace"
29162}], ["Courier-Bold", {
29163 alias: "Courier",
29164 style: BOLD,
29165 ultimate: "monospace"
29166}], ["Courier-Oblique", {
29167 alias: "Courier",
29168 style: ITALIC,
29169 ultimate: "monospace"
29170}], ["Courier-BoldOblique", {
29171 alias: "Courier",
29172 style: BOLDITALIC,
29173 ultimate: "monospace"
29174}], ["ArialBlack", {
29175 local: ["Arial Black"],
29176 style: {
29177 style: "normal",
29178 weight: "900"
29179 },
29180 fallback: "Helvetica-Bold"
29181}], ["ArialBlack-Bold", {
29182 alias: "ArialBlack"
29183}], ["ArialBlack-Italic", {
29184 alias: "ArialBlack",
29185 style: {
29186 style: "italic",
29187 weight: "900"
29188 },
29189 fallback: "Helvetica-BoldOblique"
29190}], ["ArialBlack-BoldItalic", {
29191 alias: "ArialBlack-Italic"
29192}], ["ArialNarrow", {
29193 local: ["Arial Narrow", "Liberation Sans Narrow", "Helvetica Condensed", "Nimbus Sans Narrow", "TeX Gyre Heros Cn"],
29194 style: NORMAL,
29195 fallback: "Helvetica"
29196}], ["ArialNarrow-Bold", {
29197 alias: "ArialNarrow",
29198 style: BOLD,
29199 fallback: "Helvetica-Bold"
29200}], ["ArialNarrow-Italic", {
29201 alias: "ArialNarrow",
29202 style: ITALIC,
29203 fallback: "Helvetica-Oblique"
29204}], ["ArialNarrow-BoldItalic", {
29205 alias: "ArialNarrow",
29206 style: BOLDITALIC,
29207 fallback: "Helvetica-BoldOblique"
29208}], ["Calibri", {
29209 local: ["Calibri", "Carlito"],
29210 style: NORMAL,
29211 fallback: "Helvetica"
29212}], ["Calibri-Bold", {
29213 alias: "Calibri",
29214 style: BOLD,
29215 fallback: "Helvetica-Bold"
29216}], ["Calibri-Italic", {
29217 alias: "Calibri",
29218 style: ITALIC,
29219 fallback: "Helvetica-Oblique"
29220}], ["Calibri-BoldItalic", {
29221 alias: "Calibri",
29222 style: BOLDITALIC,
29223 fallback: "Helvetica-BoldOblique"
29224}], ["Wingdings", {
29225 local: ["Wingdings", "URW Dingbats"],
29226 style: NORMAL
29227}], ["Wingdings-Regular", {
29228 alias: "Wingdings"
29229}], ["Wingdings-Bold", {
29230 alias: "Wingdings"
29231}]]);
29232const fontAliases = new Map([["Arial-Black", "ArialBlack"]]);
29233function getStyleToAppend(style) {
29234 switch (style) {
29235 case BOLD:
29236 return "Bold";
29237 case ITALIC:
29238 return "Italic";
29239 case BOLDITALIC:
29240 return "Bold Italic";
29241 default:
29242 if (style?.weight === "bold") {
29243 return "Bold";
29244 }
29245 if (style?.style === "italic") {
29246 return "Italic";
29247 }
29248 }
29249 return "";
29250}
29251function getFamilyName(str) {
29252 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"]);
29253 return str.split(/[- ,+]+/g).filter(tok => !keywords.has(tok.toLowerCase())).join(" ");
29254}
29255function generateFont({
29256 alias,
29257 local,
29258 path,
29259 fallback,
29260 style,
29261 ultimate
29262}, src, localFontPath, useFallback = true, usePath = true, append = "") {
29263 const result = {
29264 style: null,
29265 ultimate: null
29266 };
29267 if (local) {
29268 const extra = append ? ` ${append}` : "";
29269 for (const name of local) {
29270 src.push(`local(${name}${extra})`);
29271 }
29272 }
29273 if (alias) {
29274 const substitution = substitutionMap.get(alias);
29275 const aliasAppend = append || getStyleToAppend(style);
29276 Object.assign(result, generateFont(substitution, src, localFontPath, useFallback && !fallback, usePath && !path, aliasAppend));
29277 }
29278 if (style) {
29279 result.style = style;
29280 }
29281 if (ultimate) {
29282 result.ultimate = ultimate;
29283 }
29284 if (useFallback && fallback) {
29285 const fallbackInfo = substitutionMap.get(fallback);
29286 const {
29287 ultimate: fallbackUltimate
29288 } = generateFont(fallbackInfo, src, localFontPath, useFallback, usePath && !path, append);
29289 result.ultimate ||= fallbackUltimate;
29290 }
29291 if (usePath && path && localFontPath) {
29292 src.push(`url(${localFontPath}${path})`);
29293 }
29294 return result;
29295}
29296function getFontSubstitution(systemFontCache, idFactory, localFontPath, baseFontName, standardFontName) {
29297 if (baseFontName.startsWith("InvalidPDFjsFont_")) {
29298 return null;
29299 }
29300 baseFontName = normalizeFontName(baseFontName);
29301 const key = baseFontName;
29302 let substitutionInfo = systemFontCache.get(key);
29303 if (substitutionInfo) {
29304 return substitutionInfo;
29305 }
29306 let substitution = substitutionMap.get(baseFontName);
29307 if (!substitution) {
29308 for (const [alias, subst] of fontAliases) {
29309 if (baseFontName.startsWith(alias)) {
29310 baseFontName = `${subst}${baseFontName.substring(alias.length)}`;
29311 substitution = substitutionMap.get(baseFontName);
29312 break;
29313 }
29314 }
29315 }
29316 let mustAddBaseFont = false;
29317 if (!substitution) {
29318 substitution = substitutionMap.get(standardFontName);
29319 mustAddBaseFont = true;
29320 }
29321 const loadedName = `${idFactory.getDocId()}_s${idFactory.createFontId()}`;
29322 if (!substitution) {
29323 if (!validateFontName(baseFontName)) {
29324 systemFontCache.set(key, null);
29325 return null;
29326 }
29327 const bold = /bold/gi.test(baseFontName);
29328 const italic = /oblique|italic/gi.test(baseFontName);
29329 const style = bold && italic && BOLDITALIC || bold && BOLD || italic && ITALIC || NORMAL;
29330 substitutionInfo = {
29331 css: `"${getFamilyName(baseFontName)}",${loadedName}`,
29332 guessFallback: true,
29333 loadedName,
29334 baseFontName,
29335 src: `local(${baseFontName})`,
29336 style
29337 };
29338 systemFontCache.set(key, substitutionInfo);
29339 return substitutionInfo;
29340 }
29341 const src = [];
29342 if (mustAddBaseFont && validateFontName(baseFontName)) {
29343 src.push(`local(${baseFontName})`);
29344 }
29345 const {
29346 style,
29347 ultimate
29348 } = generateFont(substitution, src, localFontPath);
29349 const guessFallback = ultimate === null;
29350 const fallback = guessFallback ? "" : `,${ultimate}`;
29351 substitutionInfo = {
29352 css: `"${getFamilyName(baseFontName)}",${loadedName}${fallback}`,
29353 guessFallback,
29354 loadedName,
29355 baseFontName,
29356 src: src.join(","),
29357 style
29358 };
29359 systemFontCache.set(key, substitutionInfo);
29360 return substitutionInfo;
29361}
29362
29363;// CONCATENATED MODULE: ./src/core/image_resizer.js
29364
29365const MIN_IMAGE_DIM = 2048;
29366const MAX_IMAGE_DIM = 65537;
29367const MAX_ERROR = 128;
29368class ImageResizer {
29369 constructor(imgData, isMask) {
29370 this._imgData = imgData;
29371 this._isMask = isMask;
29372 }
29373 static needsToBeResized(width, height) {
29374 if (width <= this._goodSquareLength && height <= this._goodSquareLength) {
29375 return false;
29376 }
29377 const {
29378 MAX_DIM
29379 } = this;
29380 if (width > MAX_DIM || height > MAX_DIM) {
29381 return true;
29382 }
29383 const area = width * height;
29384 if (this._hasMaxArea) {
29385 return area > this.MAX_AREA;
29386 }
29387 if (area < this._goodSquareLength ** 2) {
29388 return false;
29389 }
29390 if (this._areGoodDims(width, height)) {
29391 this._goodSquareLength = Math.max(this._goodSquareLength, Math.floor(Math.sqrt(width * height)));
29392 return false;
29393 }
29394 this._goodSquareLength = this._guessMax(this._goodSquareLength, MAX_DIM, MAX_ERROR, 0);
29395 const maxArea = this.MAX_AREA = this._goodSquareLength ** 2;
29396 return area > maxArea;
29397 }
29398 static get MAX_DIM() {
29399 return shadow(this, "MAX_DIM", this._guessMax(MIN_IMAGE_DIM, MAX_IMAGE_DIM, 0, 1));
29400 }
29401 static get MAX_AREA() {
29402 this._hasMaxArea = true;
29403 return shadow(this, "MAX_AREA", this._guessMax(ImageResizer._goodSquareLength, this.MAX_DIM, MAX_ERROR, 0) ** 2);
29404 }
29405 static set MAX_AREA(area) {
29406 if (area >= 0) {
29407 this._hasMaxArea = true;
29408 shadow(this, "MAX_AREA", area);
29409 }
29410 }
29411 static setMaxArea(area) {
29412 if (!this._hasMaxArea) {
29413 this.MAX_AREA = area >> 2;
29414 }
29415 }
29416 static _areGoodDims(width, height) {
29417 try {
29418 const canvas = new OffscreenCanvas(width, height);
29419 const ctx = canvas.getContext("2d");
29420 ctx.fillRect(0, 0, 1, 1);
29421 const opacity = ctx.getImageData(0, 0, 1, 1).data[3];
29422 canvas.width = canvas.height = 1;
29423 return opacity !== 0;
29424 } catch {
29425 return false;
29426 }
29427 }
29428 static _guessMax(start, end, tolerance, defaultHeight) {
29429 while (start + tolerance + 1 < end) {
29430 const middle = Math.floor((start + end) / 2);
29431 const height = defaultHeight || middle;
29432 if (this._areGoodDims(middle, height)) {
29433 start = middle;
29434 } else {
29435 end = middle;
29436 }
29437 }
29438 return start;
29439 }
29440 static async createImage(imgData, isMask = false) {
29441 return new ImageResizer(imgData, isMask)._createImage();
29442 }
29443 async _createImage() {
29444 const data = this._encodeBMP();
29445 const blob = new Blob([data.buffer], {
29446 type: "image/bmp"
29447 });
29448 const bitmapPromise = createImageBitmap(blob);
29449 const {
29450 MAX_AREA,
29451 MAX_DIM
29452 } = ImageResizer;
29453 const {
29454 _imgData: imgData
29455 } = this;
29456 const {
29457 width,
29458 height
29459 } = imgData;
29460 const minFactor = Math.max(width / MAX_DIM, height / MAX_DIM, Math.sqrt(width * height / MAX_AREA));
29461 const firstFactor = Math.max(minFactor, 2);
29462 const factor = Math.round(10 * (minFactor + 1.25)) / 10 / firstFactor;
29463 const N = Math.floor(Math.log2(factor));
29464 const steps = new Array(N + 2).fill(2);
29465 steps[0] = firstFactor;
29466 steps.splice(-1, 1, factor / (1 << N));
29467 let newWidth = width;
29468 let newHeight = height;
29469 let bitmap = await bitmapPromise;
29470 for (const step of steps) {
29471 const prevWidth = newWidth;
29472 const prevHeight = newHeight;
29473 newWidth = Math.floor(newWidth / step) - 1;
29474 newHeight = Math.floor(newHeight / step) - 1;
29475 const canvas = new OffscreenCanvas(newWidth, newHeight);
29476 const ctx = canvas.getContext("2d");
29477 ctx.drawImage(bitmap, 0, 0, prevWidth, prevHeight, 0, 0, newWidth, newHeight);
29478 bitmap = canvas.transferToImageBitmap();
29479 }
29480 imgData.data = null;
29481 imgData.bitmap = bitmap;
29482 imgData.width = newWidth;
29483 imgData.height = newHeight;
29484 return imgData;
29485 }
29486 _encodeBMP() {
29487 const {
29488 width,
29489 height,
29490 kind
29491 } = this._imgData;
29492 let data = this._imgData.data;
29493 let bitPerPixel;
29494 let colorTable = new Uint8Array(0);
29495 let maskTable = colorTable;
29496 let compression = 0;
29497 switch (kind) {
29498 case ImageKind.GRAYSCALE_1BPP:
29499 {
29500 bitPerPixel = 1;
29501 colorTable = new Uint8Array(this._isMask ? [255, 255, 255, 255, 0, 0, 0, 0] : [0, 0, 0, 0, 255, 255, 255, 255]);
29502 const rowLen = width + 7 >> 3;
29503 const rowSize = rowLen + 3 & -4;
29504 if (rowLen !== rowSize) {
29505 const newData = new Uint8Array(rowSize * height);
29506 let k = 0;
29507 for (let i = 0, ii = height * rowLen; i < ii; i += rowLen, k += rowSize) {
29508 newData.set(data.subarray(i, i + rowLen), k);
29509 }
29510 data = newData;
29511 }
29512 break;
29513 }
29514 case ImageKind.RGB_24BPP:
29515 {
29516 bitPerPixel = 24;
29517 if (width & 3) {
29518 const rowLen = 3 * width;
29519 const rowSize = rowLen + 3 & -4;
29520 const extraLen = rowSize - rowLen;
29521 const newData = new Uint8Array(rowSize * height);
29522 let k = 0;
29523 for (let i = 0, ii = height * rowLen; i < ii; i += rowLen) {
29524 const row = data.subarray(i, i + rowLen);
29525 for (let j = 0; j < rowLen; j += 3) {
29526 newData[k++] = row[j + 2];
29527 newData[k++] = row[j + 1];
29528 newData[k++] = row[j];
29529 }
29530 k += extraLen;
29531 }
29532 data = newData;
29533 } else {
29534 for (let i = 0, ii = data.length; i < ii; i += 3) {
29535 const tmp = data[i];
29536 data[i] = data[i + 2];
29537 data[i + 2] = tmp;
29538 }
29539 }
29540 break;
29541 }
29542 case ImageKind.RGBA_32BPP:
29543 bitPerPixel = 32;
29544 compression = 3;
29545 maskTable = new Uint8Array(4 + 4 + 4 + 4 + 52);
29546 const view = new DataView(maskTable.buffer);
29547 if (FeatureTest.isLittleEndian) {
29548 view.setUint32(0, 0x000000ff, true);
29549 view.setUint32(4, 0x0000ff00, true);
29550 view.setUint32(8, 0x00ff0000, true);
29551 view.setUint32(12, 0xff000000, true);
29552 } else {
29553 view.setUint32(0, 0xff000000, true);
29554 view.setUint32(4, 0x00ff0000, true);
29555 view.setUint32(8, 0x0000ff00, true);
29556 view.setUint32(12, 0x000000ff, true);
29557 }
29558 break;
29559 default:
29560 throw new Error("invalid format");
29561 }
29562 let i = 0;
29563 const headerLength = 40 + maskTable.length;
29564 const fileLength = 14 + headerLength + colorTable.length + data.length;
29565 const bmpData = new Uint8Array(fileLength);
29566 const view = new DataView(bmpData.buffer);
29567 view.setUint16(i, 0x4d42, true);
29568 i += 2;
29569 view.setUint32(i, fileLength, true);
29570 i += 4;
29571 view.setUint32(i, 0, true);
29572 i += 4;
29573 view.setUint32(i, 14 + headerLength + colorTable.length, true);
29574 i += 4;
29575 view.setUint32(i, headerLength, true);
29576 i += 4;
29577 view.setInt32(i, width, true);
29578 i += 4;
29579 view.setInt32(i, -height, true);
29580 i += 4;
29581 view.setUint16(i, 1, true);
29582 i += 2;
29583 view.setUint16(i, bitPerPixel, true);
29584 i += 2;
29585 view.setUint32(i, compression, true);
29586 i += 4;
29587 view.setUint32(i, 0, true);
29588 i += 4;
29589 view.setInt32(i, 0, true);
29590 i += 4;
29591 view.setInt32(i, 0, true);
29592 i += 4;
29593 view.setUint32(i, colorTable.length / 4, true);
29594 i += 4;
29595 view.setUint32(i, 0, true);
29596 i += 4;
29597 bmpData.set(maskTable, i);
29598 i += maskTable.length;
29599 bmpData.set(colorTable, i);
29600 i += colorTable.length;
29601 bmpData.set(data, i);
29602 return bmpData;
29603 }
29604}
29605ImageResizer._goodSquareLength = MIN_IMAGE_DIM;
29606
29607;// CONCATENATED MODULE: ./src/shared/murmurhash3.js
29608const SEED = 0xc3d2e1f0;
29609const MASK_HIGH = 0xffff0000;
29610const MASK_LOW = 0xffff;
29611class MurmurHash3_64 {
29612 constructor(seed) {
29613 this.h1 = seed ? seed & 0xffffffff : SEED;
29614 this.h2 = seed ? seed & 0xffffffff : SEED;
29615 }
29616 update(input) {
29617 let data, length;
29618 if (typeof input === "string") {
29619 data = new Uint8Array(input.length * 2);
29620 length = 0;
29621 for (let i = 0, ii = input.length; i < ii; i++) {
29622 const code = input.charCodeAt(i);
29623 if (code <= 0xff) {
29624 data[length++] = code;
29625 } else {
29626 data[length++] = code >>> 8;
29627 data[length++] = code & 0xff;
29628 }
29629 }
29630 } else if (ArrayBuffer.isView(input)) {
29631 data = input.slice();
29632 length = data.byteLength;
29633 } else {
29634 throw new Error("Invalid data format, must be a string or TypedArray.");
29635 }
29636 const blockCounts = length >> 2;
29637 const tailLength = length - blockCounts * 4;
29638 const dataUint32 = new Uint32Array(data.buffer, 0, blockCounts);
29639 let k1 = 0,
29640 k2 = 0;
29641 let h1 = this.h1,
29642 h2 = this.h2;
29643 const C1 = 0xcc9e2d51,
29644 C2 = 0x1b873593;
29645 const C1_LOW = C1 & MASK_LOW,
29646 C2_LOW = C2 & MASK_LOW;
29647 for (let i = 0; i < blockCounts; i++) {
29648 if (i & 1) {
29649 k1 = dataUint32[i];
29650 k1 = k1 * C1 & MASK_HIGH | k1 * C1_LOW & MASK_LOW;
29651 k1 = k1 << 15 | k1 >>> 17;
29652 k1 = k1 * C2 & MASK_HIGH | k1 * C2_LOW & MASK_LOW;
29653 h1 ^= k1;
29654 h1 = h1 << 13 | h1 >>> 19;
29655 h1 = h1 * 5 + 0xe6546b64;
29656 } else {
29657 k2 = dataUint32[i];
29658 k2 = k2 * C1 & MASK_HIGH | k2 * C1_LOW & MASK_LOW;
29659 k2 = k2 << 15 | k2 >>> 17;
29660 k2 = k2 * C2 & MASK_HIGH | k2 * C2_LOW & MASK_LOW;
29661 h2 ^= k2;
29662 h2 = h2 << 13 | h2 >>> 19;
29663 h2 = h2 * 5 + 0xe6546b64;
29664 }
29665 }
29666 k1 = 0;
29667 switch (tailLength) {
29668 case 3:
29669 k1 ^= data[blockCounts * 4 + 2] << 16;
29670 case 2:
29671 k1 ^= data[blockCounts * 4 + 1] << 8;
29672 case 1:
29673 k1 ^= data[blockCounts * 4];
29674 k1 = k1 * C1 & MASK_HIGH | k1 * C1_LOW & MASK_LOW;
29675 k1 = k1 << 15 | k1 >>> 17;
29676 k1 = k1 * C2 & MASK_HIGH | k1 * C2_LOW & MASK_LOW;
29677 if (blockCounts & 1) {
29678 h1 ^= k1;
29679 } else {
29680 h2 ^= k1;
29681 }
29682 }
29683 this.h1 = h1;
29684 this.h2 = h2;
29685 }
29686 hexdigest() {
29687 let h1 = this.h1,
29688 h2 = this.h2;
29689 h1 ^= h2 >>> 1;
29690 h1 = h1 * 0xed558ccd & MASK_HIGH | h1 * 0x8ccd & MASK_LOW;
29691 h2 = h2 * 0xff51afd7 & MASK_HIGH | ((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16;
29692 h1 ^= h2 >>> 1;
29693 h1 = h1 * 0x1a85ec53 & MASK_HIGH | h1 * 0xec53 & MASK_LOW;
29694 h2 = h2 * 0xc4ceb9fe & MASK_HIGH | ((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16;
29695 h1 ^= h2 >>> 1;
29696 return (h1 >>> 0).toString(16).padStart(8, "0") + (h2 >>> 0).toString(16).padStart(8, "0");
29697 }
29698}
29699
29700;// CONCATENATED MODULE: ./src/core/operator_list.js
29701
29702function addState(parentState, pattern, checkFn, iterateFn, processFn) {
29703 let state = parentState;
29704 for (let i = 0, ii = pattern.length - 1; i < ii; i++) {
29705 const item = pattern[i];
29706 state = state[item] ||= [];
29707 }
29708 state[pattern.at(-1)] = {
29709 checkFn,
29710 iterateFn,
29711 processFn
29712 };
29713}
29714const InitialState = [];
29715addState(InitialState, [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore], null, function iterateInlineImageGroup(context, i) {
29716 const fnArray = context.fnArray;
29717 const iFirstSave = context.iCurr - 3;
29718 const pos = (i - iFirstSave) % 4;
29719 switch (pos) {
29720 case 0:
29721 return fnArray[i] === OPS.save;
29722 case 1:
29723 return fnArray[i] === OPS.transform;
29724 case 2:
29725 return fnArray[i] === OPS.paintInlineImageXObject;
29726 case 3:
29727 return fnArray[i] === OPS.restore;
29728 }
29729 throw new Error(`iterateInlineImageGroup - invalid pos: ${pos}`);
29730}, function foundInlineImageGroup(context, i) {
29731 const MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
29732 const MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
29733 const MAX_WIDTH = 1000;
29734 const IMAGE_PADDING = 1;
29735 const fnArray = context.fnArray,
29736 argsArray = context.argsArray;
29737 const curr = context.iCurr;
29738 const iFirstSave = curr - 3;
29739 const iFirstTransform = curr - 2;
29740 const iFirstPIIXO = curr - 1;
29741 const count = Math.min(Math.floor((i - iFirstSave) / 4), MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
29742 if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
29743 return i - (i - iFirstSave) % 4;
29744 }
29745 let maxX = 0;
29746 const map = [];
29747 let maxLineHeight = 0;
29748 let currentX = IMAGE_PADDING,
29749 currentY = IMAGE_PADDING;
29750 for (let q = 0; q < count; q++) {
29751 const transform = argsArray[iFirstTransform + (q << 2)];
29752 const img = argsArray[iFirstPIIXO + (q << 2)][0];
29753 if (currentX + img.width > MAX_WIDTH) {
29754 maxX = Math.max(maxX, currentX);
29755 currentY += maxLineHeight + 2 * IMAGE_PADDING;
29756 currentX = 0;
29757 maxLineHeight = 0;
29758 }
29759 map.push({
29760 transform,
29761 x: currentX,
29762 y: currentY,
29763 w: img.width,
29764 h: img.height
29765 });
29766 currentX += img.width + 2 * IMAGE_PADDING;
29767 maxLineHeight = Math.max(maxLineHeight, img.height);
29768 }
29769 const imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
29770 const imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
29771 const imgData = new Uint8Array(imgWidth * imgHeight * 4);
29772 const imgRowSize = imgWidth << 2;
29773 for (let q = 0; q < count; q++) {
29774 const data = argsArray[iFirstPIIXO + (q << 2)][0].data;
29775 const rowSize = map[q].w << 2;
29776 let dataOffset = 0;
29777 let offset = map[q].x + map[q].y * imgWidth << 2;
29778 imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
29779 for (let k = 0, kk = map[q].h; k < kk; k++) {
29780 imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
29781 dataOffset += rowSize;
29782 offset += imgRowSize;
29783 }
29784 imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
29785 while (offset >= 0) {
29786 data[offset - 4] = data[offset];
29787 data[offset - 3] = data[offset + 1];
29788 data[offset - 2] = data[offset + 2];
29789 data[offset - 1] = data[offset + 3];
29790 data[offset + rowSize] = data[offset + rowSize - 4];
29791 data[offset + rowSize + 1] = data[offset + rowSize - 3];
29792 data[offset + rowSize + 2] = data[offset + rowSize - 2];
29793 data[offset + rowSize + 3] = data[offset + rowSize - 1];
29794 offset -= imgRowSize;
29795 }
29796 }
29797 const img = {
29798 width: imgWidth,
29799 height: imgHeight
29800 };
29801 if (context.isOffscreenCanvasSupported) {
29802 const canvas = new OffscreenCanvas(imgWidth, imgHeight);
29803 const ctx = canvas.getContext("2d");
29804 ctx.putImageData(new ImageData(new Uint8ClampedArray(imgData.buffer), imgWidth, imgHeight), 0, 0);
29805 img.bitmap = canvas.transferToImageBitmap();
29806 img.data = null;
29807 } else {
29808 img.kind = ImageKind.RGBA_32BPP;
29809 img.data = imgData;
29810 }
29811 fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
29812 argsArray.splice(iFirstSave, count * 4, [img, map]);
29813 return iFirstSave + 1;
29814});
29815addState(InitialState, [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore], null, function iterateImageMaskGroup(context, i) {
29816 const fnArray = context.fnArray;
29817 const iFirstSave = context.iCurr - 3;
29818 const pos = (i - iFirstSave) % 4;
29819 switch (pos) {
29820 case 0:
29821 return fnArray[i] === OPS.save;
29822 case 1:
29823 return fnArray[i] === OPS.transform;
29824 case 2:
29825 return fnArray[i] === OPS.paintImageMaskXObject;
29826 case 3:
29827 return fnArray[i] === OPS.restore;
29828 }
29829 throw new Error(`iterateImageMaskGroup - invalid pos: ${pos}`);
29830}, function foundImageMaskGroup(context, i) {
29831 const MIN_IMAGES_IN_MASKS_BLOCK = 10;
29832 const MAX_IMAGES_IN_MASKS_BLOCK = 100;
29833 const MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
29834 const fnArray = context.fnArray,
29835 argsArray = context.argsArray;
29836 const curr = context.iCurr;
29837 const iFirstSave = curr - 3;
29838 const iFirstTransform = curr - 2;
29839 const iFirstPIMXO = curr - 1;
29840 let count = Math.floor((i - iFirstSave) / 4);
29841 if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
29842 return i - (i - iFirstSave) % 4;
29843 }
29844 let isSameImage = false;
29845 let iTransform, transformArgs;
29846 const firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
29847 const firstTransformArg0 = argsArray[iFirstTransform][0],
29848 firstTransformArg1 = argsArray[iFirstTransform][1],
29849 firstTransformArg2 = argsArray[iFirstTransform][2],
29850 firstTransformArg3 = argsArray[iFirstTransform][3];
29851 if (firstTransformArg1 === firstTransformArg2) {
29852 isSameImage = true;
29853 iTransform = iFirstTransform + 4;
29854 let iPIMXO = iFirstPIMXO + 4;
29855 for (let q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
29856 transformArgs = argsArray[iTransform];
29857 if (argsArray[iPIMXO][0] !== firstPIMXOArg0 || transformArgs[0] !== firstTransformArg0 || transformArgs[1] !== firstTransformArg1 || transformArgs[2] !== firstTransformArg2 || transformArgs[3] !== firstTransformArg3) {
29858 if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
29859 isSameImage = false;
29860 } else {
29861 count = q;
29862 }
29863 break;
29864 }
29865 }
29866 }
29867 if (isSameImage) {
29868 count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
29869 const positions = new Float32Array(count * 2);
29870 iTransform = iFirstTransform;
29871 for (let q = 0; q < count; q++, iTransform += 4) {
29872 transformArgs = argsArray[iTransform];
29873 positions[q << 1] = transformArgs[4];
29874 positions[(q << 1) + 1] = transformArgs[5];
29875 }
29876 fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
29877 argsArray.splice(iFirstSave, count * 4, [firstPIMXOArg0, firstTransformArg0, firstTransformArg1, firstTransformArg2, firstTransformArg3, positions]);
29878 } else {
29879 count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
29880 const images = [];
29881 for (let q = 0; q < count; q++) {
29882 transformArgs = argsArray[iFirstTransform + (q << 2)];
29883 const maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
29884 images.push({
29885 data: maskParams.data,
29886 width: maskParams.width,
29887 height: maskParams.height,
29888 interpolate: maskParams.interpolate,
29889 count: maskParams.count,
29890 transform: transformArgs
29891 });
29892 }
29893 fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
29894 argsArray.splice(iFirstSave, count * 4, [images]);
29895 }
29896 return iFirstSave + 1;
29897});
29898addState(InitialState, [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore], function (context) {
29899 const argsArray = context.argsArray;
29900 const iFirstTransform = context.iCurr - 2;
29901 return argsArray[iFirstTransform][1] === 0 && argsArray[iFirstTransform][2] === 0;
29902}, function iterateImageGroup(context, i) {
29903 const fnArray = context.fnArray,
29904 argsArray = context.argsArray;
29905 const iFirstSave = context.iCurr - 3;
29906 const pos = (i - iFirstSave) % 4;
29907 switch (pos) {
29908 case 0:
29909 return fnArray[i] === OPS.save;
29910 case 1:
29911 if (fnArray[i] !== OPS.transform) {
29912 return false;
29913 }
29914 const iFirstTransform = context.iCurr - 2;
29915 const firstTransformArg0 = argsArray[iFirstTransform][0];
29916 const firstTransformArg3 = argsArray[iFirstTransform][3];
29917 if (argsArray[i][0] !== firstTransformArg0 || argsArray[i][1] !== 0 || argsArray[i][2] !== 0 || argsArray[i][3] !== firstTransformArg3) {
29918 return false;
29919 }
29920 return true;
29921 case 2:
29922 if (fnArray[i] !== OPS.paintImageXObject) {
29923 return false;
29924 }
29925 const iFirstPIXO = context.iCurr - 1;
29926 const firstPIXOArg0 = argsArray[iFirstPIXO][0];
29927 if (argsArray[i][0] !== firstPIXOArg0) {
29928 return false;
29929 }
29930 return true;
29931 case 3:
29932 return fnArray[i] === OPS.restore;
29933 }
29934 throw new Error(`iterateImageGroup - invalid pos: ${pos}`);
29935}, function (context, i) {
29936 const MIN_IMAGES_IN_BLOCK = 3;
29937 const MAX_IMAGES_IN_BLOCK = 1000;
29938 const fnArray = context.fnArray,
29939 argsArray = context.argsArray;
29940 const curr = context.iCurr;
29941 const iFirstSave = curr - 3;
29942 const iFirstTransform = curr - 2;
29943 const iFirstPIXO = curr - 1;
29944 const firstPIXOArg0 = argsArray[iFirstPIXO][0];
29945 const firstTransformArg0 = argsArray[iFirstTransform][0];
29946 const firstTransformArg3 = argsArray[iFirstTransform][3];
29947 const count = Math.min(Math.floor((i - iFirstSave) / 4), MAX_IMAGES_IN_BLOCK);
29948 if (count < MIN_IMAGES_IN_BLOCK) {
29949 return i - (i - iFirstSave) % 4;
29950 }
29951 const positions = new Float32Array(count * 2);
29952 let iTransform = iFirstTransform;
29953 for (let q = 0; q < count; q++, iTransform += 4) {
29954 const transformArgs = argsArray[iTransform];
29955 positions[q << 1] = transformArgs[4];
29956 positions[(q << 1) + 1] = transformArgs[5];
29957 }
29958 const args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3, positions];
29959 fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
29960 argsArray.splice(iFirstSave, count * 4, args);
29961 return iFirstSave + 1;
29962});
29963addState(InitialState, [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText], null, function iterateShowTextGroup(context, i) {
29964 const fnArray = context.fnArray,
29965 argsArray = context.argsArray;
29966 const iFirstSave = context.iCurr - 4;
29967 const pos = (i - iFirstSave) % 5;
29968 switch (pos) {
29969 case 0:
29970 return fnArray[i] === OPS.beginText;
29971 case 1:
29972 return fnArray[i] === OPS.setFont;
29973 case 2:
29974 return fnArray[i] === OPS.setTextMatrix;
29975 case 3:
29976 if (fnArray[i] !== OPS.showText) {
29977 return false;
29978 }
29979 const iFirstSetFont = context.iCurr - 3;
29980 const firstSetFontArg0 = argsArray[iFirstSetFont][0];
29981 const firstSetFontArg1 = argsArray[iFirstSetFont][1];
29982 if (argsArray[i][0] !== firstSetFontArg0 || argsArray[i][1] !== firstSetFontArg1) {
29983 return false;
29984 }
29985 return true;
29986 case 4:
29987 return fnArray[i] === OPS.endText;
29988 }
29989 throw new Error(`iterateShowTextGroup - invalid pos: ${pos}`);
29990}, function (context, i) {
29991 const MIN_CHARS_IN_BLOCK = 3;
29992 const MAX_CHARS_IN_BLOCK = 1000;
29993 const fnArray = context.fnArray,
29994 argsArray = context.argsArray;
29995 const curr = context.iCurr;
29996 const iFirstBeginText = curr - 4;
29997 const iFirstSetFont = curr - 3;
29998 const iFirstSetTextMatrix = curr - 2;
29999 const iFirstShowText = curr - 1;
30000 const iFirstEndText = curr;
30001 const firstSetFontArg0 = argsArray[iFirstSetFont][0];
30002 const firstSetFontArg1 = argsArray[iFirstSetFont][1];
30003 let count = Math.min(Math.floor((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
30004 if (count < MIN_CHARS_IN_BLOCK) {
30005 return i - (i - iFirstBeginText) % 5;
30006 }
30007 let iFirst = iFirstBeginText;
30008 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) {
30009 count++;
30010 iFirst -= 5;
30011 }
30012 let iEndText = iFirst + 4;
30013 for (let q = 1; q < count; q++) {
30014 fnArray.splice(iEndText, 3);
30015 argsArray.splice(iEndText, 3);
30016 iEndText += 2;
30017 }
30018 return iEndText + 1;
30019});
30020class NullOptimizer {
30021 constructor(queue) {
30022 this.queue = queue;
30023 }
30024 _optimize() {}
30025 push(fn, args) {
30026 this.queue.fnArray.push(fn);
30027 this.queue.argsArray.push(args);
30028 this._optimize();
30029 }
30030 flush() {}
30031 reset() {}
30032}
30033class QueueOptimizer extends NullOptimizer {
30034 constructor(queue) {
30035 super(queue);
30036 this.state = null;
30037 this.context = {
30038 iCurr: 0,
30039 fnArray: queue.fnArray,
30040 argsArray: queue.argsArray,
30041 isOffscreenCanvasSupported: false
30042 };
30043 this.match = null;
30044 this.lastProcessed = 0;
30045 }
30046 set isOffscreenCanvasSupported(value) {
30047 this.context.isOffscreenCanvasSupported = value;
30048 }
30049 _optimize() {
30050 const fnArray = this.queue.fnArray;
30051 let i = this.lastProcessed,
30052 ii = fnArray.length;
30053 let state = this.state;
30054 let match = this.match;
30055 if (!state && !match && i + 1 === ii && !InitialState[fnArray[i]]) {
30056 this.lastProcessed = ii;
30057 return;
30058 }
30059 const context = this.context;
30060 while (i < ii) {
30061 if (match) {
30062 const iterate = (0, match.iterateFn)(context, i);
30063 if (iterate) {
30064 i++;
30065 continue;
30066 }
30067 i = (0, match.processFn)(context, i + 1);
30068 ii = fnArray.length;
30069 match = null;
30070 state = null;
30071 if (i >= ii) {
30072 break;
30073 }
30074 }
30075 state = (state || InitialState)[fnArray[i]];
30076 if (!state || Array.isArray(state)) {
30077 i++;
30078 continue;
30079 }
30080 context.iCurr = i;
30081 i++;
30082 if (state.checkFn && !(0, state.checkFn)(context)) {
30083 state = null;
30084 continue;
30085 }
30086 match = state;
30087 state = null;
30088 }
30089 this.state = state;
30090 this.match = match;
30091 this.lastProcessed = i;
30092 }
30093 flush() {
30094 while (this.match) {
30095 const length = this.queue.fnArray.length;
30096 this.lastProcessed = (0, this.match.processFn)(this.context, length);
30097 this.match = null;
30098 this.state = null;
30099 this._optimize();
30100 }
30101 }
30102 reset() {
30103 this.state = null;
30104 this.match = null;
30105 this.lastProcessed = 0;
30106 }
30107}
30108class OperatorList {
30109 static CHUNK_SIZE = 1000;
30110 static CHUNK_SIZE_ABOUT = this.CHUNK_SIZE - 5;
30111 constructor(intent = 0, streamSink) {
30112 this._streamSink = streamSink;
30113 this.fnArray = [];
30114 this.argsArray = [];
30115 this.optimizer = streamSink && !(intent & RenderingIntentFlag.OPLIST) ? new QueueOptimizer(this) : new NullOptimizer(this);
30116 this.dependencies = new Set();
30117 this._totalLength = 0;
30118 this.weight = 0;
30119 this._resolved = streamSink ? null : Promise.resolve();
30120 }
30121 set isOffscreenCanvasSupported(value) {
30122 this.optimizer.isOffscreenCanvasSupported = value;
30123 }
30124 get length() {
30125 return this.argsArray.length;
30126 }
30127 get ready() {
30128 return this._resolved || this._streamSink.ready;
30129 }
30130 get totalLength() {
30131 return this._totalLength + this.length;
30132 }
30133 addOp(fn, args) {
30134 this.optimizer.push(fn, args);
30135 this.weight++;
30136 if (this._streamSink) {
30137 if (this.weight >= OperatorList.CHUNK_SIZE) {
30138 this.flush();
30139 } else if (this.weight >= OperatorList.CHUNK_SIZE_ABOUT && (fn === OPS.restore || fn === OPS.endText)) {
30140 this.flush();
30141 }
30142 }
30143 }
30144 addImageOps(fn, args, optionalContent) {
30145 if (optionalContent !== undefined) {
30146 this.addOp(OPS.beginMarkedContentProps, ["OC", optionalContent]);
30147 }
30148 this.addOp(fn, args);
30149 if (optionalContent !== undefined) {
30150 this.addOp(OPS.endMarkedContent, []);
30151 }
30152 }
30153 addDependency(dependency) {
30154 if (this.dependencies.has(dependency)) {
30155 return;
30156 }
30157 this.dependencies.add(dependency);
30158 this.addOp(OPS.dependency, [dependency]);
30159 }
30160 addDependencies(dependencies) {
30161 for (const dependency of dependencies) {
30162 this.addDependency(dependency);
30163 }
30164 }
30165 addOpList(opList) {
30166 if (!(opList instanceof OperatorList)) {
30167 warn('addOpList - ignoring invalid "opList" parameter.');
30168 return;
30169 }
30170 for (const dependency of opList.dependencies) {
30171 this.dependencies.add(dependency);
30172 }
30173 for (let i = 0, ii = opList.length; i < ii; i++) {
30174 this.addOp(opList.fnArray[i], opList.argsArray[i]);
30175 }
30176 }
30177 getIR() {
30178 return {
30179 fnArray: this.fnArray,
30180 argsArray: this.argsArray,
30181 length: this.length
30182 };
30183 }
30184 get _transfers() {
30185 const transfers = [];
30186 const {
30187 fnArray,
30188 argsArray,
30189 length
30190 } = this;
30191 for (let i = 0; i < length; i++) {
30192 switch (fnArray[i]) {
30193 case OPS.paintInlineImageXObject:
30194 case OPS.paintInlineImageXObjectGroup:
30195 case OPS.paintImageMaskXObject:
30196 const arg = argsArray[i][0];
30197 if (!arg.cached && arg.data?.buffer instanceof ArrayBuffer) {
30198 transfers.push(arg.data.buffer);
30199 }
30200 break;
30201 }
30202 }
30203 return transfers;
30204 }
30205 flush(lastChunk = false, separateAnnots = null) {
30206 this.optimizer.flush();
30207 const length = this.length;
30208 this._totalLength += length;
30209 this._streamSink.enqueue({
30210 fnArray: this.fnArray,
30211 argsArray: this.argsArray,
30212 lastChunk,
30213 separateAnnots,
30214 length
30215 }, 1, this._transfers);
30216 this.dependencies.clear();
30217 this.fnArray.length = 0;
30218 this.argsArray.length = 0;
30219 this.weight = 0;
30220 this.optimizer.reset();
30221 }
30222}
30223
30224;// CONCATENATED MODULE: ./src/core/image.js
30225
30226
30227
30228
30229
30230
30231
30232
30233
30234function decodeAndClamp(value, addend, coefficient, max) {
30235 value = addend + value * coefficient;
30236 if (value < 0) {
30237 value = 0;
30238 } else if (value > max) {
30239 value = max;
30240 }
30241 return value;
30242}
30243function resizeImageMask(src, bpc, w1, h1, w2, h2) {
30244 const length = w2 * h2;
30245 let dest;
30246 if (bpc <= 8) {
30247 dest = new Uint8Array(length);
30248 } else if (bpc <= 16) {
30249 dest = new Uint16Array(length);
30250 } else {
30251 dest = new Uint32Array(length);
30252 }
30253 const xRatio = w1 / w2;
30254 const yRatio = h1 / h2;
30255 let i,
30256 j,
30257 py,
30258 newIndex = 0,
30259 oldIndex;
30260 const xScaled = new Uint16Array(w2);
30261 const w1Scanline = w1;
30262 for (i = 0; i < w2; i++) {
30263 xScaled[i] = Math.floor(i * xRatio);
30264 }
30265 for (i = 0; i < h2; i++) {
30266 py = Math.floor(i * yRatio) * w1Scanline;
30267 for (j = 0; j < w2; j++) {
30268 oldIndex = py + xScaled[j];
30269 dest[newIndex++] = src[oldIndex];
30270 }
30271 }
30272 return dest;
30273}
30274class PDFImage {
30275 constructor({
30276 xref,
30277 res,
30278 image,
30279 isInline = false,
30280 smask = null,
30281 mask = null,
30282 isMask = false,
30283 pdfFunctionFactory,
30284 localColorSpaceCache
30285 }) {
30286 this.image = image;
30287 const dict = image.dict;
30288 const filter = dict.get("F", "Filter");
30289 let filterName;
30290 if (filter instanceof Name) {
30291 filterName = filter.name;
30292 } else if (Array.isArray(filter)) {
30293 const filterZero = xref.fetchIfRef(filter[0]);
30294 if (filterZero instanceof Name) {
30295 filterName = filterZero.name;
30296 }
30297 }
30298 switch (filterName) {
30299 case "JPXDecode":
30300 const jpxImage = new JpxImage();
30301 jpxImage.parseImageProperties(image.stream);
30302 image.stream.reset();
30303 image.width = jpxImage.width;
30304 image.height = jpxImage.height;
30305 image.bitsPerComponent = jpxImage.bitsPerComponent;
30306 image.numComps = jpxImage.componentsCount;
30307 break;
30308 case "JBIG2Decode":
30309 image.bitsPerComponent = 1;
30310 image.numComps = 1;
30311 break;
30312 }
30313 let width = dict.get("W", "Width");
30314 let height = dict.get("H", "Height");
30315 if (Number.isInteger(image.width) && image.width > 0 && Number.isInteger(image.height) && image.height > 0 && (image.width !== width || image.height !== height)) {
30316 warn("PDFImage - using the Width/Height of the image data, " + "rather than the image dictionary.");
30317 width = image.width;
30318 height = image.height;
30319 }
30320 if (width < 1 || height < 1) {
30321 throw new FormatError(`Invalid image width: ${width} or height: ${height}`);
30322 }
30323 this.width = width;
30324 this.height = height;
30325 this.interpolate = dict.get("I", "Interpolate");
30326 this.imageMask = dict.get("IM", "ImageMask") || false;
30327 this.matte = dict.get("Matte") || false;
30328 let bitsPerComponent = image.bitsPerComponent;
30329 if (!bitsPerComponent) {
30330 bitsPerComponent = dict.get("BPC", "BitsPerComponent");
30331 if (!bitsPerComponent) {
30332 if (this.imageMask) {
30333 bitsPerComponent = 1;
30334 } else {
30335 throw new FormatError(`Bits per component missing in image: ${this.imageMask}`);
30336 }
30337 }
30338 }
30339 this.bpc = bitsPerComponent;
30340 if (!this.imageMask) {
30341 let colorSpace = dict.getRaw("CS") || dict.getRaw("ColorSpace");
30342 if (!colorSpace) {
30343 info("JPX images (which do not require color spaces)");
30344 switch (image.numComps) {
30345 case 1:
30346 colorSpace = Name.get("DeviceGray");
30347 break;
30348 case 3:
30349 colorSpace = Name.get("DeviceRGB");
30350 break;
30351 case 4:
30352 colorSpace = Name.get("DeviceCMYK");
30353 break;
30354 default:
30355 throw new Error(`JPX images with ${image.numComps} color components not supported.`);
30356 }
30357 }
30358 this.colorSpace = ColorSpace.parse({
30359 cs: colorSpace,
30360 xref,
30361 resources: isInline ? res : null,
30362 pdfFunctionFactory,
30363 localColorSpaceCache
30364 });
30365 this.numComps = this.colorSpace.numComps;
30366 }
30367 this.decode = dict.getArray("D", "Decode");
30368 this.needsDecode = false;
30369 if (this.decode && (this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode, bitsPerComponent) || isMask && !ColorSpace.isDefaultDecode(this.decode, 1))) {
30370 this.needsDecode = true;
30371 const max = (1 << bitsPerComponent) - 1;
30372 this.decodeCoefficients = [];
30373 this.decodeAddends = [];
30374 const isIndexed = this.colorSpace?.name === "Indexed";
30375 for (let i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
30376 const dmin = this.decode[i];
30377 const dmax = this.decode[i + 1];
30378 this.decodeCoefficients[j] = isIndexed ? (dmax - dmin) / max : dmax - dmin;
30379 this.decodeAddends[j] = isIndexed ? dmin : max * dmin;
30380 }
30381 }
30382 if (smask) {
30383 this.smask = new PDFImage({
30384 xref,
30385 res,
30386 image: smask,
30387 isInline,
30388 pdfFunctionFactory,
30389 localColorSpaceCache
30390 });
30391 } else if (mask) {
30392 if (mask instanceof BaseStream) {
30393 const maskDict = mask.dict,
30394 imageMask = maskDict.get("IM", "ImageMask");
30395 if (!imageMask) {
30396 warn("Ignoring /Mask in image without /ImageMask.");
30397 } else {
30398 this.mask = new PDFImage({
30399 xref,
30400 res,
30401 image: mask,
30402 isInline,
30403 isMask: true,
30404 pdfFunctionFactory,
30405 localColorSpaceCache
30406 });
30407 }
30408 } else {
30409 this.mask = mask;
30410 }
30411 }
30412 }
30413 static async buildImage({
30414 xref,
30415 res,
30416 image,
30417 isInline = false,
30418 pdfFunctionFactory,
30419 localColorSpaceCache
30420 }) {
30421 const imageData = image;
30422 let smaskData = null;
30423 let maskData = null;
30424 const smask = image.dict.get("SMask");
30425 const mask = image.dict.get("Mask");
30426 if (smask) {
30427 if (smask instanceof BaseStream) {
30428 smaskData = smask;
30429 } else {
30430 warn("Unsupported /SMask format.");
30431 }
30432 } else if (mask) {
30433 if (mask instanceof BaseStream || Array.isArray(mask)) {
30434 maskData = mask;
30435 } else {
30436 warn("Unsupported /Mask format.");
30437 }
30438 }
30439 return new PDFImage({
30440 xref,
30441 res,
30442 image: imageData,
30443 isInline,
30444 smask: smaskData,
30445 mask: maskData,
30446 pdfFunctionFactory,
30447 localColorSpaceCache
30448 });
30449 }
30450 static createRawMask({
30451 imgArray,
30452 width,
30453 height,
30454 imageIsFromDecodeStream,
30455 inverseDecode,
30456 interpolate
30457 }) {
30458 const computedLength = (width + 7 >> 3) * height;
30459 const actualLength = imgArray.byteLength;
30460 const haveFullData = computedLength === actualLength;
30461 let data, i;
30462 if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
30463 data = imgArray;
30464 } else if (!inverseDecode) {
30465 data = new Uint8Array(imgArray);
30466 } else {
30467 data = new Uint8Array(computedLength);
30468 data.set(imgArray);
30469 data.fill(0xff, actualLength);
30470 }
30471 if (inverseDecode) {
30472 for (i = 0; i < actualLength; i++) {
30473 data[i] ^= 0xff;
30474 }
30475 }
30476 return {
30477 data,
30478 width,
30479 height,
30480 interpolate
30481 };
30482 }
30483 static async createMask({
30484 imgArray,
30485 width,
30486 height,
30487 imageIsFromDecodeStream,
30488 inverseDecode,
30489 interpolate,
30490 isOffscreenCanvasSupported = false
30491 }) {
30492 const isSingleOpaquePixel = width === 1 && height === 1 && inverseDecode === (imgArray.length === 0 || !!(imgArray[0] & 128));
30493 if (isSingleOpaquePixel) {
30494 return {
30495 isSingleOpaquePixel
30496 };
30497 }
30498 if (isOffscreenCanvasSupported) {
30499 if (ImageResizer.needsToBeResized(width, height)) {
30500 const data = new Uint8ClampedArray(width * height * 4);
30501 convertBlackAndWhiteToRGBA({
30502 src: imgArray,
30503 dest: data,
30504 width,
30505 height,
30506 nonBlackColor: 0,
30507 inverseDecode
30508 });
30509 return ImageResizer.createImage({
30510 kind: ImageKind.RGBA_32BPP,
30511 data,
30512 width,
30513 height,
30514 interpolate
30515 });
30516 }
30517 const canvas = new OffscreenCanvas(width, height);
30518 const ctx = canvas.getContext("2d");
30519 const imgData = ctx.createImageData(width, height);
30520 convertBlackAndWhiteToRGBA({
30521 src: imgArray,
30522 dest: imgData.data,
30523 width,
30524 height,
30525 nonBlackColor: 0,
30526 inverseDecode
30527 });
30528 ctx.putImageData(imgData, 0, 0);
30529 const bitmap = canvas.transferToImageBitmap();
30530 return {
30531 data: null,
30532 width,
30533 height,
30534 interpolate,
30535 bitmap
30536 };
30537 }
30538 return this.createRawMask({
30539 imgArray,
30540 width,
30541 height,
30542 inverseDecode,
30543 imageIsFromDecodeStream,
30544 interpolate
30545 });
30546 }
30547 get drawWidth() {
30548 return Math.max(this.width, this.smask?.width || 0, this.mask?.width || 0);
30549 }
30550 get drawHeight() {
30551 return Math.max(this.height, this.smask?.height || 0, this.mask?.height || 0);
30552 }
30553 decodeBuffer(buffer) {
30554 const bpc = this.bpc;
30555 const numComps = this.numComps;
30556 const decodeAddends = this.decodeAddends;
30557 const decodeCoefficients = this.decodeCoefficients;
30558 const max = (1 << bpc) - 1;
30559 let i, ii;
30560 if (bpc === 1) {
30561 for (i = 0, ii = buffer.length; i < ii; i++) {
30562 buffer[i] = +!buffer[i];
30563 }
30564 return;
30565 }
30566 let index = 0;
30567 for (i = 0, ii = this.width * this.height; i < ii; i++) {
30568 for (let j = 0; j < numComps; j++) {
30569 buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j], decodeCoefficients[j], max);
30570 index++;
30571 }
30572 }
30573 }
30574 getComponents(buffer) {
30575 const bpc = this.bpc;
30576 if (bpc === 8) {
30577 return buffer;
30578 }
30579 const width = this.width;
30580 const height = this.height;
30581 const numComps = this.numComps;
30582 const length = width * height * numComps;
30583 let bufferPos = 0;
30584 let output;
30585 if (bpc <= 8) {
30586 output = new Uint8Array(length);
30587 } else if (bpc <= 16) {
30588 output = new Uint16Array(length);
30589 } else {
30590 output = new Uint32Array(length);
30591 }
30592 const rowComps = width * numComps;
30593 const max = (1 << bpc) - 1;
30594 let i = 0,
30595 ii,
30596 buf;
30597 if (bpc === 1) {
30598 let mask, loop1End, loop2End;
30599 for (let j = 0; j < height; j++) {
30600 loop1End = i + (rowComps & ~7);
30601 loop2End = i + rowComps;
30602 while (i < loop1End) {
30603 buf = buffer[bufferPos++];
30604 output[i] = buf >> 7 & 1;
30605 output[i + 1] = buf >> 6 & 1;
30606 output[i + 2] = buf >> 5 & 1;
30607 output[i + 3] = buf >> 4 & 1;
30608 output[i + 4] = buf >> 3 & 1;
30609 output[i + 5] = buf >> 2 & 1;
30610 output[i + 6] = buf >> 1 & 1;
30611 output[i + 7] = buf & 1;
30612 i += 8;
30613 }
30614 if (i < loop2End) {
30615 buf = buffer[bufferPos++];
30616 mask = 128;
30617 while (i < loop2End) {
30618 output[i++] = +!!(buf & mask);
30619 mask >>= 1;
30620 }
30621 }
30622 }
30623 } else {
30624 let bits = 0;
30625 buf = 0;
30626 for (i = 0, ii = length; i < ii; ++i) {
30627 if (i % rowComps === 0) {
30628 buf = 0;
30629 bits = 0;
30630 }
30631 while (bits < bpc) {
30632 buf = buf << 8 | buffer[bufferPos++];
30633 bits += 8;
30634 }
30635 const remainingBits = bits - bpc;
30636 let value = buf >> remainingBits;
30637 if (value < 0) {
30638 value = 0;
30639 } else if (value > max) {
30640 value = max;
30641 }
30642 output[i] = value;
30643 buf &= (1 << remainingBits) - 1;
30644 bits = remainingBits;
30645 }
30646 }
30647 return output;
30648 }
30649 fillOpacity(rgbaBuf, width, height, actualHeight, image) {
30650 const smask = this.smask;
30651 const mask = this.mask;
30652 let alphaBuf, sw, sh, i, ii, j;
30653 if (smask) {
30654 sw = smask.width;
30655 sh = smask.height;
30656 alphaBuf = new Uint8ClampedArray(sw * sh);
30657 smask.fillGrayBuffer(alphaBuf);
30658 if (sw !== width || sh !== height) {
30659 alphaBuf = resizeImageMask(alphaBuf, smask.bpc, sw, sh, width, height);
30660 }
30661 } else if (mask) {
30662 if (mask instanceof PDFImage) {
30663 sw = mask.width;
30664 sh = mask.height;
30665 alphaBuf = new Uint8ClampedArray(sw * sh);
30666 mask.numComps = 1;
30667 mask.fillGrayBuffer(alphaBuf);
30668 for (i = 0, ii = sw * sh; i < ii; ++i) {
30669 alphaBuf[i] = 255 - alphaBuf[i];
30670 }
30671 if (sw !== width || sh !== height) {
30672 alphaBuf = resizeImageMask(alphaBuf, mask.bpc, sw, sh, width, height);
30673 }
30674 } else if (Array.isArray(mask)) {
30675 alphaBuf = new Uint8ClampedArray(width * height);
30676 const numComps = this.numComps;
30677 for (i = 0, ii = width * height; i < ii; ++i) {
30678 let opacity = 0;
30679 const imageOffset = i * numComps;
30680 for (j = 0; j < numComps; ++j) {
30681 const color = image[imageOffset + j];
30682 const maskOffset = j * 2;
30683 if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
30684 opacity = 255;
30685 break;
30686 }
30687 }
30688 alphaBuf[i] = opacity;
30689 }
30690 } else {
30691 throw new FormatError("Unknown mask format.");
30692 }
30693 }
30694 if (alphaBuf) {
30695 for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
30696 rgbaBuf[j] = alphaBuf[i];
30697 }
30698 } else {
30699 for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
30700 rgbaBuf[j] = 255;
30701 }
30702 }
30703 }
30704 undoPreblend(buffer, width, height) {
30705 const matte = this.smask?.matte;
30706 if (!matte) {
30707 return;
30708 }
30709 const matteRgb = this.colorSpace.getRgb(matte, 0);
30710 const matteR = matteRgb[0];
30711 const matteG = matteRgb[1];
30712 const matteB = matteRgb[2];
30713 const length = width * height * 4;
30714 for (let i = 0; i < length; i += 4) {
30715 const alpha = buffer[i + 3];
30716 if (alpha === 0) {
30717 buffer[i] = 255;
30718 buffer[i + 1] = 255;
30719 buffer[i + 2] = 255;
30720 continue;
30721 }
30722 const k = 255 / alpha;
30723 buffer[i] = (buffer[i] - matteR) * k + matteR;
30724 buffer[i + 1] = (buffer[i + 1] - matteG) * k + matteG;
30725 buffer[i + 2] = (buffer[i + 2] - matteB) * k + matteB;
30726 }
30727 }
30728 async createImageData(forceRGBA = false, isOffscreenCanvasSupported = false) {
30729 const drawWidth = this.drawWidth;
30730 const drawHeight = this.drawHeight;
30731 const imgData = {
30732 width: drawWidth,
30733 height: drawHeight,
30734 interpolate: this.interpolate,
30735 kind: 0,
30736 data: null
30737 };
30738 const numComps = this.numComps;
30739 const originalWidth = this.width;
30740 const originalHeight = this.height;
30741 const bpc = this.bpc;
30742 const rowBytes = originalWidth * numComps * bpc + 7 >> 3;
30743 const mustBeResized = isOffscreenCanvasSupported && ImageResizer.needsToBeResized(drawWidth, drawHeight);
30744 if (!forceRGBA) {
30745 let kind;
30746 if (this.colorSpace.name === "DeviceGray" && bpc === 1) {
30747 kind = ImageKind.GRAYSCALE_1BPP;
30748 } else if (this.colorSpace.name === "DeviceRGB" && bpc === 8 && !this.needsDecode) {
30749 kind = ImageKind.RGB_24BPP;
30750 }
30751 if (kind && !this.smask && !this.mask && drawWidth === originalWidth && drawHeight === originalHeight) {
30752 const data = this.getImageBytes(originalHeight * rowBytes, {});
30753 if (isOffscreenCanvasSupported) {
30754 if (mustBeResized) {
30755 return ImageResizer.createImage({
30756 data,
30757 kind,
30758 width: drawWidth,
30759 height: drawHeight,
30760 interpolate: this.interpolate
30761 }, this.needsDecode);
30762 }
30763 return this.createBitmap(kind, originalWidth, originalHeight, data);
30764 }
30765 imgData.kind = kind;
30766 imgData.data = data;
30767 if (this.needsDecode) {
30768 assert(kind === ImageKind.GRAYSCALE_1BPP, "PDFImage.createImageData: The image must be grayscale.");
30769 const buffer = imgData.data;
30770 for (let i = 0, ii = buffer.length; i < ii; i++) {
30771 buffer[i] ^= 0xff;
30772 }
30773 }
30774 return imgData;
30775 }
30776 if (this.image instanceof JpegStream && !this.smask && !this.mask && !this.needsDecode) {
30777 let imageLength = originalHeight * rowBytes;
30778 if (isOffscreenCanvasSupported && !mustBeResized) {
30779 let isHandled = false;
30780 switch (this.colorSpace.name) {
30781 case "DeviceGray":
30782 imageLength *= 4;
30783 isHandled = true;
30784 break;
30785 case "DeviceRGB":
30786 imageLength = imageLength / 3 * 4;
30787 isHandled = true;
30788 break;
30789 case "DeviceCMYK":
30790 isHandled = true;
30791 break;
30792 }
30793 if (isHandled) {
30794 const rgba = this.getImageBytes(imageLength, {
30795 drawWidth,
30796 drawHeight,
30797 forceRGBA: true
30798 });
30799 return this.createBitmap(ImageKind.RGBA_32BPP, drawWidth, drawHeight, rgba);
30800 }
30801 } else {
30802 switch (this.colorSpace.name) {
30803 case "DeviceGray":
30804 imageLength *= 3;
30805 case "DeviceRGB":
30806 case "DeviceCMYK":
30807 imgData.kind = ImageKind.RGB_24BPP;
30808 imgData.data = this.getImageBytes(imageLength, {
30809 drawWidth,
30810 drawHeight,
30811 forceRGB: true
30812 });
30813 if (mustBeResized) {
30814 return ImageResizer.createImage(imgData);
30815 }
30816 return imgData;
30817 }
30818 }
30819 }
30820 }
30821 const imgArray = this.getImageBytes(originalHeight * rowBytes, {
30822 internal: true
30823 });
30824 const actualHeight = 0 | imgArray.length / rowBytes * drawHeight / originalHeight;
30825 const comps = this.getComponents(imgArray);
30826 let alpha01, maybeUndoPreblend;
30827 let canvas, ctx, canvasImgData, data;
30828 if (isOffscreenCanvasSupported && !mustBeResized) {
30829 canvas = new OffscreenCanvas(drawWidth, drawHeight);
30830 ctx = canvas.getContext("2d");
30831 canvasImgData = ctx.createImageData(drawWidth, drawHeight);
30832 data = canvasImgData.data;
30833 }
30834 imgData.kind = ImageKind.RGBA_32BPP;
30835 if (!forceRGBA && !this.smask && !this.mask) {
30836 if (!isOffscreenCanvasSupported || mustBeResized) {
30837 imgData.kind = ImageKind.RGB_24BPP;
30838 data = new Uint8ClampedArray(drawWidth * drawHeight * 3);
30839 alpha01 = 0;
30840 } else {
30841 const arr = new Uint32Array(data.buffer);
30842 arr.fill(FeatureTest.isLittleEndian ? 0xff000000 : 0x000000ff);
30843 alpha01 = 1;
30844 }
30845 maybeUndoPreblend = false;
30846 } else {
30847 if (!isOffscreenCanvasSupported || mustBeResized) {
30848 data = new Uint8ClampedArray(drawWidth * drawHeight * 4);
30849 }
30850 alpha01 = 1;
30851 maybeUndoPreblend = true;
30852 this.fillOpacity(data, drawWidth, drawHeight, actualHeight, comps);
30853 }
30854 if (this.needsDecode) {
30855 this.decodeBuffer(comps);
30856 }
30857 this.colorSpace.fillRgb(data, originalWidth, originalHeight, drawWidth, drawHeight, actualHeight, bpc, comps, alpha01);
30858 if (maybeUndoPreblend) {
30859 this.undoPreblend(data, drawWidth, actualHeight);
30860 }
30861 if (isOffscreenCanvasSupported && !mustBeResized) {
30862 ctx.putImageData(canvasImgData, 0, 0);
30863 const bitmap = canvas.transferToImageBitmap();
30864 return {
30865 data: null,
30866 width: drawWidth,
30867 height: drawHeight,
30868 bitmap,
30869 interpolate: this.interpolate
30870 };
30871 }
30872 imgData.data = data;
30873 if (mustBeResized) {
30874 return ImageResizer.createImage(imgData);
30875 }
30876 return imgData;
30877 }
30878 fillGrayBuffer(buffer) {
30879 const numComps = this.numComps;
30880 if (numComps !== 1) {
30881 throw new FormatError(`Reading gray scale from a color image: ${numComps}`);
30882 }
30883 const width = this.width;
30884 const height = this.height;
30885 const bpc = this.bpc;
30886 const rowBytes = width * numComps * bpc + 7 >> 3;
30887 const imgArray = this.getImageBytes(height * rowBytes, {
30888 internal: true
30889 });
30890 const comps = this.getComponents(imgArray);
30891 let i, length;
30892 if (bpc === 1) {
30893 length = width * height;
30894 if (this.needsDecode) {
30895 for (i = 0; i < length; ++i) {
30896 buffer[i] = comps[i] - 1 & 255;
30897 }
30898 } else {
30899 for (i = 0; i < length; ++i) {
30900 buffer[i] = -comps[i] & 255;
30901 }
30902 }
30903 return;
30904 }
30905 if (this.needsDecode) {
30906 this.decodeBuffer(comps);
30907 }
30908 length = width * height;
30909 const scale = 255 / ((1 << bpc) - 1);
30910 for (i = 0; i < length; ++i) {
30911 buffer[i] = scale * comps[i];
30912 }
30913 }
30914 createBitmap(kind, width, height, src) {
30915 const canvas = new OffscreenCanvas(width, height);
30916 const ctx = canvas.getContext("2d");
30917 let imgData;
30918 if (kind === ImageKind.RGBA_32BPP) {
30919 imgData = new ImageData(src, width, height);
30920 } else {
30921 imgData = ctx.createImageData(width, height);
30922 convertToRGBA({
30923 kind,
30924 src,
30925 dest: new Uint32Array(imgData.data.buffer),
30926 width,
30927 height,
30928 inverseDecode: this.needsDecode
30929 });
30930 }
30931 ctx.putImageData(imgData, 0, 0);
30932 const bitmap = canvas.transferToImageBitmap();
30933 return {
30934 data: null,
30935 width,
30936 height,
30937 bitmap,
30938 interpolate: this.interpolate
30939 };
30940 }
30941 getImageBytes(length, {
30942 drawWidth,
30943 drawHeight,
30944 forceRGBA = false,
30945 forceRGB = false,
30946 internal = false
30947 }) {
30948 this.image.reset();
30949 this.image.drawWidth = drawWidth || this.width;
30950 this.image.drawHeight = drawHeight || this.height;
30951 this.image.forceRGBA = !!forceRGBA;
30952 this.image.forceRGB = !!forceRGB;
30953 const imageBytes = this.image.getBytes(length);
30954 if (internal || this.image instanceof DecodeStream) {
30955 return imageBytes;
30956 }
30957 assert(imageBytes instanceof Uint8Array, 'PDFImage.getImageBytes: Unsupported "imageBytes" type.');
30958 return new Uint8Array(imageBytes);
30959 }
30960}
30961
30962;// CONCATENATED MODULE: ./src/core/evaluator.js
30963
30964
30965
30966
30967
30968
30969
30970
30971
30972
30973
30974
30975
30976
30977
30978
30979
30980
30981
30982
30983
30984
30985
30986
30987
30988
30989const DefaultPartialEvaluatorOptions = Object.freeze({
30990 maxImageSize: -1,
30991 disableFontFace: false,
30992 ignoreErrors: false,
30993 isEvalSupported: true,
30994 isOffscreenCanvasSupported: false,
30995 canvasMaxAreaInBytes: -1,
30996 fontExtraProperties: false,
30997 useSystemFonts: true,
30998 cMapUrl: null,
30999 standardFontDataUrl: null
31000});
31001const PatternType = {
31002 TILING: 1,
31003 SHADING: 2
31004};
31005const TEXT_CHUNK_BATCH_SIZE = 10;
31006const deferred = Promise.resolve();
31007function normalizeBlendMode(value, parsingArray = false) {
31008 if (Array.isArray(value)) {
31009 for (const val of value) {
31010 const maybeBM = normalizeBlendMode(val, true);
31011 if (maybeBM) {
31012 return maybeBM;
31013 }
31014 }
31015 warn(`Unsupported blend mode Array: ${value}`);
31016 return "source-over";
31017 }
31018 if (!(value instanceof Name)) {
31019 if (parsingArray) {
31020 return null;
31021 }
31022 return "source-over";
31023 }
31024 switch (value.name) {
31025 case "Normal":
31026 case "Compatible":
31027 return "source-over";
31028 case "Multiply":
31029 return "multiply";
31030 case "Screen":
31031 return "screen";
31032 case "Overlay":
31033 return "overlay";
31034 case "Darken":
31035 return "darken";
31036 case "Lighten":
31037 return "lighten";
31038 case "ColorDodge":
31039 return "color-dodge";
31040 case "ColorBurn":
31041 return "color-burn";
31042 case "HardLight":
31043 return "hard-light";
31044 case "SoftLight":
31045 return "soft-light";
31046 case "Difference":
31047 return "difference";
31048 case "Exclusion":
31049 return "exclusion";
31050 case "Hue":
31051 return "hue";
31052 case "Saturation":
31053 return "saturation";
31054 case "Color":
31055 return "color";
31056 case "Luminosity":
31057 return "luminosity";
31058 }
31059 if (parsingArray) {
31060 return null;
31061 }
31062 warn(`Unsupported blend mode: ${value.name}`);
31063 return "source-over";
31064}
31065function incrementCachedImageMaskCount(data) {
31066 if (data.fn === OPS.paintImageMaskXObject && data.args[0]?.count > 0) {
31067 data.args[0].count++;
31068 }
31069}
31070class TimeSlotManager {
31071 static TIME_SLOT_DURATION_MS = 20;
31072 static CHECK_TIME_EVERY = 100;
31073 constructor() {
31074 this.reset();
31075 }
31076 check() {
31077 if (++this.checked < TimeSlotManager.CHECK_TIME_EVERY) {
31078 return false;
31079 }
31080 this.checked = 0;
31081 return this.endTime <= Date.now();
31082 }
31083 reset() {
31084 this.endTime = Date.now() + TimeSlotManager.TIME_SLOT_DURATION_MS;
31085 this.checked = 0;
31086 }
31087}
31088class PartialEvaluator {
31089 constructor({
31090 xref,
31091 handler,
31092 pageIndex,
31093 idFactory,
31094 fontCache,
31095 builtInCMapCache,
31096 standardFontDataCache,
31097 globalImageCache,
31098 systemFontCache,
31099 options = null
31100 }) {
31101 this.xref = xref;
31102 this.handler = handler;
31103 this.pageIndex = pageIndex;
31104 this.idFactory = idFactory;
31105 this.fontCache = fontCache;
31106 this.builtInCMapCache = builtInCMapCache;
31107 this.standardFontDataCache = standardFontDataCache;
31108 this.globalImageCache = globalImageCache;
31109 this.systemFontCache = systemFontCache;
31110 this.options = options || DefaultPartialEvaluatorOptions;
31111 this.parsingType3Font = false;
31112 this._regionalImageCache = new RegionalImageCache();
31113 this._fetchBuiltInCMapBound = this.fetchBuiltInCMap.bind(this);
31114 ImageResizer.setMaxArea(this.options.canvasMaxAreaInBytes);
31115 }
31116 get _pdfFunctionFactory() {
31117 const pdfFunctionFactory = new PDFFunctionFactory({
31118 xref: this.xref,
31119 isEvalSupported: this.options.isEvalSupported
31120 });
31121 return shadow(this, "_pdfFunctionFactory", pdfFunctionFactory);
31122 }
31123 clone(newOptions = null) {
31124 const newEvaluator = Object.create(this);
31125 newEvaluator.options = Object.assign(Object.create(null), this.options, newOptions);
31126 return newEvaluator;
31127 }
31128 hasBlendModes(resources, nonBlendModesSet) {
31129 if (!(resources instanceof Dict)) {
31130 return false;
31131 }
31132 if (resources.objId && nonBlendModesSet.has(resources.objId)) {
31133 return false;
31134 }
31135 const processed = new RefSet(nonBlendModesSet);
31136 if (resources.objId) {
31137 processed.put(resources.objId);
31138 }
31139 const nodes = [resources],
31140 xref = this.xref;
31141 while (nodes.length) {
31142 const node = nodes.shift();
31143 const graphicStates = node.get("ExtGState");
31144 if (graphicStates instanceof Dict) {
31145 for (let graphicState of graphicStates.getRawValues()) {
31146 if (graphicState instanceof Ref) {
31147 if (processed.has(graphicState)) {
31148 continue;
31149 }
31150 try {
31151 graphicState = xref.fetch(graphicState);
31152 } catch (ex) {
31153 processed.put(graphicState);
31154 info(`hasBlendModes - ignoring ExtGState: "${ex}".`);
31155 continue;
31156 }
31157 }
31158 if (!(graphicState instanceof Dict)) {
31159 continue;
31160 }
31161 if (graphicState.objId) {
31162 processed.put(graphicState.objId);
31163 }
31164 const bm = graphicState.get("BM");
31165 if (bm instanceof Name) {
31166 if (bm.name !== "Normal") {
31167 return true;
31168 }
31169 continue;
31170 }
31171 if (bm !== undefined && Array.isArray(bm)) {
31172 for (const element of bm) {
31173 if (element instanceof Name && element.name !== "Normal") {
31174 return true;
31175 }
31176 }
31177 }
31178 }
31179 }
31180 const xObjects = node.get("XObject");
31181 if (!(xObjects instanceof Dict)) {
31182 continue;
31183 }
31184 for (let xObject of xObjects.getRawValues()) {
31185 if (xObject instanceof Ref) {
31186 if (processed.has(xObject)) {
31187 continue;
31188 }
31189 try {
31190 xObject = xref.fetch(xObject);
31191 } catch (ex) {
31192 processed.put(xObject);
31193 info(`hasBlendModes - ignoring XObject: "${ex}".`);
31194 continue;
31195 }
31196 }
31197 if (!(xObject instanceof BaseStream)) {
31198 continue;
31199 }
31200 if (xObject.dict.objId) {
31201 processed.put(xObject.dict.objId);
31202 }
31203 const xResources = xObject.dict.get("Resources");
31204 if (!(xResources instanceof Dict)) {
31205 continue;
31206 }
31207 if (xResources.objId && processed.has(xResources.objId)) {
31208 continue;
31209 }
31210 nodes.push(xResources);
31211 if (xResources.objId) {
31212 processed.put(xResources.objId);
31213 }
31214 }
31215 }
31216 for (const ref of processed) {
31217 nonBlendModesSet.put(ref);
31218 }
31219 return false;
31220 }
31221 async fetchBuiltInCMap(name) {
31222 const cachedData = this.builtInCMapCache.get(name);
31223 if (cachedData) {
31224 return cachedData;
31225 }
31226 let data;
31227 if (this.options.cMapUrl !== null) {
31228 const url = `${this.options.cMapUrl}${name}.bcmap`;
31229 const response = await fetch(url);
31230 if (!response.ok) {
31231 throw new Error(`fetchBuiltInCMap: failed to fetch file "${url}" with "${response.statusText}".`);
31232 }
31233 data = {
31234 cMapData: new Uint8Array(await response.arrayBuffer()),
31235 compressionType: CMapCompressionType.BINARY
31236 };
31237 } else {
31238 data = await this.handler.sendWithPromise("FetchBuiltInCMap", {
31239 name
31240 });
31241 }
31242 if (data.compressionType !== CMapCompressionType.NONE) {
31243 this.builtInCMapCache.set(name, data);
31244 }
31245 return data;
31246 }
31247 async fetchStandardFontData(name) {
31248 const cachedData = this.standardFontDataCache.get(name);
31249 if (cachedData) {
31250 return new Stream(cachedData);
31251 }
31252 if (this.options.useSystemFonts && name !== "Symbol" && name !== "ZapfDingbats") {
31253 return null;
31254 }
31255 const standardFontNameToFileName = getFontNameToFileMap(),
31256 filename = standardFontNameToFileName[name];
31257 let data;
31258 if (this.options.standardFontDataUrl !== null) {
31259 const url = `${this.options.standardFontDataUrl}${filename}`;
31260 const response = await fetch(url);
31261 if (!response.ok) {
31262 warn(`fetchStandardFontData: failed to fetch file "${url}" with "${response.statusText}".`);
31263 } else {
31264 data = new Uint8Array(await response.arrayBuffer());
31265 }
31266 } else {
31267 try {
31268 data = await this.handler.sendWithPromise("FetchStandardFontData", {
31269 filename
31270 });
31271 } catch (e) {
31272 warn(`fetchStandardFontData: failed to fetch file "${filename}" with "${e}".`);
31273 }
31274 }
31275 if (!data) {
31276 return null;
31277 }
31278 this.standardFontDataCache.set(name, data);
31279 return new Stream(data);
31280 }
31281 async buildFormXObject(resources, xobj, smask, operatorList, task, initialState, localColorSpaceCache) {
31282 const dict = xobj.dict;
31283 const matrix = dict.getArray("Matrix");
31284 let bbox = dict.getArray("BBox");
31285 bbox = Array.isArray(bbox) && bbox.length === 4 ? Util.normalizeRect(bbox) : null;
31286 let optionalContent, groupOptions;
31287 if (dict.has("OC")) {
31288 optionalContent = await this.parseMarkedContentProps(dict.get("OC"), resources);
31289 }
31290 if (optionalContent !== undefined) {
31291 operatorList.addOp(OPS.beginMarkedContentProps, ["OC", optionalContent]);
31292 }
31293 const group = dict.get("Group");
31294 if (group) {
31295 groupOptions = {
31296 matrix,
31297 bbox,
31298 smask,
31299 isolated: false,
31300 knockout: false
31301 };
31302 const groupSubtype = group.get("S");
31303 let colorSpace = null;
31304 if (isName(groupSubtype, "Transparency")) {
31305 groupOptions.isolated = group.get("I") || false;
31306 groupOptions.knockout = group.get("K") || false;
31307 if (group.has("CS")) {
31308 const cs = group.getRaw("CS");
31309 const cachedColorSpace = ColorSpace.getCached(cs, this.xref, localColorSpaceCache);
31310 if (cachedColorSpace) {
31311 colorSpace = cachedColorSpace;
31312 } else {
31313 colorSpace = await this.parseColorSpace({
31314 cs,
31315 resources,
31316 localColorSpaceCache
31317 });
31318 }
31319 }
31320 }
31321 if (smask?.backdrop) {
31322 colorSpace ||= ColorSpace.singletons.rgb;
31323 smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
31324 }
31325 operatorList.addOp(OPS.beginGroup, [groupOptions]);
31326 }
31327 const args = group ? [matrix, null] : [matrix, bbox];
31328 operatorList.addOp(OPS.paintFormXObjectBegin, args);
31329 await this.getOperatorList({
31330 stream: xobj,
31331 task,
31332 resources: dict.get("Resources") || resources,
31333 operatorList,
31334 initialState
31335 });
31336 operatorList.addOp(OPS.paintFormXObjectEnd, []);
31337 if (group) {
31338 operatorList.addOp(OPS.endGroup, [groupOptions]);
31339 }
31340 if (optionalContent !== undefined) {
31341 operatorList.addOp(OPS.endMarkedContent, []);
31342 }
31343 }
31344 _sendImgData(objId, imgData, cacheGlobally = false) {
31345 const transfers = imgData ? [imgData.bitmap || imgData.data.buffer] : null;
31346 if (this.parsingType3Font || cacheGlobally) {
31347 return this.handler.send("commonobj", [objId, "Image", imgData], transfers);
31348 }
31349 return this.handler.send("obj", [objId, this.pageIndex, "Image", imgData], transfers);
31350 }
31351 async buildPaintImageXObject({
31352 resources,
31353 image,
31354 isInline = false,
31355 operatorList,
31356 cacheKey,
31357 localImageCache,
31358 localColorSpaceCache
31359 }) {
31360 const dict = image.dict;
31361 const imageRef = dict.objId;
31362 const w = dict.get("W", "Width");
31363 const h = dict.get("H", "Height");
31364 if (!(w && typeof w === "number") || !(h && typeof h === "number")) {
31365 warn("Image dimensions are missing, or not numbers.");
31366 return;
31367 }
31368 const maxImageSize = this.options.maxImageSize;
31369 if (maxImageSize !== -1 && w * h > maxImageSize) {
31370 const msg = "Image exceeded maximum allowed size and was removed.";
31371 if (this.options.ignoreErrors) {
31372 warn(msg);
31373 return;
31374 }
31375 throw new Error(msg);
31376 }
31377 let optionalContent;
31378 if (dict.has("OC")) {
31379 optionalContent = await this.parseMarkedContentProps(dict.get("OC"), resources);
31380 }
31381 const imageMask = dict.get("IM", "ImageMask") || false;
31382 let imgData, args;
31383 if (imageMask) {
31384 const interpolate = dict.get("I", "Interpolate");
31385 const bitStrideLength = w + 7 >> 3;
31386 const imgArray = image.getBytes(bitStrideLength * h);
31387 const decode = dict.getArray("D", "Decode");
31388 if (this.parsingType3Font) {
31389 imgData = PDFImage.createRawMask({
31390 imgArray,
31391 width: w,
31392 height: h,
31393 imageIsFromDecodeStream: image instanceof DecodeStream,
31394 inverseDecode: decode?.[0] > 0,
31395 interpolate
31396 });
31397 imgData.cached = !!cacheKey;
31398 args = [imgData];
31399 operatorList.addImageOps(OPS.paintImageMaskXObject, args, optionalContent);
31400 if (cacheKey) {
31401 const cacheData = {
31402 fn: OPS.paintImageMaskXObject,
31403 args,
31404 optionalContent
31405 };
31406 localImageCache.set(cacheKey, imageRef, cacheData);
31407 if (imageRef) {
31408 this._regionalImageCache.set(null, imageRef, cacheData);
31409 }
31410 }
31411 return;
31412 }
31413 imgData = await PDFImage.createMask({
31414 imgArray,
31415 width: w,
31416 height: h,
31417 imageIsFromDecodeStream: image instanceof DecodeStream,
31418 inverseDecode: decode?.[0] > 0,
31419 interpolate,
31420 isOffscreenCanvasSupported: this.options.isOffscreenCanvasSupported
31421 });
31422 if (imgData.isSingleOpaquePixel) {
31423 operatorList.addImageOps(OPS.paintSolidColorImageMask, [], optionalContent);
31424 if (cacheKey) {
31425 const cacheData = {
31426 fn: OPS.paintSolidColorImageMask,
31427 args: [],
31428 optionalContent
31429 };
31430 localImageCache.set(cacheKey, imageRef, cacheData);
31431 if (imageRef) {
31432 this._regionalImageCache.set(null, imageRef, cacheData);
31433 }
31434 }
31435 return;
31436 }
31437 const objId = `mask_${this.idFactory.createObjId()}`;
31438 operatorList.addDependency(objId);
31439 imgData.dataLen = imgData.bitmap ? imgData.width * imgData.height * 4 : imgData.data.length;
31440 this._sendImgData(objId, imgData);
31441 args = [{
31442 data: objId,
31443 width: imgData.width,
31444 height: imgData.height,
31445 interpolate: imgData.interpolate,
31446 count: 1
31447 }];
31448 operatorList.addImageOps(OPS.paintImageMaskXObject, args, optionalContent);
31449 if (cacheKey) {
31450 const cacheData = {
31451 fn: OPS.paintImageMaskXObject,
31452 args,
31453 optionalContent
31454 };
31455 localImageCache.set(cacheKey, imageRef, cacheData);
31456 if (imageRef) {
31457 this._regionalImageCache.set(null, imageRef, cacheData);
31458 }
31459 }
31460 return;
31461 }
31462 const SMALL_IMAGE_DIMENSIONS = 200;
31463 if (isInline && !dict.has("SMask") && !dict.has("Mask") && w + h < SMALL_IMAGE_DIMENSIONS) {
31464 try {
31465 const imageObj = new PDFImage({
31466 xref: this.xref,
31467 res: resources,
31468 image,
31469 isInline,
31470 pdfFunctionFactory: this._pdfFunctionFactory,
31471 localColorSpaceCache
31472 });
31473 imgData = await imageObj.createImageData(true, false);
31474 operatorList.isOffscreenCanvasSupported = this.options.isOffscreenCanvasSupported;
31475 operatorList.addImageOps(OPS.paintInlineImageXObject, [imgData], optionalContent);
31476 } catch (reason) {
31477 const msg = `Unable to decode inline image: "${reason}".`;
31478 if (!this.options.ignoreErrors) {
31479 throw new Error(msg);
31480 }
31481 warn(msg);
31482 }
31483 return;
31484 }
31485 let objId = `img_${this.idFactory.createObjId()}`,
31486 cacheGlobally = false;
31487 if (this.parsingType3Font) {
31488 objId = `${this.idFactory.getDocId()}_type3_${objId}`;
31489 } else if (cacheKey && imageRef) {
31490 cacheGlobally = this.globalImageCache.shouldCache(imageRef, this.pageIndex);
31491 if (cacheGlobally) {
31492 assert(!isInline, "Cannot cache an inline image globally.");
31493 objId = `${this.idFactory.getDocId()}_${objId}`;
31494 }
31495 }
31496 operatorList.addDependency(objId);
31497 args = [objId, w, h];
31498 operatorList.addImageOps(OPS.paintImageXObject, args, optionalContent);
31499 if (cacheGlobally && w * h > 250000) {
31500 const localLength = await this.handler.sendWithPromise("commonobj", [objId, "CopyLocalImage", {
31501 imageRef
31502 }]);
31503 if (localLength) {
31504 this.globalImageCache.setData(imageRef, {
31505 objId,
31506 fn: OPS.paintImageXObject,
31507 args,
31508 optionalContent,
31509 byteSize: 0
31510 });
31511 this.globalImageCache.addByteSize(imageRef, localLength);
31512 return;
31513 }
31514 }
31515 PDFImage.buildImage({
31516 xref: this.xref,
31517 res: resources,
31518 image,
31519 isInline,
31520 pdfFunctionFactory: this._pdfFunctionFactory,
31521 localColorSpaceCache
31522 }).then(async imageObj => {
31523 imgData = await imageObj.createImageData(false, this.options.isOffscreenCanvasSupported);
31524 imgData.dataLen = imgData.bitmap ? imgData.width * imgData.height * 4 : imgData.data.length;
31525 imgData.ref = imageRef;
31526 if (cacheGlobally) {
31527 this.globalImageCache.addByteSize(imageRef, imgData.dataLen);
31528 }
31529 return this._sendImgData(objId, imgData, cacheGlobally);
31530 }).catch(reason => {
31531 warn(`Unable to decode image "${objId}": "${reason}".`);
31532 return this._sendImgData(objId, null, cacheGlobally);
31533 });
31534 if (cacheKey) {
31535 const cacheData = {
31536 fn: OPS.paintImageXObject,
31537 args,
31538 optionalContent
31539 };
31540 localImageCache.set(cacheKey, imageRef, cacheData);
31541 if (imageRef) {
31542 this._regionalImageCache.set(null, imageRef, cacheData);
31543 if (cacheGlobally) {
31544 this.globalImageCache.setData(imageRef, {
31545 objId,
31546 fn: OPS.paintImageXObject,
31547 args,
31548 optionalContent,
31549 byteSize: 0
31550 });
31551 }
31552 }
31553 }
31554 }
31555 handleSMask(smask, resources, operatorList, task, stateManager, localColorSpaceCache) {
31556 const smaskContent = smask.get("G");
31557 const smaskOptions = {
31558 subtype: smask.get("S").name,
31559 backdrop: smask.get("BC")
31560 };
31561 const transferObj = smask.get("TR");
31562 if (isPDFFunction(transferObj)) {
31563 const transferFn = this._pdfFunctionFactory.create(transferObj);
31564 const transferMap = new Uint8Array(256);
31565 const tmp = new Float32Array(1);
31566 for (let i = 0; i < 256; i++) {
31567 tmp[0] = i / 255;
31568 transferFn(tmp, 0, tmp, 0);
31569 transferMap[i] = tmp[0] * 255 | 0;
31570 }
31571 smaskOptions.transferMap = transferMap;
31572 }
31573 return this.buildFormXObject(resources, smaskContent, smaskOptions, operatorList, task, stateManager.state.clone(), localColorSpaceCache);
31574 }
31575 handleTransferFunction(tr) {
31576 let transferArray;
31577 if (Array.isArray(tr)) {
31578 transferArray = tr;
31579 } else if (isPDFFunction(tr)) {
31580 transferArray = [tr];
31581 } else {
31582 return null;
31583 }
31584 const transferMaps = [];
31585 let numFns = 0,
31586 numEffectfulFns = 0;
31587 for (const entry of transferArray) {
31588 const transferObj = this.xref.fetchIfRef(entry);
31589 numFns++;
31590 if (isName(transferObj, "Identity")) {
31591 transferMaps.push(null);
31592 continue;
31593 } else if (!isPDFFunction(transferObj)) {
31594 return null;
31595 }
31596 const transferFn = this._pdfFunctionFactory.create(transferObj);
31597 const transferMap = new Uint8Array(256),
31598 tmp = new Float32Array(1);
31599 for (let j = 0; j < 256; j++) {
31600 tmp[0] = j / 255;
31601 transferFn(tmp, 0, tmp, 0);
31602 transferMap[j] = tmp[0] * 255 | 0;
31603 }
31604 transferMaps.push(transferMap);
31605 numEffectfulFns++;
31606 }
31607 if (!(numFns === 1 || numFns === 4)) {
31608 return null;
31609 }
31610 if (numEffectfulFns === 0) {
31611 return null;
31612 }
31613 return transferMaps;
31614 }
31615 handleTilingType(fn, color, resources, pattern, patternDict, operatorList, task, localTilingPatternCache) {
31616 const tilingOpList = new OperatorList();
31617 const patternResources = Dict.merge({
31618 xref: this.xref,
31619 dictArray: [patternDict.get("Resources"), resources]
31620 });
31621 return this.getOperatorList({
31622 stream: pattern,
31623 task,
31624 resources: patternResources,
31625 operatorList: tilingOpList
31626 }).then(function () {
31627 const operatorListIR = tilingOpList.getIR();
31628 const tilingPatternIR = getTilingPatternIR(operatorListIR, patternDict, color);
31629 operatorList.addDependencies(tilingOpList.dependencies);
31630 operatorList.addOp(fn, tilingPatternIR);
31631 if (patternDict.objId) {
31632 localTilingPatternCache.set(null, patternDict.objId, {
31633 operatorListIR,
31634 dict: patternDict
31635 });
31636 }
31637 }).catch(reason => {
31638 if (reason instanceof AbortException) {
31639 return;
31640 }
31641 if (this.options.ignoreErrors) {
31642 warn(`handleTilingType - ignoring pattern: "${reason}".`);
31643 return;
31644 }
31645 throw reason;
31646 });
31647 }
31648 async handleSetFont(resources, fontArgs, fontRef, operatorList, task, state, fallbackFontDict = null, cssFontInfo = null) {
31649 const fontName = fontArgs?.[0] instanceof Name ? fontArgs[0].name : null;
31650 let translated = await this.loadFont(fontName, fontRef, resources, fallbackFontDict, cssFontInfo);
31651 if (translated.font.isType3Font) {
31652 try {
31653 await translated.loadType3Data(this, resources, task);
31654 operatorList.addDependencies(translated.type3Dependencies);
31655 } catch (reason) {
31656 translated = new TranslatedFont({
31657 loadedName: "g_font_error",
31658 font: new ErrorFont(`Type3 font load error: ${reason}`),
31659 dict: translated.font,
31660 evaluatorOptions: this.options
31661 });
31662 }
31663 }
31664 state.font = translated.font;
31665 translated.send(this.handler);
31666 return translated.loadedName;
31667 }
31668 handleText(chars, state) {
31669 const font = state.font;
31670 const glyphs = font.charsToGlyphs(chars);
31671 if (font.data) {
31672 const isAddToPathSet = !!(state.textRenderingMode & TextRenderingMode.ADD_TO_PATH_FLAG);
31673 if (isAddToPathSet || state.fillColorSpace.name === "Pattern" || font.disableFontFace || this.options.disableFontFace) {
31674 PartialEvaluator.buildFontPaths(font, glyphs, this.handler, this.options);
31675 }
31676 }
31677 return glyphs;
31678 }
31679 ensureStateFont(state) {
31680 if (state.font) {
31681 return;
31682 }
31683 const reason = new FormatError("Missing setFont (Tf) operator before text rendering operator.");
31684 if (this.options.ignoreErrors) {
31685 warn(`ensureStateFont: "${reason}".`);
31686 return;
31687 }
31688 throw reason;
31689 }
31690 async setGState({
31691 resources,
31692 gState,
31693 operatorList,
31694 cacheKey,
31695 task,
31696 stateManager,
31697 localGStateCache,
31698 localColorSpaceCache
31699 }) {
31700 const gStateRef = gState.objId;
31701 let isSimpleGState = true;
31702 const gStateObj = [];
31703 let promise = Promise.resolve();
31704 for (const key of gState.getKeys()) {
31705 const value = gState.get(key);
31706 switch (key) {
31707 case "Type":
31708 break;
31709 case "LW":
31710 case "LC":
31711 case "LJ":
31712 case "ML":
31713 case "D":
31714 case "RI":
31715 case "FL":
31716 case "CA":
31717 case "ca":
31718 gStateObj.push([key, value]);
31719 break;
31720 case "Font":
31721 isSimpleGState = false;
31722 promise = promise.then(() => this.handleSetFont(resources, null, value[0], operatorList, task, stateManager.state).then(function (loadedName) {
31723 operatorList.addDependency(loadedName);
31724 gStateObj.push([key, [loadedName, value[1]]]);
31725 }));
31726 break;
31727 case "BM":
31728 gStateObj.push([key, normalizeBlendMode(value)]);
31729 break;
31730 case "SMask":
31731 if (isName(value, "None")) {
31732 gStateObj.push([key, false]);
31733 break;
31734 }
31735 if (value instanceof Dict) {
31736 isSimpleGState = false;
31737 promise = promise.then(() => this.handleSMask(value, resources, operatorList, task, stateManager, localColorSpaceCache));
31738 gStateObj.push([key, true]);
31739 } else {
31740 warn("Unsupported SMask type");
31741 }
31742 break;
31743 case "TR":
31744 const transferMaps = this.handleTransferFunction(value);
31745 gStateObj.push([key, transferMaps]);
31746 break;
31747 case "OP":
31748 case "op":
31749 case "OPM":
31750 case "BG":
31751 case "BG2":
31752 case "UCR":
31753 case "UCR2":
31754 case "TR2":
31755 case "HT":
31756 case "SM":
31757 case "SA":
31758 case "AIS":
31759 case "TK":
31760 info("graphic state operator " + key);
31761 break;
31762 default:
31763 info("Unknown graphic state operator " + key);
31764 break;
31765 }
31766 }
31767 await promise;
31768 if (gStateObj.length > 0) {
31769 operatorList.addOp(OPS.setGState, [gStateObj]);
31770 }
31771 if (isSimpleGState) {
31772 localGStateCache.set(cacheKey, gStateRef, gStateObj);
31773 }
31774 }
31775 loadFont(fontName, font, resources, fallbackFontDict = null, cssFontInfo = null) {
31776 const errorFont = async () => {
31777 return new TranslatedFont({
31778 loadedName: "g_font_error",
31779 font: new ErrorFont(`Font "${fontName}" is not available.`),
31780 dict: font,
31781 evaluatorOptions: this.options
31782 });
31783 };
31784 let fontRef;
31785 if (font) {
31786 if (font instanceof Ref) {
31787 fontRef = font;
31788 }
31789 } else {
31790 const fontRes = resources.get("Font");
31791 if (fontRes) {
31792 fontRef = fontRes.getRaw(fontName);
31793 }
31794 }
31795 if (fontRef) {
31796 if (this.parsingType3Font && this.type3FontRefs.has(fontRef)) {
31797 return errorFont();
31798 }
31799 if (this.fontCache.has(fontRef)) {
31800 return this.fontCache.get(fontRef);
31801 }
31802 font = this.xref.fetchIfRef(fontRef);
31803 }
31804 if (!(font instanceof Dict)) {
31805 if (!this.options.ignoreErrors && !this.parsingType3Font) {
31806 warn(`Font "${fontName}" is not available.`);
31807 return errorFont();
31808 }
31809 warn(`Font "${fontName}" is not available -- attempting to fallback to a default font.`);
31810 font = fallbackFontDict || PartialEvaluator.fallbackFontDict;
31811 }
31812 if (font.cacheKey && this.fontCache.has(font.cacheKey)) {
31813 return this.fontCache.get(font.cacheKey);
31814 }
31815 const {
31816 promise,
31817 resolve
31818 } = Promise.withResolvers();
31819 let preEvaluatedFont;
31820 try {
31821 preEvaluatedFont = this.preEvaluateFont(font);
31822 preEvaluatedFont.cssFontInfo = cssFontInfo;
31823 } catch (reason) {
31824 warn(`loadFont - preEvaluateFont failed: "${reason}".`);
31825 return errorFont();
31826 }
31827 const {
31828 descriptor,
31829 hash
31830 } = preEvaluatedFont;
31831 const fontRefIsRef = fontRef instanceof Ref;
31832 let fontID;
31833 if (hash && descriptor instanceof Dict) {
31834 const fontAliases = descriptor.fontAliases ||= Object.create(null);
31835 if (fontAliases[hash]) {
31836 const aliasFontRef = fontAliases[hash].aliasRef;
31837 if (fontRefIsRef && aliasFontRef && this.fontCache.has(aliasFontRef)) {
31838 this.fontCache.putAlias(fontRef, aliasFontRef);
31839 return this.fontCache.get(fontRef);
31840 }
31841 } else {
31842 fontAliases[hash] = {
31843 fontID: this.idFactory.createFontId()
31844 };
31845 }
31846 if (fontRefIsRef) {
31847 fontAliases[hash].aliasRef = fontRef;
31848 }
31849 fontID = fontAliases[hash].fontID;
31850 } else {
31851 fontID = this.idFactory.createFontId();
31852 }
31853 assert(fontID?.startsWith("f"), 'The "fontID" must be (correctly) defined.');
31854 if (fontRefIsRef) {
31855 this.fontCache.put(fontRef, promise);
31856 } else {
31857 font.cacheKey = `cacheKey_${fontID}`;
31858 this.fontCache.put(font.cacheKey, promise);
31859 }
31860 font.loadedName = `${this.idFactory.getDocId()}_${fontID}`;
31861 this.translateFont(preEvaluatedFont).then(translatedFont => {
31862 resolve(new TranslatedFont({
31863 loadedName: font.loadedName,
31864 font: translatedFont,
31865 dict: font,
31866 evaluatorOptions: this.options
31867 }));
31868 }).catch(reason => {
31869 warn(`loadFont - translateFont failed: "${reason}".`);
31870 resolve(new TranslatedFont({
31871 loadedName: font.loadedName,
31872 font: new ErrorFont(reason instanceof Error ? reason.message : reason),
31873 dict: font,
31874 evaluatorOptions: this.options
31875 }));
31876 });
31877 return promise;
31878 }
31879 buildPath(operatorList, fn, args, parsingText = false) {
31880 const lastIndex = operatorList.length - 1;
31881 if (!args) {
31882 args = [];
31883 }
31884 if (lastIndex < 0 || operatorList.fnArray[lastIndex] !== OPS.constructPath) {
31885 if (parsingText) {
31886 warn(`Encountered path operator "${fn}" inside of a text object.`);
31887 operatorList.addOp(OPS.save, null);
31888 }
31889 let minMax;
31890 switch (fn) {
31891 case OPS.rectangle:
31892 const x = args[0] + args[2];
31893 const y = args[1] + args[3];
31894 minMax = [Math.min(args[0], x), Math.min(args[1], y), Math.max(args[0], x), Math.max(args[1], y)];
31895 break;
31896 case OPS.moveTo:
31897 case OPS.lineTo:
31898 minMax = [args[0], args[1], args[0], args[1]];
31899 break;
31900 default:
31901 minMax = [Infinity, Infinity, -Infinity, -Infinity];
31902 break;
31903 }
31904 operatorList.addOp(OPS.constructPath, [[fn], args, minMax]);
31905 if (parsingText) {
31906 operatorList.addOp(OPS.restore, null);
31907 }
31908 } else {
31909 const opArgs = operatorList.argsArray[lastIndex];
31910 opArgs[0].push(fn);
31911 opArgs[1].push(...args);
31912 const minMax = opArgs[2];
31913 switch (fn) {
31914 case OPS.rectangle:
31915 const x = args[0] + args[2];
31916 const y = args[1] + args[3];
31917 minMax[0] = Math.min(minMax[0], args[0], x);
31918 minMax[1] = Math.min(minMax[1], args[1], y);
31919 minMax[2] = Math.max(minMax[2], args[0], x);
31920 minMax[3] = Math.max(minMax[3], args[1], y);
31921 break;
31922 case OPS.moveTo:
31923 case OPS.lineTo:
31924 minMax[0] = Math.min(minMax[0], args[0]);
31925 minMax[1] = Math.min(minMax[1], args[1]);
31926 minMax[2] = Math.max(minMax[2], args[0]);
31927 minMax[3] = Math.max(minMax[3], args[1]);
31928 break;
31929 }
31930 }
31931 }
31932 parseColorSpace({
31933 cs,
31934 resources,
31935 localColorSpaceCache
31936 }) {
31937 return ColorSpace.parseAsync({
31938 cs,
31939 xref: this.xref,
31940 resources,
31941 pdfFunctionFactory: this._pdfFunctionFactory,
31942 localColorSpaceCache
31943 }).catch(reason => {
31944 if (reason instanceof AbortException) {
31945 return null;
31946 }
31947 if (this.options.ignoreErrors) {
31948 warn(`parseColorSpace - ignoring ColorSpace: "${reason}".`);
31949 return null;
31950 }
31951 throw reason;
31952 });
31953 }
31954 parseShading({
31955 shading,
31956 resources,
31957 localColorSpaceCache,
31958 localShadingPatternCache
31959 }) {
31960 let id = localShadingPatternCache.get(shading);
31961 if (id) {
31962 return id;
31963 }
31964 let patternIR;
31965 try {
31966 const shadingFill = Pattern.parseShading(shading, this.xref, resources, this._pdfFunctionFactory, localColorSpaceCache);
31967 patternIR = shadingFill.getIR();
31968 } catch (reason) {
31969 if (reason instanceof AbortException) {
31970 return null;
31971 }
31972 if (this.options.ignoreErrors) {
31973 warn(`parseShading - ignoring shading: "${reason}".`);
31974 localShadingPatternCache.set(shading, null);
31975 return null;
31976 }
31977 throw reason;
31978 }
31979 id = `pattern_${this.idFactory.createObjId()}`;
31980 if (this.parsingType3Font) {
31981 id = `${this.idFactory.getDocId()}_type3_${id}`;
31982 }
31983 localShadingPatternCache.set(shading, id);
31984 if (this.parsingType3Font) {
31985 this.handler.send("commonobj", [id, "Pattern", patternIR]);
31986 } else {
31987 this.handler.send("obj", [id, this.pageIndex, "Pattern", patternIR]);
31988 }
31989 return id;
31990 }
31991 handleColorN(operatorList, fn, args, cs, patterns, resources, task, localColorSpaceCache, localTilingPatternCache, localShadingPatternCache) {
31992 const patternName = args.pop();
31993 if (patternName instanceof Name) {
31994 const rawPattern = patterns.getRaw(patternName.name);
31995 const localTilingPattern = rawPattern instanceof Ref && localTilingPatternCache.getByRef(rawPattern);
31996 if (localTilingPattern) {
31997 try {
31998 const color = cs.base ? cs.base.getRgb(args, 0) : null;
31999 const tilingPatternIR = getTilingPatternIR(localTilingPattern.operatorListIR, localTilingPattern.dict, color);
32000 operatorList.addOp(fn, tilingPatternIR);
32001 return undefined;
32002 } catch {}
32003 }
32004 const pattern = this.xref.fetchIfRef(rawPattern);
32005 if (pattern) {
32006 const dict = pattern instanceof BaseStream ? pattern.dict : pattern;
32007 const typeNum = dict.get("PatternType");
32008 if (typeNum === PatternType.TILING) {
32009 const color = cs.base ? cs.base.getRgb(args, 0) : null;
32010 return this.handleTilingType(fn, color, resources, pattern, dict, operatorList, task, localTilingPatternCache);
32011 } else if (typeNum === PatternType.SHADING) {
32012 const shading = dict.get("Shading");
32013 const objId = this.parseShading({
32014 shading,
32015 resources,
32016 localColorSpaceCache,
32017 localShadingPatternCache
32018 });
32019 if (objId) {
32020 const matrix = dict.getArray("Matrix");
32021 operatorList.addOp(fn, ["Shading", objId, matrix]);
32022 }
32023 return undefined;
32024 }
32025 throw new FormatError(`Unknown PatternType: ${typeNum}`);
32026 }
32027 }
32028 throw new FormatError(`Unknown PatternName: ${patternName}`);
32029 }
32030 _parseVisibilityExpression(array, nestingCounter, currentResult) {
32031 const MAX_NESTING = 10;
32032 if (++nestingCounter > MAX_NESTING) {
32033 warn("Visibility expression is too deeply nested");
32034 return;
32035 }
32036 const length = array.length;
32037 const operator = this.xref.fetchIfRef(array[0]);
32038 if (length < 2 || !(operator instanceof Name)) {
32039 warn("Invalid visibility expression");
32040 return;
32041 }
32042 switch (operator.name) {
32043 case "And":
32044 case "Or":
32045 case "Not":
32046 currentResult.push(operator.name);
32047 break;
32048 default:
32049 warn(`Invalid operator ${operator.name} in visibility expression`);
32050 return;
32051 }
32052 for (let i = 1; i < length; i++) {
32053 const raw = array[i];
32054 const object = this.xref.fetchIfRef(raw);
32055 if (Array.isArray(object)) {
32056 const nestedResult = [];
32057 currentResult.push(nestedResult);
32058 this._parseVisibilityExpression(object, nestingCounter, nestedResult);
32059 } else if (raw instanceof Ref) {
32060 currentResult.push(raw.toString());
32061 }
32062 }
32063 }
32064 async parseMarkedContentProps(contentProperties, resources) {
32065 let optionalContent;
32066 if (contentProperties instanceof Name) {
32067 const properties = resources.get("Properties");
32068 optionalContent = properties.get(contentProperties.name);
32069 } else if (contentProperties instanceof Dict) {
32070 optionalContent = contentProperties;
32071 } else {
32072 throw new FormatError("Optional content properties malformed.");
32073 }
32074 const optionalContentType = optionalContent.get("Type")?.name;
32075 if (optionalContentType === "OCG") {
32076 return {
32077 type: optionalContentType,
32078 id: optionalContent.objId
32079 };
32080 } else if (optionalContentType === "OCMD") {
32081 const expression = optionalContent.get("VE");
32082 if (Array.isArray(expression)) {
32083 const result = [];
32084 this._parseVisibilityExpression(expression, 0, result);
32085 if (result.length > 0) {
32086 return {
32087 type: "OCMD",
32088 expression: result
32089 };
32090 }
32091 }
32092 const optionalContentGroups = optionalContent.get("OCGs");
32093 if (Array.isArray(optionalContentGroups) || optionalContentGroups instanceof Dict) {
32094 const groupIds = [];
32095 if (Array.isArray(optionalContentGroups)) {
32096 for (const ocg of optionalContentGroups) {
32097 groupIds.push(ocg.toString());
32098 }
32099 } else {
32100 groupIds.push(optionalContentGroups.objId);
32101 }
32102 return {
32103 type: optionalContentType,
32104 ids: groupIds,
32105 policy: optionalContent.get("P") instanceof Name ? optionalContent.get("P").name : null,
32106 expression: null
32107 };
32108 } else if (optionalContentGroups instanceof Ref) {
32109 return {
32110 type: optionalContentType,
32111 id: optionalContentGroups.toString()
32112 };
32113 }
32114 }
32115 return null;
32116 }
32117 getOperatorList({
32118 stream,
32119 task,
32120 resources,
32121 operatorList,
32122 initialState = null,
32123 fallbackFontDict = null
32124 }) {
32125 resources ||= Dict.empty;
32126 initialState ||= new EvalState();
32127 if (!operatorList) {
32128 throw new Error('getOperatorList: missing "operatorList" parameter');
32129 }
32130 const self = this;
32131 const xref = this.xref;
32132 let parsingText = false;
32133 const localImageCache = new LocalImageCache();
32134 const localColorSpaceCache = new LocalColorSpaceCache();
32135 const localGStateCache = new LocalGStateCache();
32136 const localTilingPatternCache = new LocalTilingPatternCache();
32137 const localShadingPatternCache = new Map();
32138 const xobjs = resources.get("XObject") || Dict.empty;
32139 const patterns = resources.get("Pattern") || Dict.empty;
32140 const stateManager = new StateManager(initialState);
32141 const preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
32142 const timeSlotManager = new TimeSlotManager();
32143 function closePendingRestoreOPS(argument) {
32144 for (let i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
32145 operatorList.addOp(OPS.restore, []);
32146 }
32147 }
32148 return new Promise(function promiseBody(resolve, reject) {
32149 const next = function (promise) {
32150 Promise.all([promise, operatorList.ready]).then(function () {
32151 try {
32152 promiseBody(resolve, reject);
32153 } catch (ex) {
32154 reject(ex);
32155 }
32156 }, reject);
32157 };
32158 task.ensureNotTerminated();
32159 timeSlotManager.reset();
32160 const operation = {};
32161 let stop, i, ii, cs, name, isValidName;
32162 while (!(stop = timeSlotManager.check())) {
32163 operation.args = null;
32164 if (!preprocessor.read(operation)) {
32165 break;
32166 }
32167 let args = operation.args;
32168 let fn = operation.fn;
32169 switch (fn | 0) {
32170 case OPS.paintXObject:
32171 isValidName = args[0] instanceof Name;
32172 name = args[0].name;
32173 if (isValidName) {
32174 const localImage = localImageCache.getByName(name);
32175 if (localImage) {
32176 operatorList.addImageOps(localImage.fn, localImage.args, localImage.optionalContent);
32177 incrementCachedImageMaskCount(localImage);
32178 args = null;
32179 continue;
32180 }
32181 }
32182 next(new Promise(function (resolveXObject, rejectXObject) {
32183 if (!isValidName) {
32184 throw new FormatError("XObject must be referred to by name.");
32185 }
32186 let xobj = xobjs.getRaw(name);
32187 if (xobj instanceof Ref) {
32188 const localImage = localImageCache.getByRef(xobj) || self._regionalImageCache.getByRef(xobj);
32189 if (localImage) {
32190 operatorList.addImageOps(localImage.fn, localImage.args, localImage.optionalContent);
32191 incrementCachedImageMaskCount(localImage);
32192 resolveXObject();
32193 return;
32194 }
32195 const globalImage = self.globalImageCache.getData(xobj, self.pageIndex);
32196 if (globalImage) {
32197 operatorList.addDependency(globalImage.objId);
32198 operatorList.addImageOps(globalImage.fn, globalImage.args, globalImage.optionalContent);
32199 resolveXObject();
32200 return;
32201 }
32202 xobj = xref.fetch(xobj);
32203 }
32204 if (!(xobj instanceof BaseStream)) {
32205 throw new FormatError("XObject should be a stream");
32206 }
32207 const type = xobj.dict.get("Subtype");
32208 if (!(type instanceof Name)) {
32209 throw new FormatError("XObject should have a Name subtype");
32210 }
32211 if (type.name === "Form") {
32212 stateManager.save();
32213 self.buildFormXObject(resources, xobj, null, operatorList, task, stateManager.state.clone(), localColorSpaceCache).then(function () {
32214 stateManager.restore();
32215 resolveXObject();
32216 }, rejectXObject);
32217 return;
32218 } else if (type.name === "Image") {
32219 self.buildPaintImageXObject({
32220 resources,
32221 image: xobj,
32222 operatorList,
32223 cacheKey: name,
32224 localImageCache,
32225 localColorSpaceCache
32226 }).then(resolveXObject, rejectXObject);
32227 return;
32228 } else if (type.name === "PS") {
32229 info("Ignored XObject subtype PS");
32230 } else {
32231 throw new FormatError(`Unhandled XObject subtype ${type.name}`);
32232 }
32233 resolveXObject();
32234 }).catch(function (reason) {
32235 if (reason instanceof AbortException) {
32236 return;
32237 }
32238 if (self.options.ignoreErrors) {
32239 warn(`getOperatorList - ignoring XObject: "${reason}".`);
32240 return;
32241 }
32242 throw reason;
32243 }));
32244 return;
32245 case OPS.setFont:
32246 var fontSize = args[1];
32247 next(self.handleSetFont(resources, args, null, operatorList, task, stateManager.state, fallbackFontDict).then(function (loadedName) {
32248 operatorList.addDependency(loadedName);
32249 operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
32250 }));
32251 return;
32252 case OPS.beginText:
32253 parsingText = true;
32254 break;
32255 case OPS.endText:
32256 parsingText = false;
32257 break;
32258 case OPS.endInlineImage:
32259 var cacheKey = args[0].cacheKey;
32260 if (cacheKey) {
32261 const localImage = localImageCache.getByName(cacheKey);
32262 if (localImage) {
32263 operatorList.addImageOps(localImage.fn, localImage.args, localImage.optionalContent);
32264 incrementCachedImageMaskCount(localImage);
32265 args = null;
32266 continue;
32267 }
32268 }
32269 next(self.buildPaintImageXObject({
32270 resources,
32271 image: args[0],
32272 isInline: true,
32273 operatorList,
32274 cacheKey,
32275 localImageCache,
32276 localColorSpaceCache
32277 }));
32278 return;
32279 case OPS.showText:
32280 if (!stateManager.state.font) {
32281 self.ensureStateFont(stateManager.state);
32282 continue;
32283 }
32284 args[0] = self.handleText(args[0], stateManager.state);
32285 break;
32286 case OPS.showSpacedText:
32287 if (!stateManager.state.font) {
32288 self.ensureStateFont(stateManager.state);
32289 continue;
32290 }
32291 var combinedGlyphs = [];
32292 var state = stateManager.state;
32293 for (const arrItem of args[0]) {
32294 if (typeof arrItem === "string") {
32295 combinedGlyphs.push(...self.handleText(arrItem, state));
32296 } else if (typeof arrItem === "number") {
32297 combinedGlyphs.push(arrItem);
32298 }
32299 }
32300 args[0] = combinedGlyphs;
32301 fn = OPS.showText;
32302 break;
32303 case OPS.nextLineShowText:
32304 if (!stateManager.state.font) {
32305 self.ensureStateFont(stateManager.state);
32306 continue;
32307 }
32308 operatorList.addOp(OPS.nextLine);
32309 args[0] = self.handleText(args[0], stateManager.state);
32310 fn = OPS.showText;
32311 break;
32312 case OPS.nextLineSetSpacingShowText:
32313 if (!stateManager.state.font) {
32314 self.ensureStateFont(stateManager.state);
32315 continue;
32316 }
32317 operatorList.addOp(OPS.nextLine);
32318 operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
32319 operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
32320 args[0] = self.handleText(args[0], stateManager.state);
32321 fn = OPS.showText;
32322 break;
32323 case OPS.setTextRenderingMode:
32324 stateManager.state.textRenderingMode = args[0];
32325 break;
32326 case OPS.setFillColorSpace:
32327 {
32328 const cachedColorSpace = ColorSpace.getCached(args[0], xref, localColorSpaceCache);
32329 if (cachedColorSpace) {
32330 stateManager.state.fillColorSpace = cachedColorSpace;
32331 continue;
32332 }
32333 next(self.parseColorSpace({
32334 cs: args[0],
32335 resources,
32336 localColorSpaceCache
32337 }).then(function (colorSpace) {
32338 if (colorSpace) {
32339 stateManager.state.fillColorSpace = colorSpace;
32340 }
32341 }));
32342 return;
32343 }
32344 case OPS.setStrokeColorSpace:
32345 {
32346 const cachedColorSpace = ColorSpace.getCached(args[0], xref, localColorSpaceCache);
32347 if (cachedColorSpace) {
32348 stateManager.state.strokeColorSpace = cachedColorSpace;
32349 continue;
32350 }
32351 next(self.parseColorSpace({
32352 cs: args[0],
32353 resources,
32354 localColorSpaceCache
32355 }).then(function (colorSpace) {
32356 if (colorSpace) {
32357 stateManager.state.strokeColorSpace = colorSpace;
32358 }
32359 }));
32360 return;
32361 }
32362 case OPS.setFillColor:
32363 cs = stateManager.state.fillColorSpace;
32364 args = cs.getRgb(args, 0);
32365 fn = OPS.setFillRGBColor;
32366 break;
32367 case OPS.setStrokeColor:
32368 cs = stateManager.state.strokeColorSpace;
32369 args = cs.getRgb(args, 0);
32370 fn = OPS.setStrokeRGBColor;
32371 break;
32372 case OPS.setFillGray:
32373 stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
32374 args = ColorSpace.singletons.gray.getRgb(args, 0);
32375 fn = OPS.setFillRGBColor;
32376 break;
32377 case OPS.setStrokeGray:
32378 stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
32379 args = ColorSpace.singletons.gray.getRgb(args, 0);
32380 fn = OPS.setStrokeRGBColor;
32381 break;
32382 case OPS.setFillCMYKColor:
32383 stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
32384 args = ColorSpace.singletons.cmyk.getRgb(args, 0);
32385 fn = OPS.setFillRGBColor;
32386 break;
32387 case OPS.setStrokeCMYKColor:
32388 stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
32389 args = ColorSpace.singletons.cmyk.getRgb(args, 0);
32390 fn = OPS.setStrokeRGBColor;
32391 break;
32392 case OPS.setFillRGBColor:
32393 stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
32394 args = ColorSpace.singletons.rgb.getRgb(args, 0);
32395 break;
32396 case OPS.setStrokeRGBColor:
32397 stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
32398 args = ColorSpace.singletons.rgb.getRgb(args, 0);
32399 break;
32400 case OPS.setFillColorN:
32401 cs = stateManager.state.fillColorSpace;
32402 if (cs.name === "Pattern") {
32403 next(self.handleColorN(operatorList, OPS.setFillColorN, args, cs, patterns, resources, task, localColorSpaceCache, localTilingPatternCache, localShadingPatternCache));
32404 return;
32405 }
32406 args = cs.getRgb(args, 0);
32407 fn = OPS.setFillRGBColor;
32408 break;
32409 case OPS.setStrokeColorN:
32410 cs = stateManager.state.strokeColorSpace;
32411 if (cs.name === "Pattern") {
32412 next(self.handleColorN(operatorList, OPS.setStrokeColorN, args, cs, patterns, resources, task, localColorSpaceCache, localTilingPatternCache, localShadingPatternCache));
32413 return;
32414 }
32415 args = cs.getRgb(args, 0);
32416 fn = OPS.setStrokeRGBColor;
32417 break;
32418 case OPS.shadingFill:
32419 var shadingRes = resources.get("Shading");
32420 if (!shadingRes) {
32421 throw new FormatError("No shading resource found");
32422 }
32423 var shading = shadingRes.get(args[0].name);
32424 if (!shading) {
32425 throw new FormatError("No shading object found");
32426 }
32427 const patternId = self.parseShading({
32428 shading,
32429 resources,
32430 localColorSpaceCache,
32431 localShadingPatternCache
32432 });
32433 if (!patternId) {
32434 continue;
32435 }
32436 args = [patternId];
32437 fn = OPS.shadingFill;
32438 break;
32439 case OPS.setGState:
32440 isValidName = args[0] instanceof Name;
32441 name = args[0].name;
32442 if (isValidName) {
32443 const localGStateObj = localGStateCache.getByName(name);
32444 if (localGStateObj) {
32445 if (localGStateObj.length > 0) {
32446 operatorList.addOp(OPS.setGState, [localGStateObj]);
32447 }
32448 args = null;
32449 continue;
32450 }
32451 }
32452 next(new Promise(function (resolveGState, rejectGState) {
32453 if (!isValidName) {
32454 throw new FormatError("GState must be referred to by name.");
32455 }
32456 const extGState = resources.get("ExtGState");
32457 if (!(extGState instanceof Dict)) {
32458 throw new FormatError("ExtGState should be a dictionary.");
32459 }
32460 const gState = extGState.get(name);
32461 if (!(gState instanceof Dict)) {
32462 throw new FormatError("GState should be a dictionary.");
32463 }
32464 self.setGState({
32465 resources,
32466 gState,
32467 operatorList,
32468 cacheKey: name,
32469 task,
32470 stateManager,
32471 localGStateCache,
32472 localColorSpaceCache
32473 }).then(resolveGState, rejectGState);
32474 }).catch(function (reason) {
32475 if (reason instanceof AbortException) {
32476 return;
32477 }
32478 if (self.options.ignoreErrors) {
32479 warn(`getOperatorList - ignoring ExtGState: "${reason}".`);
32480 return;
32481 }
32482 throw reason;
32483 }));
32484 return;
32485 case OPS.moveTo:
32486 case OPS.lineTo:
32487 case OPS.curveTo:
32488 case OPS.curveTo2:
32489 case OPS.curveTo3:
32490 case OPS.closePath:
32491 case OPS.rectangle:
32492 self.buildPath(operatorList, fn, args, parsingText);
32493 continue;
32494 case OPS.markPoint:
32495 case OPS.markPointProps:
32496 case OPS.beginCompat:
32497 case OPS.endCompat:
32498 continue;
32499 case OPS.beginMarkedContentProps:
32500 if (!(args[0] instanceof Name)) {
32501 warn(`Expected name for beginMarkedContentProps arg0=${args[0]}`);
32502 operatorList.addOp(OPS.beginMarkedContentProps, ["OC", null]);
32503 continue;
32504 }
32505 if (args[0].name === "OC") {
32506 next(self.parseMarkedContentProps(args[1], resources).then(data => {
32507 operatorList.addOp(OPS.beginMarkedContentProps, ["OC", data]);
32508 }).catch(reason => {
32509 if (reason instanceof AbortException) {
32510 return;
32511 }
32512 if (self.options.ignoreErrors) {
32513 warn(`getOperatorList - ignoring beginMarkedContentProps: "${reason}".`);
32514 operatorList.addOp(OPS.beginMarkedContentProps, ["OC", null]);
32515 return;
32516 }
32517 throw reason;
32518 }));
32519 return;
32520 }
32521 args = [args[0].name, args[1] instanceof Dict ? args[1].get("MCID") : null];
32522 break;
32523 case OPS.beginMarkedContent:
32524 case OPS.endMarkedContent:
32525 default:
32526 if (args !== null) {
32527 for (i = 0, ii = args.length; i < ii; i++) {
32528 if (args[i] instanceof Dict) {
32529 break;
32530 }
32531 }
32532 if (i < ii) {
32533 warn("getOperatorList - ignoring operator: " + fn);
32534 continue;
32535 }
32536 }
32537 }
32538 operatorList.addOp(fn, args);
32539 }
32540 if (stop) {
32541 next(deferred);
32542 return;
32543 }
32544 closePendingRestoreOPS();
32545 resolve();
32546 }).catch(reason => {
32547 if (reason instanceof AbortException) {
32548 return;
32549 }
32550 if (this.options.ignoreErrors) {
32551 warn(`getOperatorList - ignoring errors during "${task.name}" ` + `task: "${reason}".`);
32552 closePendingRestoreOPS();
32553 return;
32554 }
32555 throw reason;
32556 });
32557 }
32558 getTextContent({
32559 stream,
32560 task,
32561 resources,
32562 stateManager = null,
32563 includeMarkedContent = false,
32564 sink,
32565 seenStyles = new Set(),
32566 viewBox,
32567 markedContentData = null,
32568 disableNormalization = false,
32569 keepWhiteSpace = false
32570 }) {
32571 resources ||= Dict.empty;
32572 stateManager ||= new StateManager(new TextState());
32573 if (includeMarkedContent) {
32574 markedContentData ||= {
32575 level: 0
32576 };
32577 }
32578 const textContent = {
32579 items: [],
32580 styles: Object.create(null)
32581 };
32582 const textContentItem = {
32583 initialized: false,
32584 str: [],
32585 totalWidth: 0,
32586 totalHeight: 0,
32587 width: 0,
32588 height: 0,
32589 vertical: false,
32590 prevTransform: null,
32591 textAdvanceScale: 0,
32592 spaceInFlowMin: 0,
32593 spaceInFlowMax: 0,
32594 trackingSpaceMin: Infinity,
32595 negativeSpaceMax: -Infinity,
32596 notASpace: -Infinity,
32597 transform: null,
32598 fontName: null,
32599 hasEOL: false
32600 };
32601 const twoLastChars = [" ", " "];
32602 let twoLastCharsPos = 0;
32603 function saveLastChar(char) {
32604 const nextPos = (twoLastCharsPos + 1) % 2;
32605 const ret = twoLastChars[twoLastCharsPos] !== " " && twoLastChars[nextPos] === " ";
32606 twoLastChars[twoLastCharsPos] = char;
32607 twoLastCharsPos = nextPos;
32608 return !keepWhiteSpace && ret;
32609 }
32610 function shouldAddWhitepsace() {
32611 return !keepWhiteSpace && twoLastChars[twoLastCharsPos] !== " " && twoLastChars[(twoLastCharsPos + 1) % 2] === " ";
32612 }
32613 function resetLastChars() {
32614 twoLastChars[0] = twoLastChars[1] = " ";
32615 twoLastCharsPos = 0;
32616 }
32617 const TRACKING_SPACE_FACTOR = 0.102;
32618 const NOT_A_SPACE_FACTOR = 0.03;
32619 const NEGATIVE_SPACE_FACTOR = -0.2;
32620 const SPACE_IN_FLOW_MIN_FACTOR = 0.102;
32621 const SPACE_IN_FLOW_MAX_FACTOR = 0.6;
32622 const VERTICAL_SHIFT_RATIO = 0.25;
32623 const self = this;
32624 const xref = this.xref;
32625 const showSpacedTextBuffer = [];
32626 let xobjs = null;
32627 const emptyXObjectCache = new LocalImageCache();
32628 const emptyGStateCache = new LocalGStateCache();
32629 const preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
32630 let textState;
32631 function pushWhitespace({
32632 width = 0,
32633 height = 0,
32634 transform = textContentItem.prevTransform,
32635 fontName = textContentItem.fontName
32636 }) {
32637 textContent.items.push({
32638 str: " ",
32639 dir: "ltr",
32640 width,
32641 height,
32642 transform,
32643 fontName,
32644 hasEOL: false
32645 });
32646 }
32647 function getCurrentTextTransform() {
32648 const font = textState.font;
32649 const tsm = [textState.fontSize * textState.textHScale, 0, 0, textState.fontSize, 0, textState.textRise];
32650 if (font.isType3Font && (textState.fontSize <= 1 || font.isCharBBox) && !isArrayEqual(textState.fontMatrix, FONT_IDENTITY_MATRIX)) {
32651 const glyphHeight = font.bbox[3] - font.bbox[1];
32652 if (glyphHeight > 0) {
32653 tsm[3] *= glyphHeight * textState.fontMatrix[3];
32654 }
32655 }
32656 return Util.transform(textState.ctm, Util.transform(textState.textMatrix, tsm));
32657 }
32658 function ensureTextContentItem() {
32659 if (textContentItem.initialized) {
32660 return textContentItem;
32661 }
32662 const {
32663 font,
32664 loadedName
32665 } = textState;
32666 if (!seenStyles.has(loadedName)) {
32667 seenStyles.add(loadedName);
32668 textContent.styles[loadedName] = {
32669 fontFamily: font.fallbackName,
32670 ascent: font.ascent,
32671 descent: font.descent,
32672 vertical: font.vertical
32673 };
32674 if (self.options.fontExtraProperties && font.systemFontInfo) {
32675 const style = textContent.styles[loadedName];
32676 style.fontSubstitution = font.systemFontInfo.css;
32677 style.fontSubstitutionLoadedName = font.systemFontInfo.loadedName;
32678 }
32679 }
32680 textContentItem.fontName = loadedName;
32681 const trm = textContentItem.transform = getCurrentTextTransform();
32682 if (!font.vertical) {
32683 textContentItem.width = textContentItem.totalWidth = 0;
32684 textContentItem.height = textContentItem.totalHeight = Math.hypot(trm[2], trm[3]);
32685 textContentItem.vertical = false;
32686 } else {
32687 textContentItem.width = textContentItem.totalWidth = Math.hypot(trm[0], trm[1]);
32688 textContentItem.height = textContentItem.totalHeight = 0;
32689 textContentItem.vertical = true;
32690 }
32691 const scaleLineX = Math.hypot(textState.textLineMatrix[0], textState.textLineMatrix[1]);
32692 const scaleCtmX = Math.hypot(textState.ctm[0], textState.ctm[1]);
32693 textContentItem.textAdvanceScale = scaleCtmX * scaleLineX;
32694 const {
32695 fontSize
32696 } = textState;
32697 textContentItem.trackingSpaceMin = fontSize * TRACKING_SPACE_FACTOR;
32698 textContentItem.notASpace = fontSize * NOT_A_SPACE_FACTOR;
32699 textContentItem.negativeSpaceMax = fontSize * NEGATIVE_SPACE_FACTOR;
32700 textContentItem.spaceInFlowMin = fontSize * SPACE_IN_FLOW_MIN_FACTOR;
32701 textContentItem.spaceInFlowMax = fontSize * SPACE_IN_FLOW_MAX_FACTOR;
32702 textContentItem.hasEOL = false;
32703 textContentItem.initialized = true;
32704 return textContentItem;
32705 }
32706 function updateAdvanceScale() {
32707 if (!textContentItem.initialized) {
32708 return;
32709 }
32710 const scaleLineX = Math.hypot(textState.textLineMatrix[0], textState.textLineMatrix[1]);
32711 const scaleCtmX = Math.hypot(textState.ctm[0], textState.ctm[1]);
32712 const scaleFactor = scaleCtmX * scaleLineX;
32713 if (scaleFactor === textContentItem.textAdvanceScale) {
32714 return;
32715 }
32716 if (!textContentItem.vertical) {
32717 textContentItem.totalWidth += textContentItem.width * textContentItem.textAdvanceScale;
32718 textContentItem.width = 0;
32719 } else {
32720 textContentItem.totalHeight += textContentItem.height * textContentItem.textAdvanceScale;
32721 textContentItem.height = 0;
32722 }
32723 textContentItem.textAdvanceScale = scaleFactor;
32724 }
32725 function runBidiTransform(textChunk) {
32726 let text = textChunk.str.join("");
32727 if (!disableNormalization) {
32728 text = normalizeUnicode(text);
32729 }
32730 const bidiResult = bidi(text, -1, textChunk.vertical);
32731 return {
32732 str: bidiResult.str,
32733 dir: bidiResult.dir,
32734 width: Math.abs(textChunk.totalWidth),
32735 height: Math.abs(textChunk.totalHeight),
32736 transform: textChunk.transform,
32737 fontName: textChunk.fontName,
32738 hasEOL: textChunk.hasEOL
32739 };
32740 }
32741 async function handleSetFont(fontName, fontRef) {
32742 const translated = await self.loadFont(fontName, fontRef, resources);
32743 if (translated.font.isType3Font) {
32744 try {
32745 await translated.loadType3Data(self, resources, task);
32746 } catch {}
32747 }
32748 textState.loadedName = translated.loadedName;
32749 textState.font = translated.font;
32750 textState.fontMatrix = translated.font.fontMatrix || FONT_IDENTITY_MATRIX;
32751 }
32752 function applyInverseRotation(x, y, matrix) {
32753 const scale = Math.hypot(matrix[0], matrix[1]);
32754 return [(matrix[0] * x + matrix[1] * y) / scale, (matrix[2] * x + matrix[3] * y) / scale];
32755 }
32756 function compareWithLastPosition(glyphWidth) {
32757 const currentTransform = getCurrentTextTransform();
32758 let posX = currentTransform[4];
32759 let posY = currentTransform[5];
32760 if (textState.font?.vertical) {
32761 if (posX < viewBox[0] || posX > viewBox[2] || posY + glyphWidth < viewBox[1] || posY > viewBox[3]) {
32762 return false;
32763 }
32764 } else if (posX + glyphWidth < viewBox[0] || posX > viewBox[2] || posY < viewBox[1] || posY > viewBox[3]) {
32765 return false;
32766 }
32767 if (!textState.font || !textContentItem.prevTransform) {
32768 return true;
32769 }
32770 let lastPosX = textContentItem.prevTransform[4];
32771 let lastPosY = textContentItem.prevTransform[5];
32772 if (lastPosX === posX && lastPosY === posY) {
32773 return true;
32774 }
32775 let rotate = -1;
32776 if (currentTransform[0] && currentTransform[1] === 0 && currentTransform[2] === 0) {
32777 rotate = currentTransform[0] > 0 ? 0 : 180;
32778 } else if (currentTransform[1] && currentTransform[0] === 0 && currentTransform[3] === 0) {
32779 rotate = currentTransform[1] > 0 ? 90 : 270;
32780 }
32781 switch (rotate) {
32782 case 0:
32783 break;
32784 case 90:
32785 [posX, posY] = [posY, posX];
32786 [lastPosX, lastPosY] = [lastPosY, lastPosX];
32787 break;
32788 case 180:
32789 [posX, posY, lastPosX, lastPosY] = [-posX, -posY, -lastPosX, -lastPosY];
32790 break;
32791 case 270:
32792 [posX, posY] = [-posY, -posX];
32793 [lastPosX, lastPosY] = [-lastPosY, -lastPosX];
32794 break;
32795 default:
32796 [posX, posY] = applyInverseRotation(posX, posY, currentTransform);
32797 [lastPosX, lastPosY] = applyInverseRotation(lastPosX, lastPosY, textContentItem.prevTransform);
32798 }
32799 if (textState.font.vertical) {
32800 const advanceY = (lastPosY - posY) / textContentItem.textAdvanceScale;
32801 const advanceX = posX - lastPosX;
32802 const textOrientation = Math.sign(textContentItem.height);
32803 if (advanceY < textOrientation * textContentItem.negativeSpaceMax) {
32804 if (Math.abs(advanceX) > 0.5 * textContentItem.width) {
32805 appendEOL();
32806 return true;
32807 }
32808 resetLastChars();
32809 flushTextContentItem();
32810 return true;
32811 }
32812 if (Math.abs(advanceX) > textContentItem.width) {
32813 appendEOL();
32814 return true;
32815 }
32816 if (advanceY <= textOrientation * textContentItem.notASpace) {
32817 resetLastChars();
32818 }
32819 if (advanceY <= textOrientation * textContentItem.trackingSpaceMin) {
32820 if (shouldAddWhitepsace()) {
32821 resetLastChars();
32822 flushTextContentItem();
32823 pushWhitespace({
32824 height: Math.abs(advanceY)
32825 });
32826 } else {
32827 textContentItem.height += advanceY;
32828 }
32829 } else if (!addFakeSpaces(advanceY, textContentItem.prevTransform, textOrientation)) {
32830 if (textContentItem.str.length === 0) {
32831 resetLastChars();
32832 pushWhitespace({
32833 height: Math.abs(advanceY)
32834 });
32835 } else {
32836 textContentItem.height += advanceY;
32837 }
32838 }
32839 if (Math.abs(advanceX) > textContentItem.width * VERTICAL_SHIFT_RATIO) {
32840 flushTextContentItem();
32841 }
32842 return true;
32843 }
32844 const advanceX = (posX - lastPosX) / textContentItem.textAdvanceScale;
32845 const advanceY = posY - lastPosY;
32846 const textOrientation = Math.sign(textContentItem.width);
32847 if (advanceX < textOrientation * textContentItem.negativeSpaceMax) {
32848 if (Math.abs(advanceY) > 0.5 * textContentItem.height) {
32849 appendEOL();
32850 return true;
32851 }
32852 resetLastChars();
32853 flushTextContentItem();
32854 return true;
32855 }
32856 if (Math.abs(advanceY) > textContentItem.height) {
32857 appendEOL();
32858 return true;
32859 }
32860 if (advanceX <= textOrientation * textContentItem.notASpace) {
32861 resetLastChars();
32862 }
32863 if (advanceX <= textOrientation * textContentItem.trackingSpaceMin) {
32864 if (shouldAddWhitepsace()) {
32865 resetLastChars();
32866 flushTextContentItem();
32867 pushWhitespace({
32868 width: Math.abs(advanceX)
32869 });
32870 } else {
32871 textContentItem.width += advanceX;
32872 }
32873 } else if (!addFakeSpaces(advanceX, textContentItem.prevTransform, textOrientation)) {
32874 if (textContentItem.str.length === 0) {
32875 resetLastChars();
32876 pushWhitespace({
32877 width: Math.abs(advanceX)
32878 });
32879 } else {
32880 textContentItem.width += advanceX;
32881 }
32882 }
32883 if (Math.abs(advanceY) > textContentItem.height * VERTICAL_SHIFT_RATIO) {
32884 flushTextContentItem();
32885 }
32886 return true;
32887 }
32888 function buildTextContentItem({
32889 chars,
32890 extraSpacing
32891 }) {
32892 const font = textState.font;
32893 if (!chars) {
32894 const charSpacing = textState.charSpacing + extraSpacing;
32895 if (charSpacing) {
32896 if (!font.vertical) {
32897 textState.translateTextMatrix(charSpacing * textState.textHScale, 0);
32898 } else {
32899 textState.translateTextMatrix(0, -charSpacing);
32900 }
32901 }
32902 if (keepWhiteSpace) {
32903 compareWithLastPosition(0);
32904 }
32905 return;
32906 }
32907 const glyphs = font.charsToGlyphs(chars);
32908 const scale = textState.fontMatrix[0] * textState.fontSize;
32909 for (let i = 0, ii = glyphs.length; i < ii; i++) {
32910 const glyph = glyphs[i];
32911 const {
32912 category
32913 } = glyph;
32914 if (category.isInvisibleFormatMark) {
32915 continue;
32916 }
32917 let charSpacing = textState.charSpacing + (i + 1 === ii ? extraSpacing : 0);
32918 let glyphWidth = glyph.width;
32919 if (font.vertical) {
32920 glyphWidth = glyph.vmetric ? glyph.vmetric[0] : -glyphWidth;
32921 }
32922 let scaledDim = glyphWidth * scale;
32923 if (!keepWhiteSpace && category.isWhitespace) {
32924 if (!font.vertical) {
32925 charSpacing += scaledDim + textState.wordSpacing;
32926 textState.translateTextMatrix(charSpacing * textState.textHScale, 0);
32927 } else {
32928 charSpacing += -scaledDim + textState.wordSpacing;
32929 textState.translateTextMatrix(0, -charSpacing);
32930 }
32931 saveLastChar(" ");
32932 continue;
32933 }
32934 if (!category.isZeroWidthDiacritic && !compareWithLastPosition(scaledDim)) {
32935 if (!font.vertical) {
32936 textState.translateTextMatrix(scaledDim * textState.textHScale, 0);
32937 } else {
32938 textState.translateTextMatrix(0, scaledDim);
32939 }
32940 continue;
32941 }
32942 const textChunk = ensureTextContentItem();
32943 if (category.isZeroWidthDiacritic) {
32944 scaledDim = 0;
32945 }
32946 if (!font.vertical) {
32947 scaledDim *= textState.textHScale;
32948 textState.translateTextMatrix(scaledDim, 0);
32949 textChunk.width += scaledDim;
32950 } else {
32951 textState.translateTextMatrix(0, scaledDim);
32952 scaledDim = Math.abs(scaledDim);
32953 textChunk.height += scaledDim;
32954 }
32955 if (scaledDim) {
32956 textChunk.prevTransform = getCurrentTextTransform();
32957 }
32958 const glyphUnicode = glyph.unicode;
32959 if (saveLastChar(glyphUnicode)) {
32960 textChunk.str.push(" ");
32961 }
32962 textChunk.str.push(glyphUnicode);
32963 if (charSpacing) {
32964 if (!font.vertical) {
32965 textState.translateTextMatrix(charSpacing * textState.textHScale, 0);
32966 } else {
32967 textState.translateTextMatrix(0, -charSpacing);
32968 }
32969 }
32970 }
32971 }
32972 function appendEOL() {
32973 resetLastChars();
32974 if (textContentItem.initialized) {
32975 textContentItem.hasEOL = true;
32976 flushTextContentItem();
32977 } else {
32978 textContent.items.push({
32979 str: "",
32980 dir: "ltr",
32981 width: 0,
32982 height: 0,
32983 transform: getCurrentTextTransform(),
32984 fontName: textState.loadedName,
32985 hasEOL: true
32986 });
32987 }
32988 }
32989 function addFakeSpaces(width, transf, textOrientation) {
32990 if (textOrientation * textContentItem.spaceInFlowMin <= width && width <= textOrientation * textContentItem.spaceInFlowMax) {
32991 if (textContentItem.initialized) {
32992 resetLastChars();
32993 textContentItem.str.push(" ");
32994 }
32995 return false;
32996 }
32997 const fontName = textContentItem.fontName;
32998 let height = 0;
32999 if (textContentItem.vertical) {
33000 height = width;
33001 width = 0;
33002 }
33003 flushTextContentItem();
33004 resetLastChars();
33005 pushWhitespace({
33006 width: Math.abs(width),
33007 height: Math.abs(height),
33008 transform: transf || getCurrentTextTransform(),
33009 fontName
33010 });
33011 return true;
33012 }
33013 function flushTextContentItem() {
33014 if (!textContentItem.initialized || !textContentItem.str) {
33015 return;
33016 }
33017 if (!textContentItem.vertical) {
33018 textContentItem.totalWidth += textContentItem.width * textContentItem.textAdvanceScale;
33019 } else {
33020 textContentItem.totalHeight += textContentItem.height * textContentItem.textAdvanceScale;
33021 }
33022 textContent.items.push(runBidiTransform(textContentItem));
33023 textContentItem.initialized = false;
33024 textContentItem.str.length = 0;
33025 }
33026 function enqueueChunk(batch = false) {
33027 const length = textContent.items.length;
33028 if (length === 0) {
33029 return;
33030 }
33031 if (batch && length < TEXT_CHUNK_BATCH_SIZE) {
33032 return;
33033 }
33034 sink.enqueue(textContent, length);
33035 textContent.items = [];
33036 textContent.styles = Object.create(null);
33037 }
33038 const timeSlotManager = new TimeSlotManager();
33039 return new Promise(function promiseBody(resolve, reject) {
33040 const next = function (promise) {
33041 enqueueChunk(true);
33042 Promise.all([promise, sink.ready]).then(function () {
33043 try {
33044 promiseBody(resolve, reject);
33045 } catch (ex) {
33046 reject(ex);
33047 }
33048 }, reject);
33049 };
33050 task.ensureNotTerminated();
33051 timeSlotManager.reset();
33052 const operation = {};
33053 let stop,
33054 args = [];
33055 while (!(stop = timeSlotManager.check())) {
33056 args.length = 0;
33057 operation.args = args;
33058 if (!preprocessor.read(operation)) {
33059 break;
33060 }
33061 const previousState = textState;
33062 textState = stateManager.state;
33063 const fn = operation.fn;
33064 args = operation.args;
33065 switch (fn | 0) {
33066 case OPS.setFont:
33067 var fontNameArg = args[0].name,
33068 fontSizeArg = args[1];
33069 if (textState.font && fontNameArg === textState.fontName && fontSizeArg === textState.fontSize) {
33070 break;
33071 }
33072 flushTextContentItem();
33073 textState.fontName = fontNameArg;
33074 textState.fontSize = fontSizeArg;
33075 next(handleSetFont(fontNameArg, null));
33076 return;
33077 case OPS.setTextRise:
33078 textState.textRise = args[0];
33079 break;
33080 case OPS.setHScale:
33081 textState.textHScale = args[0] / 100;
33082 break;
33083 case OPS.setLeading:
33084 textState.leading = args[0];
33085 break;
33086 case OPS.moveText:
33087 textState.translateTextLineMatrix(args[0], args[1]);
33088 textState.textMatrix = textState.textLineMatrix.slice();
33089 break;
33090 case OPS.setLeadingMoveText:
33091 textState.leading = -args[1];
33092 textState.translateTextLineMatrix(args[0], args[1]);
33093 textState.textMatrix = textState.textLineMatrix.slice();
33094 break;
33095 case OPS.nextLine:
33096 textState.carriageReturn();
33097 break;
33098 case OPS.setTextMatrix:
33099 textState.setTextMatrix(args[0], args[1], args[2], args[3], args[4], args[5]);
33100 textState.setTextLineMatrix(args[0], args[1], args[2], args[3], args[4], args[5]);
33101 updateAdvanceScale();
33102 break;
33103 case OPS.setCharSpacing:
33104 textState.charSpacing = args[0];
33105 break;
33106 case OPS.setWordSpacing:
33107 textState.wordSpacing = args[0];
33108 break;
33109 case OPS.beginText:
33110 textState.textMatrix = IDENTITY_MATRIX.slice();
33111 textState.textLineMatrix = IDENTITY_MATRIX.slice();
33112 break;
33113 case OPS.showSpacedText:
33114 if (!stateManager.state.font) {
33115 self.ensureStateFont(stateManager.state);
33116 continue;
33117 }
33118 const spaceFactor = (textState.font.vertical ? 1 : -1) * textState.fontSize / 1000;
33119 const elements = args[0];
33120 for (let i = 0, ii = elements.length; i < ii; i++) {
33121 const item = elements[i];
33122 if (typeof item === "string") {
33123 showSpacedTextBuffer.push(item);
33124 } else if (typeof item === "number" && item !== 0) {
33125 const str = showSpacedTextBuffer.join("");
33126 showSpacedTextBuffer.length = 0;
33127 buildTextContentItem({
33128 chars: str,
33129 extraSpacing: item * spaceFactor
33130 });
33131 }
33132 }
33133 if (showSpacedTextBuffer.length > 0) {
33134 const str = showSpacedTextBuffer.join("");
33135 showSpacedTextBuffer.length = 0;
33136 buildTextContentItem({
33137 chars: str,
33138 extraSpacing: 0
33139 });
33140 }
33141 break;
33142 case OPS.showText:
33143 if (!stateManager.state.font) {
33144 self.ensureStateFont(stateManager.state);
33145 continue;
33146 }
33147 buildTextContentItem({
33148 chars: args[0],
33149 extraSpacing: 0
33150 });
33151 break;
33152 case OPS.nextLineShowText:
33153 if (!stateManager.state.font) {
33154 self.ensureStateFont(stateManager.state);
33155 continue;
33156 }
33157 textState.carriageReturn();
33158 buildTextContentItem({
33159 chars: args[0],
33160 extraSpacing: 0
33161 });
33162 break;
33163 case OPS.nextLineSetSpacingShowText:
33164 if (!stateManager.state.font) {
33165 self.ensureStateFont(stateManager.state);
33166 continue;
33167 }
33168 textState.wordSpacing = args[0];
33169 textState.charSpacing = args[1];
33170 textState.carriageReturn();
33171 buildTextContentItem({
33172 chars: args[2],
33173 extraSpacing: 0
33174 });
33175 break;
33176 case OPS.paintXObject:
33177 flushTextContentItem();
33178 if (!xobjs) {
33179 xobjs = resources.get("XObject") || Dict.empty;
33180 }
33181 var isValidName = args[0] instanceof Name;
33182 var name = args[0].name;
33183 if (isValidName && emptyXObjectCache.getByName(name)) {
33184 break;
33185 }
33186 next(new Promise(function (resolveXObject, rejectXObject) {
33187 if (!isValidName) {
33188 throw new FormatError("XObject must be referred to by name.");
33189 }
33190 let xobj = xobjs.getRaw(name);
33191 if (xobj instanceof Ref) {
33192 if (emptyXObjectCache.getByRef(xobj)) {
33193 resolveXObject();
33194 return;
33195 }
33196 const globalImage = self.globalImageCache.getData(xobj, self.pageIndex);
33197 if (globalImage) {
33198 resolveXObject();
33199 return;
33200 }
33201 xobj = xref.fetch(xobj);
33202 }
33203 if (!(xobj instanceof BaseStream)) {
33204 throw new FormatError("XObject should be a stream");
33205 }
33206 const type = xobj.dict.get("Subtype");
33207 if (!(type instanceof Name)) {
33208 throw new FormatError("XObject should have a Name subtype");
33209 }
33210 if (type.name !== "Form") {
33211 emptyXObjectCache.set(name, xobj.dict.objId, true);
33212 resolveXObject();
33213 return;
33214 }
33215 const currentState = stateManager.state.clone();
33216 const xObjStateManager = new StateManager(currentState);
33217 const matrix = xobj.dict.getArray("Matrix");
33218 if (Array.isArray(matrix) && matrix.length === 6) {
33219 xObjStateManager.transform(matrix);
33220 }
33221 enqueueChunk();
33222 const sinkWrapper = {
33223 enqueueInvoked: false,
33224 enqueue(chunk, size) {
33225 this.enqueueInvoked = true;
33226 sink.enqueue(chunk, size);
33227 },
33228 get desiredSize() {
33229 return sink.desiredSize;
33230 },
33231 get ready() {
33232 return sink.ready;
33233 }
33234 };
33235 self.getTextContent({
33236 stream: xobj,
33237 task,
33238 resources: xobj.dict.get("Resources") || resources,
33239 stateManager: xObjStateManager,
33240 includeMarkedContent,
33241 sink: sinkWrapper,
33242 seenStyles,
33243 viewBox,
33244 markedContentData,
33245 disableNormalization,
33246 keepWhiteSpace
33247 }).then(function () {
33248 if (!sinkWrapper.enqueueInvoked) {
33249 emptyXObjectCache.set(name, xobj.dict.objId, true);
33250 }
33251 resolveXObject();
33252 }, rejectXObject);
33253 }).catch(function (reason) {
33254 if (reason instanceof AbortException) {
33255 return;
33256 }
33257 if (self.options.ignoreErrors) {
33258 warn(`getTextContent - ignoring XObject: "${reason}".`);
33259 return;
33260 }
33261 throw reason;
33262 }));
33263 return;
33264 case OPS.setGState:
33265 isValidName = args[0] instanceof Name;
33266 name = args[0].name;
33267 if (isValidName && emptyGStateCache.getByName(name)) {
33268 break;
33269 }
33270 next(new Promise(function (resolveGState, rejectGState) {
33271 if (!isValidName) {
33272 throw new FormatError("GState must be referred to by name.");
33273 }
33274 const extGState = resources.get("ExtGState");
33275 if (!(extGState instanceof Dict)) {
33276 throw new FormatError("ExtGState should be a dictionary.");
33277 }
33278 const gState = extGState.get(name);
33279 if (!(gState instanceof Dict)) {
33280 throw new FormatError("GState should be a dictionary.");
33281 }
33282 const gStateFont = gState.get("Font");
33283 if (!gStateFont) {
33284 emptyGStateCache.set(name, gState.objId, true);
33285 resolveGState();
33286 return;
33287 }
33288 flushTextContentItem();
33289 textState.fontName = null;
33290 textState.fontSize = gStateFont[1];
33291 handleSetFont(null, gStateFont[0]).then(resolveGState, rejectGState);
33292 }).catch(function (reason) {
33293 if (reason instanceof AbortException) {
33294 return;
33295 }
33296 if (self.options.ignoreErrors) {
33297 warn(`getTextContent - ignoring ExtGState: "${reason}".`);
33298 return;
33299 }
33300 throw reason;
33301 }));
33302 return;
33303 case OPS.beginMarkedContent:
33304 flushTextContentItem();
33305 if (includeMarkedContent) {
33306 markedContentData.level++;
33307 textContent.items.push({
33308 type: "beginMarkedContent",
33309 tag: args[0] instanceof Name ? args[0].name : null
33310 });
33311 }
33312 break;
33313 case OPS.beginMarkedContentProps:
33314 flushTextContentItem();
33315 if (includeMarkedContent) {
33316 markedContentData.level++;
33317 let mcid = null;
33318 if (args[1] instanceof Dict) {
33319 mcid = args[1].get("MCID");
33320 }
33321 textContent.items.push({
33322 type: "beginMarkedContentProps",
33323 id: Number.isInteger(mcid) ? `${self.idFactory.getPageObjId()}_mc${mcid}` : null,
33324 tag: args[0] instanceof Name ? args[0].name : null
33325 });
33326 }
33327 break;
33328 case OPS.endMarkedContent:
33329 flushTextContentItem();
33330 if (includeMarkedContent) {
33331 if (markedContentData.level === 0) {
33332 break;
33333 }
33334 markedContentData.level--;
33335 textContent.items.push({
33336 type: "endMarkedContent"
33337 });
33338 }
33339 break;
33340 case OPS.restore:
33341 if (previousState && (previousState.font !== textState.font || previousState.fontSize !== textState.fontSize || previousState.fontName !== textState.fontName)) {
33342 flushTextContentItem();
33343 }
33344 break;
33345 }
33346 if (textContent.items.length >= sink.desiredSize) {
33347 stop = true;
33348 break;
33349 }
33350 }
33351 if (stop) {
33352 next(deferred);
33353 return;
33354 }
33355 flushTextContentItem();
33356 enqueueChunk();
33357 resolve();
33358 }).catch(reason => {
33359 if (reason instanceof AbortException) {
33360 return;
33361 }
33362 if (this.options.ignoreErrors) {
33363 warn(`getTextContent - ignoring errors during "${task.name}" ` + `task: "${reason}".`);
33364 flushTextContentItem();
33365 enqueueChunk();
33366 return;
33367 }
33368 throw reason;
33369 });
33370 }
33371 async extractDataStructures(dict, properties) {
33372 const xref = this.xref;
33373 let cidToGidBytes;
33374 const toUnicodePromise = this.readToUnicode(properties.toUnicode);
33375 if (properties.composite) {
33376 const cidSystemInfo = dict.get("CIDSystemInfo");
33377 if (cidSystemInfo instanceof Dict) {
33378 properties.cidSystemInfo = {
33379 registry: stringToPDFString(cidSystemInfo.get("Registry")),
33380 ordering: stringToPDFString(cidSystemInfo.get("Ordering")),
33381 supplement: cidSystemInfo.get("Supplement")
33382 };
33383 }
33384 try {
33385 const cidToGidMap = dict.get("CIDToGIDMap");
33386 if (cidToGidMap instanceof BaseStream) {
33387 cidToGidBytes = cidToGidMap.getBytes();
33388 }
33389 } catch (ex) {
33390 if (!this.options.ignoreErrors) {
33391 throw ex;
33392 }
33393 warn(`extractDataStructures - ignoring CIDToGIDMap data: "${ex}".`);
33394 }
33395 }
33396 const differences = [];
33397 let baseEncodingName = null;
33398 let encoding;
33399 if (dict.has("Encoding")) {
33400 encoding = dict.get("Encoding");
33401 if (encoding instanceof Dict) {
33402 baseEncodingName = encoding.get("BaseEncoding");
33403 baseEncodingName = baseEncodingName instanceof Name ? baseEncodingName.name : null;
33404 if (encoding.has("Differences")) {
33405 const diffEncoding = encoding.get("Differences");
33406 let index = 0;
33407 for (const entry of diffEncoding) {
33408 const data = xref.fetchIfRef(entry);
33409 if (typeof data === "number") {
33410 index = data;
33411 } else if (data instanceof Name) {
33412 differences[index++] = data.name;
33413 } else {
33414 throw new FormatError(`Invalid entry in 'Differences' array: ${data}`);
33415 }
33416 }
33417 }
33418 } else if (encoding instanceof Name) {
33419 baseEncodingName = encoding.name;
33420 } else {
33421 const msg = "Encoding is not a Name nor a Dict";
33422 if (!this.options.ignoreErrors) {
33423 throw new FormatError(msg);
33424 }
33425 warn(msg);
33426 }
33427 if (baseEncodingName !== "MacRomanEncoding" && baseEncodingName !== "MacExpertEncoding" && baseEncodingName !== "WinAnsiEncoding") {
33428 baseEncodingName = null;
33429 }
33430 }
33431 const nonEmbeddedFont = !properties.file || properties.isInternalFont,
33432 isSymbolsFontName = getSymbolsFonts()[properties.name];
33433 if (baseEncodingName && nonEmbeddedFont && isSymbolsFontName) {
33434 baseEncodingName = null;
33435 }
33436 if (baseEncodingName) {
33437 properties.defaultEncoding = getEncoding(baseEncodingName);
33438 } else {
33439 const isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
33440 const isNonsymbolicFont = !!(properties.flags & FontFlags.Nonsymbolic);
33441 encoding = StandardEncoding;
33442 if (properties.type === "TrueType" && !isNonsymbolicFont) {
33443 encoding = WinAnsiEncoding;
33444 }
33445 if (isSymbolicFont || isSymbolsFontName) {
33446 encoding = MacRomanEncoding;
33447 if (nonEmbeddedFont) {
33448 if (/Symbol/i.test(properties.name)) {
33449 encoding = SymbolSetEncoding;
33450 } else if (/Dingbats/i.test(properties.name)) {
33451 encoding = ZapfDingbatsEncoding;
33452 } else if (/Wingdings/i.test(properties.name)) {
33453 encoding = WinAnsiEncoding;
33454 }
33455 }
33456 }
33457 properties.defaultEncoding = encoding;
33458 }
33459 properties.differences = differences;
33460 properties.baseEncodingName = baseEncodingName;
33461 properties.hasEncoding = !!baseEncodingName || differences.length > 0;
33462 properties.dict = dict;
33463 properties.toUnicode = await toUnicodePromise;
33464 const builtToUnicode = await this.buildToUnicode(properties);
33465 properties.toUnicode = builtToUnicode;
33466 if (cidToGidBytes) {
33467 properties.cidToGidMap = this.readCidToGidMap(cidToGidBytes, builtToUnicode);
33468 }
33469 return properties;
33470 }
33471 _simpleFontToUnicode(properties, forceGlyphs = false) {
33472 assert(!properties.composite, "Must be a simple font.");
33473 const toUnicode = [];
33474 const encoding = properties.defaultEncoding.slice();
33475 const baseEncodingName = properties.baseEncodingName;
33476 const differences = properties.differences;
33477 for (const charcode in differences) {
33478 const glyphName = differences[charcode];
33479 if (glyphName === ".notdef") {
33480 continue;
33481 }
33482 encoding[charcode] = glyphName;
33483 }
33484 const glyphsUnicodeMap = getGlyphsUnicode();
33485 for (const charcode in encoding) {
33486 let glyphName = encoding[charcode];
33487 if (glyphName === "") {
33488 continue;
33489 }
33490 let unicode = glyphsUnicodeMap[glyphName];
33491 if (unicode !== undefined) {
33492 toUnicode[charcode] = String.fromCharCode(unicode);
33493 continue;
33494 }
33495 let code = 0;
33496 switch (glyphName[0]) {
33497 case "G":
33498 if (glyphName.length === 3) {
33499 code = parseInt(glyphName.substring(1), 16);
33500 }
33501 break;
33502 case "g":
33503 if (glyphName.length === 5) {
33504 code = parseInt(glyphName.substring(1), 16);
33505 }
33506 break;
33507 case "C":
33508 case "c":
33509 if (glyphName.length >= 3 && glyphName.length <= 4) {
33510 const codeStr = glyphName.substring(1);
33511 if (forceGlyphs) {
33512 code = parseInt(codeStr, 16);
33513 break;
33514 }
33515 code = +codeStr;
33516 if (Number.isNaN(code) && Number.isInteger(parseInt(codeStr, 16))) {
33517 return this._simpleFontToUnicode(properties, true);
33518 }
33519 }
33520 break;
33521 case "u":
33522 unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
33523 if (unicode !== -1) {
33524 code = unicode;
33525 }
33526 break;
33527 default:
33528 switch (glyphName) {
33529 case "f_h":
33530 case "f_t":
33531 case "T_h":
33532 toUnicode[charcode] = glyphName.replaceAll("_", "");
33533 continue;
33534 }
33535 break;
33536 }
33537 if (code > 0 && code <= 0x10ffff && Number.isInteger(code)) {
33538 if (baseEncodingName && code === +charcode) {
33539 const baseEncoding = getEncoding(baseEncodingName);
33540 if (baseEncoding && (glyphName = baseEncoding[charcode])) {
33541 toUnicode[charcode] = String.fromCharCode(glyphsUnicodeMap[glyphName]);
33542 continue;
33543 }
33544 }
33545 toUnicode[charcode] = String.fromCodePoint(code);
33546 }
33547 }
33548 return toUnicode;
33549 }
33550 async buildToUnicode(properties) {
33551 properties.hasIncludedToUnicodeMap = properties.toUnicode?.length > 0;
33552 if (properties.hasIncludedToUnicodeMap) {
33553 if (!properties.composite && properties.hasEncoding) {
33554 properties.fallbackToUnicode = this._simpleFontToUnicode(properties);
33555 }
33556 return properties.toUnicode;
33557 }
33558 if (!properties.composite) {
33559 return new ToUnicodeMap(this._simpleFontToUnicode(properties));
33560 }
33561 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"))) {
33562 const {
33563 registry,
33564 ordering
33565 } = properties.cidSystemInfo;
33566 const ucs2CMapName = Name.get(`${registry}-${ordering}-UCS2`);
33567 const ucs2CMap = await CMapFactory.create({
33568 encoding: ucs2CMapName,
33569 fetchBuiltInCMap: this._fetchBuiltInCMapBound,
33570 useCMap: null
33571 });
33572 const toUnicode = [],
33573 buf = [];
33574 properties.cMap.forEach(function (charcode, cid) {
33575 if (cid > 0xffff) {
33576 throw new FormatError("Max size of CID is 65,535");
33577 }
33578 const ucs2 = ucs2CMap.lookup(cid);
33579 if (ucs2) {
33580 buf.length = 0;
33581 for (let i = 0, ii = ucs2.length; i < ii; i += 2) {
33582 buf.push((ucs2.charCodeAt(i) << 8) + ucs2.charCodeAt(i + 1));
33583 }
33584 toUnicode[charcode] = String.fromCharCode(...buf);
33585 }
33586 });
33587 return new ToUnicodeMap(toUnicode);
33588 }
33589 return new IdentityToUnicodeMap(properties.firstChar, properties.lastChar);
33590 }
33591 async readToUnicode(cmapObj) {
33592 if (!cmapObj) {
33593 return null;
33594 }
33595 if (cmapObj instanceof Name) {
33596 const cmap = await CMapFactory.create({
33597 encoding: cmapObj,
33598 fetchBuiltInCMap: this._fetchBuiltInCMapBound,
33599 useCMap: null
33600 });
33601 if (cmap instanceof IdentityCMap) {
33602 return new IdentityToUnicodeMap(0, 0xffff);
33603 }
33604 return new ToUnicodeMap(cmap.getMap());
33605 }
33606 if (cmapObj instanceof BaseStream) {
33607 try {
33608 const cmap = await CMapFactory.create({
33609 encoding: cmapObj,
33610 fetchBuiltInCMap: this._fetchBuiltInCMapBound,
33611 useCMap: null
33612 });
33613 if (cmap instanceof IdentityCMap) {
33614 return new IdentityToUnicodeMap(0, 0xffff);
33615 }
33616 const map = new Array(cmap.length);
33617 cmap.forEach(function (charCode, token) {
33618 if (typeof token === "number") {
33619 map[charCode] = String.fromCodePoint(token);
33620 return;
33621 }
33622 const str = [];
33623 for (let k = 0; k < token.length; k += 2) {
33624 const w1 = token.charCodeAt(k) << 8 | token.charCodeAt(k + 1);
33625 if ((w1 & 0xf800) !== 0xd800) {
33626 str.push(w1);
33627 continue;
33628 }
33629 k += 2;
33630 const w2 = token.charCodeAt(k) << 8 | token.charCodeAt(k + 1);
33631 str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
33632 }
33633 map[charCode] = String.fromCodePoint(...str);
33634 });
33635 return new ToUnicodeMap(map);
33636 } catch (reason) {
33637 if (reason instanceof AbortException) {
33638 return null;
33639 }
33640 if (this.options.ignoreErrors) {
33641 warn(`readToUnicode - ignoring ToUnicode data: "${reason}".`);
33642 return null;
33643 }
33644 throw reason;
33645 }
33646 }
33647 return null;
33648 }
33649 readCidToGidMap(glyphsData, toUnicode) {
33650 const result = [];
33651 for (let j = 0, jj = glyphsData.length; j < jj; j++) {
33652 const glyphID = glyphsData[j++] << 8 | glyphsData[j];
33653 const code = j >> 1;
33654 if (glyphID === 0 && !toUnicode.has(code)) {
33655 continue;
33656 }
33657 result[code] = glyphID;
33658 }
33659 return result;
33660 }
33661 extractWidths(dict, descriptor, properties) {
33662 const xref = this.xref;
33663 let glyphsWidths = [];
33664 let defaultWidth = 0;
33665 const glyphsVMetrics = [];
33666 let defaultVMetrics;
33667 let i, ii, j, jj, start, code, widths;
33668 if (properties.composite) {
33669 defaultWidth = dict.has("DW") ? dict.get("DW") : 1000;
33670 widths = dict.get("W");
33671 if (widths) {
33672 for (i = 0, ii = widths.length; i < ii; i++) {
33673 start = xref.fetchIfRef(widths[i++]);
33674 code = xref.fetchIfRef(widths[i]);
33675 if (Array.isArray(code)) {
33676 for (j = 0, jj = code.length; j < jj; j++) {
33677 glyphsWidths[start++] = xref.fetchIfRef(code[j]);
33678 }
33679 } else {
33680 const width = xref.fetchIfRef(widths[++i]);
33681 for (j = start; j <= code; j++) {
33682 glyphsWidths[j] = width;
33683 }
33684 }
33685 }
33686 }
33687 if (properties.vertical) {
33688 let vmetrics = dict.getArray("DW2") || [880, -1000];
33689 defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
33690 vmetrics = dict.get("W2");
33691 if (vmetrics) {
33692 for (i = 0, ii = vmetrics.length; i < ii; i++) {
33693 start = xref.fetchIfRef(vmetrics[i++]);
33694 code = xref.fetchIfRef(vmetrics[i]);
33695 if (Array.isArray(code)) {
33696 for (j = 0, jj = code.length; j < jj; j++) {
33697 glyphsVMetrics[start++] = [xref.fetchIfRef(code[j++]), xref.fetchIfRef(code[j++]), xref.fetchIfRef(code[j])];
33698 }
33699 } else {
33700 const vmetric = [xref.fetchIfRef(vmetrics[++i]), xref.fetchIfRef(vmetrics[++i]), xref.fetchIfRef(vmetrics[++i])];
33701 for (j = start; j <= code; j++) {
33702 glyphsVMetrics[j] = vmetric;
33703 }
33704 }
33705 }
33706 }
33707 }
33708 } else {
33709 const firstChar = properties.firstChar;
33710 widths = dict.get("Widths");
33711 if (widths) {
33712 j = firstChar;
33713 for (i = 0, ii = widths.length; i < ii; i++) {
33714 glyphsWidths[j++] = xref.fetchIfRef(widths[i]);
33715 }
33716 defaultWidth = parseFloat(descriptor.get("MissingWidth")) || 0;
33717 } else {
33718 const baseFontName = dict.get("BaseFont");
33719 if (baseFontName instanceof Name) {
33720 const metrics = this.getBaseFontMetrics(baseFontName.name);
33721 glyphsWidths = this.buildCharCodeToWidth(metrics.widths, properties);
33722 defaultWidth = metrics.defaultWidth;
33723 }
33724 }
33725 }
33726 let isMonospace = true;
33727 let firstWidth = defaultWidth;
33728 for (const glyph in glyphsWidths) {
33729 const glyphWidth = glyphsWidths[glyph];
33730 if (!glyphWidth) {
33731 continue;
33732 }
33733 if (!firstWidth) {
33734 firstWidth = glyphWidth;
33735 continue;
33736 }
33737 if (firstWidth !== glyphWidth) {
33738 isMonospace = false;
33739 break;
33740 }
33741 }
33742 if (isMonospace) {
33743 properties.flags |= FontFlags.FixedPitch;
33744 } else {
33745 properties.flags &= ~FontFlags.FixedPitch;
33746 }
33747 properties.defaultWidth = defaultWidth;
33748 properties.widths = glyphsWidths;
33749 properties.defaultVMetrics = defaultVMetrics;
33750 properties.vmetrics = glyphsVMetrics;
33751 }
33752 isSerifFont(baseFontName) {
33753 const fontNameWoStyle = baseFontName.split("-", 1)[0];
33754 return fontNameWoStyle in getSerifFonts() || /serif/gi.test(fontNameWoStyle);
33755 }
33756 getBaseFontMetrics(name) {
33757 let defaultWidth = 0;
33758 let widths = Object.create(null);
33759 let monospace = false;
33760 const stdFontMap = getStdFontMap();
33761 let lookupName = stdFontMap[name] || name;
33762 const Metrics = getMetrics();
33763 if (!(lookupName in Metrics)) {
33764 lookupName = this.isSerifFont(name) ? "Times-Roman" : "Helvetica";
33765 }
33766 const glyphWidths = Metrics[lookupName];
33767 if (typeof glyphWidths === "number") {
33768 defaultWidth = glyphWidths;
33769 monospace = true;
33770 } else {
33771 widths = glyphWidths();
33772 }
33773 return {
33774 defaultWidth,
33775 monospace,
33776 widths
33777 };
33778 }
33779 buildCharCodeToWidth(widthsByGlyphName, properties) {
33780 const widths = Object.create(null);
33781 const differences = properties.differences;
33782 const encoding = properties.defaultEncoding;
33783 for (let charCode = 0; charCode < 256; charCode++) {
33784 if (charCode in differences && widthsByGlyphName[differences[charCode]]) {
33785 widths[charCode] = widthsByGlyphName[differences[charCode]];
33786 continue;
33787 }
33788 if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
33789 widths[charCode] = widthsByGlyphName[encoding[charCode]];
33790 continue;
33791 }
33792 }
33793 return widths;
33794 }
33795 preEvaluateFont(dict) {
33796 const baseDict = dict;
33797 let type = dict.get("Subtype");
33798 if (!(type instanceof Name)) {
33799 throw new FormatError("invalid font Subtype");
33800 }
33801 let composite = false;
33802 let hash;
33803 if (type.name === "Type0") {
33804 const df = dict.get("DescendantFonts");
33805 if (!df) {
33806 throw new FormatError("Descendant fonts are not specified");
33807 }
33808 dict = Array.isArray(df) ? this.xref.fetchIfRef(df[0]) : df;
33809 if (!(dict instanceof Dict)) {
33810 throw new FormatError("Descendant font is not a dictionary.");
33811 }
33812 type = dict.get("Subtype");
33813 if (!(type instanceof Name)) {
33814 throw new FormatError("invalid font Subtype");
33815 }
33816 composite = true;
33817 }
33818 const firstChar = dict.get("FirstChar") || 0,
33819 lastChar = dict.get("LastChar") || (composite ? 0xffff : 0xff);
33820 const descriptor = dict.get("FontDescriptor");
33821 const toUnicode = dict.get("ToUnicode") || baseDict.get("ToUnicode");
33822 if (descriptor) {
33823 hash = new MurmurHash3_64();
33824 const encoding = baseDict.getRaw("Encoding");
33825 if (encoding instanceof Name) {
33826 hash.update(encoding.name);
33827 } else if (encoding instanceof Ref) {
33828 hash.update(encoding.toString());
33829 } else if (encoding instanceof Dict) {
33830 for (const entry of encoding.getRawValues()) {
33831 if (entry instanceof Name) {
33832 hash.update(entry.name);
33833 } else if (entry instanceof Ref) {
33834 hash.update(entry.toString());
33835 } else if (Array.isArray(entry)) {
33836 const diffLength = entry.length,
33837 diffBuf = new Array(diffLength);
33838 for (let j = 0; j < diffLength; j++) {
33839 const diffEntry = entry[j];
33840 if (diffEntry instanceof Name) {
33841 diffBuf[j] = diffEntry.name;
33842 } else if (typeof diffEntry === "number" || diffEntry instanceof Ref) {
33843 diffBuf[j] = diffEntry.toString();
33844 }
33845 }
33846 hash.update(diffBuf.join());
33847 }
33848 }
33849 }
33850 hash.update(`${firstChar}-${lastChar}`);
33851 if (toUnicode instanceof BaseStream) {
33852 const stream = toUnicode.str || toUnicode;
33853 const uint8array = stream.buffer ? new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) : new Uint8Array(stream.bytes.buffer, stream.start, stream.end - stream.start);
33854 hash.update(uint8array);
33855 } else if (toUnicode instanceof Name) {
33856 hash.update(toUnicode.name);
33857 }
33858 const widths = dict.get("Widths") || baseDict.get("Widths");
33859 if (Array.isArray(widths)) {
33860 const widthsBuf = [];
33861 for (const entry of widths) {
33862 if (typeof entry === "number" || entry instanceof Ref) {
33863 widthsBuf.push(entry.toString());
33864 }
33865 }
33866 hash.update(widthsBuf.join());
33867 }
33868 if (composite) {
33869 hash.update("compositeFont");
33870 const compositeWidths = dict.get("W") || baseDict.get("W");
33871 if (Array.isArray(compositeWidths)) {
33872 const widthsBuf = [];
33873 for (const entry of compositeWidths) {
33874 if (typeof entry === "number" || entry instanceof Ref) {
33875 widthsBuf.push(entry.toString());
33876 } else if (Array.isArray(entry)) {
33877 const subWidthsBuf = [];
33878 for (const element of entry) {
33879 if (typeof element === "number" || element instanceof Ref) {
33880 subWidthsBuf.push(element.toString());
33881 }
33882 }
33883 widthsBuf.push(`[${subWidthsBuf.join()}]`);
33884 }
33885 }
33886 hash.update(widthsBuf.join());
33887 }
33888 const cidToGidMap = dict.getRaw("CIDToGIDMap") || baseDict.getRaw("CIDToGIDMap");
33889 if (cidToGidMap instanceof Name) {
33890 hash.update(cidToGidMap.name);
33891 } else if (cidToGidMap instanceof Ref) {
33892 hash.update(cidToGidMap.toString());
33893 } else if (cidToGidMap instanceof BaseStream) {
33894 hash.update(cidToGidMap.peekBytes());
33895 }
33896 }
33897 }
33898 return {
33899 descriptor,
33900 dict,
33901 baseDict,
33902 composite,
33903 type: type.name,
33904 firstChar,
33905 lastChar,
33906 toUnicode,
33907 hash: hash ? hash.hexdigest() : ""
33908 };
33909 }
33910 async translateFont({
33911 descriptor,
33912 dict,
33913 baseDict,
33914 composite,
33915 type,
33916 firstChar,
33917 lastChar,
33918 toUnicode,
33919 cssFontInfo
33920 }) {
33921 const isType3Font = type === "Type3";
33922 if (!descriptor) {
33923 if (isType3Font) {
33924 descriptor = new Dict(null);
33925 descriptor.set("FontName", Name.get(type));
33926 descriptor.set("FontBBox", dict.getArray("FontBBox") || [0, 0, 0, 0]);
33927 } else {
33928 let baseFontName = dict.get("BaseFont");
33929 if (!(baseFontName instanceof Name)) {
33930 throw new FormatError("Base font is not specified");
33931 }
33932 baseFontName = baseFontName.name.replaceAll(/[,_]/g, "-");
33933 const metrics = this.getBaseFontMetrics(baseFontName);
33934 const fontNameWoStyle = baseFontName.split("-", 1)[0];
33935 const flags = (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) | (metrics.monospace ? FontFlags.FixedPitch : 0) | (getSymbolsFonts()[fontNameWoStyle] ? FontFlags.Symbolic : FontFlags.Nonsymbolic);
33936 const properties = {
33937 type,
33938 name: baseFontName,
33939 loadedName: baseDict.loadedName,
33940 systemFontInfo: null,
33941 widths: metrics.widths,
33942 defaultWidth: metrics.defaultWidth,
33943 isSimulatedFlags: true,
33944 flags,
33945 firstChar,
33946 lastChar,
33947 toUnicode,
33948 xHeight: 0,
33949 capHeight: 0,
33950 italicAngle: 0,
33951 isType3Font
33952 };
33953 const widths = dict.get("Widths");
33954 const standardFontName = getStandardFontName(baseFontName);
33955 let file = null;
33956 if (standardFontName) {
33957 file = await this.fetchStandardFontData(standardFontName);
33958 properties.isInternalFont = !!file;
33959 }
33960 if (!properties.isInternalFont && this.options.useSystemFonts) {
33961 properties.systemFontInfo = getFontSubstitution(this.systemFontCache, this.idFactory, this.options.standardFontDataUrl, baseFontName, standardFontName);
33962 }
33963 const newProperties = await this.extractDataStructures(dict, properties);
33964 if (widths) {
33965 const glyphWidths = [];
33966 let j = firstChar;
33967 for (const width of widths) {
33968 glyphWidths[j++] = this.xref.fetchIfRef(width);
33969 }
33970 newProperties.widths = glyphWidths;
33971 } else {
33972 newProperties.widths = this.buildCharCodeToWidth(metrics.widths, newProperties);
33973 }
33974 return new Font(baseFontName, file, newProperties);
33975 }
33976 }
33977 let fontName = descriptor.get("FontName");
33978 let baseFont = dict.get("BaseFont");
33979 if (typeof fontName === "string") {
33980 fontName = Name.get(fontName);
33981 }
33982 if (typeof baseFont === "string") {
33983 baseFont = Name.get(baseFont);
33984 }
33985 const fontNameStr = fontName?.name;
33986 const baseFontStr = baseFont?.name;
33987 if (!isType3Font && fontNameStr !== baseFontStr) {
33988 info(`The FontDescriptor's FontName is "${fontNameStr}" but ` + `should be the same as the Font's BaseFont "${baseFontStr}".`);
33989 if (fontNameStr && baseFontStr && (baseFontStr.startsWith(fontNameStr) || !isKnownFontName(fontNameStr) && isKnownFontName(baseFontStr))) {
33990 fontName = null;
33991 }
33992 }
33993 fontName ||= baseFont;
33994 if (!(fontName instanceof Name)) {
33995 throw new FormatError("invalid font name");
33996 }
33997 let fontFile, subtype, length1, length2, length3;
33998 try {
33999 fontFile = descriptor.get("FontFile", "FontFile2", "FontFile3");
34000 } catch (ex) {
34001 if (!this.options.ignoreErrors) {
34002 throw ex;
34003 }
34004 warn(`translateFont - fetching "${fontName.name}" font file: "${ex}".`);
34005 fontFile = new NullStream();
34006 }
34007 let isInternalFont = false;
34008 let glyphScaleFactors = null;
34009 let systemFontInfo = null;
34010 if (fontFile) {
34011 if (fontFile.dict) {
34012 const subtypeEntry = fontFile.dict.get("Subtype");
34013 if (subtypeEntry instanceof Name) {
34014 subtype = subtypeEntry.name;
34015 }
34016 length1 = fontFile.dict.get("Length1");
34017 length2 = fontFile.dict.get("Length2");
34018 length3 = fontFile.dict.get("Length3");
34019 }
34020 } else if (cssFontInfo) {
34021 const standardFontName = getXfaFontName(fontName.name);
34022 if (standardFontName) {
34023 cssFontInfo.fontFamily = `${cssFontInfo.fontFamily}-PdfJS-XFA`;
34024 cssFontInfo.metrics = standardFontName.metrics || null;
34025 glyphScaleFactors = standardFontName.factors || null;
34026 fontFile = await this.fetchStandardFontData(standardFontName.name);
34027 isInternalFont = !!fontFile;
34028 baseDict = dict = getXfaFontDict(fontName.name);
34029 composite = true;
34030 }
34031 } else if (!isType3Font) {
34032 const standardFontName = getStandardFontName(fontName.name);
34033 if (standardFontName) {
34034 fontFile = await this.fetchStandardFontData(standardFontName);
34035 isInternalFont = !!fontFile;
34036 }
34037 if (!isInternalFont && this.options.useSystemFonts) {
34038 systemFontInfo = getFontSubstitution(this.systemFontCache, this.idFactory, this.options.standardFontDataUrl, fontName.name, standardFontName);
34039 }
34040 }
34041 const properties = {
34042 type,
34043 name: fontName.name,
34044 subtype,
34045 file: fontFile,
34046 length1,
34047 length2,
34048 length3,
34049 isInternalFont,
34050 loadedName: baseDict.loadedName,
34051 composite,
34052 fixedPitch: false,
34053 fontMatrix: dict.getArray("FontMatrix") || FONT_IDENTITY_MATRIX,
34054 firstChar,
34055 lastChar,
34056 toUnicode,
34057 bbox: descriptor.getArray("FontBBox") || dict.getArray("FontBBox"),
34058 ascent: descriptor.get("Ascent"),
34059 descent: descriptor.get("Descent"),
34060 xHeight: descriptor.get("XHeight") || 0,
34061 capHeight: descriptor.get("CapHeight") || 0,
34062 flags: descriptor.get("Flags"),
34063 italicAngle: descriptor.get("ItalicAngle") || 0,
34064 isType3Font,
34065 cssFontInfo,
34066 scaleFactors: glyphScaleFactors,
34067 systemFontInfo
34068 };
34069 if (composite) {
34070 const cidEncoding = baseDict.get("Encoding");
34071 if (cidEncoding instanceof Name) {
34072 properties.cidEncoding = cidEncoding.name;
34073 }
34074 const cMap = await CMapFactory.create({
34075 encoding: cidEncoding,
34076 fetchBuiltInCMap: this._fetchBuiltInCMapBound,
34077 useCMap: null
34078 });
34079 properties.cMap = cMap;
34080 properties.vertical = properties.cMap.vertical;
34081 }
34082 const newProperties = await this.extractDataStructures(dict, properties);
34083 this.extractWidths(dict, descriptor, newProperties);
34084 return new Font(fontName.name, fontFile, newProperties);
34085 }
34086 static buildFontPaths(font, glyphs, handler, evaluatorOptions) {
34087 function buildPath(fontChar) {
34088 const glyphName = `${font.loadedName}_path_${fontChar}`;
34089 try {
34090 if (font.renderer.hasBuiltPath(fontChar)) {
34091 return;
34092 }
34093 handler.send("commonobj", [glyphName, "FontPath", font.renderer.getPathJs(fontChar)]);
34094 } catch (reason) {
34095 if (evaluatorOptions.ignoreErrors) {
34096 warn(`buildFontPaths - ignoring ${glyphName} glyph: "${reason}".`);
34097 return;
34098 }
34099 throw reason;
34100 }
34101 }
34102 for (const glyph of glyphs) {
34103 buildPath(glyph.fontChar);
34104 const accent = glyph.accent;
34105 if (accent?.fontChar) {
34106 buildPath(accent.fontChar);
34107 }
34108 }
34109 }
34110 static get fallbackFontDict() {
34111 const dict = new Dict();
34112 dict.set("BaseFont", Name.get("Helvetica"));
34113 dict.set("Type", Name.get("FallbackType"));
34114 dict.set("Subtype", Name.get("FallbackType"));
34115 dict.set("Encoding", Name.get("WinAnsiEncoding"));
34116 return shadow(this, "fallbackFontDict", dict);
34117 }
34118}
34119class TranslatedFont {
34120 constructor({
34121 loadedName,
34122 font,
34123 dict,
34124 evaluatorOptions
34125 }) {
34126 this.loadedName = loadedName;
34127 this.font = font;
34128 this.dict = dict;
34129 this._evaluatorOptions = evaluatorOptions || DefaultPartialEvaluatorOptions;
34130 this.type3Loaded = null;
34131 this.type3Dependencies = font.isType3Font ? new Set() : null;
34132 this.sent = false;
34133 }
34134 send(handler) {
34135 if (this.sent) {
34136 return;
34137 }
34138 this.sent = true;
34139 handler.send("commonobj", [this.loadedName, "Font", this.font.exportData(this._evaluatorOptions.fontExtraProperties)]);
34140 }
34141 fallback(handler) {
34142 if (!this.font.data) {
34143 return;
34144 }
34145 this.font.disableFontFace = true;
34146 PartialEvaluator.buildFontPaths(this.font, this.font.glyphCacheValues, handler, this._evaluatorOptions);
34147 }
34148 loadType3Data(evaluator, resources, task) {
34149 if (this.type3Loaded) {
34150 return this.type3Loaded;
34151 }
34152 if (!this.font.isType3Font) {
34153 throw new Error("Must be a Type3 font.");
34154 }
34155 const type3Evaluator = evaluator.clone({
34156 ignoreErrors: false
34157 });
34158 type3Evaluator.parsingType3Font = true;
34159 const type3FontRefs = new RefSet(evaluator.type3FontRefs);
34160 if (this.dict.objId && !type3FontRefs.has(this.dict.objId)) {
34161 type3FontRefs.put(this.dict.objId);
34162 }
34163 type3Evaluator.type3FontRefs = type3FontRefs;
34164 const translatedFont = this.font,
34165 type3Dependencies = this.type3Dependencies;
34166 let loadCharProcsPromise = Promise.resolve();
34167 const charProcs = this.dict.get("CharProcs");
34168 const fontResources = this.dict.get("Resources") || resources;
34169 const charProcOperatorList = Object.create(null);
34170 const fontBBox = Util.normalizeRect(translatedFont.bbox || [0, 0, 0, 0]),
34171 width = fontBBox[2] - fontBBox[0],
34172 height = fontBBox[3] - fontBBox[1];
34173 const fontBBoxSize = Math.hypot(width, height);
34174 for (const key of charProcs.getKeys()) {
34175 loadCharProcsPromise = loadCharProcsPromise.then(() => {
34176 const glyphStream = charProcs.get(key);
34177 const operatorList = new OperatorList();
34178 return type3Evaluator.getOperatorList({
34179 stream: glyphStream,
34180 task,
34181 resources: fontResources,
34182 operatorList
34183 }).then(() => {
34184 if (operatorList.fnArray[0] === OPS.setCharWidthAndBounds) {
34185 this._removeType3ColorOperators(operatorList, fontBBoxSize);
34186 }
34187 charProcOperatorList[key] = operatorList.getIR();
34188 for (const dependency of operatorList.dependencies) {
34189 type3Dependencies.add(dependency);
34190 }
34191 }).catch(function (reason) {
34192 warn(`Type3 font resource "${key}" is not available.`);
34193 const dummyOperatorList = new OperatorList();
34194 charProcOperatorList[key] = dummyOperatorList.getIR();
34195 });
34196 });
34197 }
34198 this.type3Loaded = loadCharProcsPromise.then(() => {
34199 translatedFont.charProcOperatorList = charProcOperatorList;
34200 if (this._bbox) {
34201 translatedFont.isCharBBox = true;
34202 translatedFont.bbox = this._bbox;
34203 }
34204 });
34205 return this.type3Loaded;
34206 }
34207 _removeType3ColorOperators(operatorList, fontBBoxSize = NaN) {
34208 const charBBox = Util.normalizeRect(operatorList.argsArray[0].slice(2)),
34209 width = charBBox[2] - charBBox[0],
34210 height = charBBox[3] - charBBox[1];
34211 const charBBoxSize = Math.hypot(width, height);
34212 if (width === 0 || height === 0) {
34213 operatorList.fnArray.splice(0, 1);
34214 operatorList.argsArray.splice(0, 1);
34215 } else if (fontBBoxSize === 0 || Math.round(charBBoxSize / fontBBoxSize) >= 10) {
34216 if (!this._bbox) {
34217 this._bbox = [Infinity, Infinity, -Infinity, -Infinity];
34218 }
34219 this._bbox[0] = Math.min(this._bbox[0], charBBox[0]);
34220 this._bbox[1] = Math.min(this._bbox[1], charBBox[1]);
34221 this._bbox[2] = Math.max(this._bbox[2], charBBox[2]);
34222 this._bbox[3] = Math.max(this._bbox[3], charBBox[3]);
34223 }
34224 let i = 0,
34225 ii = operatorList.length;
34226 while (i < ii) {
34227 switch (operatorList.fnArray[i]) {
34228 case OPS.setCharWidthAndBounds:
34229 break;
34230 case OPS.setStrokeColorSpace:
34231 case OPS.setFillColorSpace:
34232 case OPS.setStrokeColor:
34233 case OPS.setStrokeColorN:
34234 case OPS.setFillColor:
34235 case OPS.setFillColorN:
34236 case OPS.setStrokeGray:
34237 case OPS.setFillGray:
34238 case OPS.setStrokeRGBColor:
34239 case OPS.setFillRGBColor:
34240 case OPS.setStrokeCMYKColor:
34241 case OPS.setFillCMYKColor:
34242 case OPS.shadingFill:
34243 case OPS.setRenderingIntent:
34244 operatorList.fnArray.splice(i, 1);
34245 operatorList.argsArray.splice(i, 1);
34246 ii--;
34247 continue;
34248 case OPS.setGState:
34249 const [gStateObj] = operatorList.argsArray[i];
34250 let j = 0,
34251 jj = gStateObj.length;
34252 while (j < jj) {
34253 const [gStateKey] = gStateObj[j];
34254 switch (gStateKey) {
34255 case "TR":
34256 case "TR2":
34257 case "HT":
34258 case "BG":
34259 case "BG2":
34260 case "UCR":
34261 case "UCR2":
34262 gStateObj.splice(j, 1);
34263 jj--;
34264 continue;
34265 }
34266 j++;
34267 }
34268 break;
34269 }
34270 i++;
34271 }
34272 }
34273}
34274class StateManager {
34275 constructor(initialState = new EvalState()) {
34276 this.state = initialState;
34277 this.stateStack = [];
34278 }
34279 save() {
34280 const old = this.state;
34281 this.stateStack.push(this.state);
34282 this.state = old.clone();
34283 }
34284 restore() {
34285 const prev = this.stateStack.pop();
34286 if (prev) {
34287 this.state = prev;
34288 }
34289 }
34290 transform(args) {
34291 this.state.ctm = Util.transform(this.state.ctm, args);
34292 }
34293}
34294class TextState {
34295 constructor() {
34296 this.ctm = new Float32Array(IDENTITY_MATRIX);
34297 this.fontName = null;
34298 this.fontSize = 0;
34299 this.loadedName = null;
34300 this.font = null;
34301 this.fontMatrix = FONT_IDENTITY_MATRIX;
34302 this.textMatrix = IDENTITY_MATRIX.slice();
34303 this.textLineMatrix = IDENTITY_MATRIX.slice();
34304 this.charSpacing = 0;
34305 this.wordSpacing = 0;
34306 this.leading = 0;
34307 this.textHScale = 1;
34308 this.textRise = 0;
34309 }
34310 setTextMatrix(a, b, c, d, e, f) {
34311 const m = this.textMatrix;
34312 m[0] = a;
34313 m[1] = b;
34314 m[2] = c;
34315 m[3] = d;
34316 m[4] = e;
34317 m[5] = f;
34318 }
34319 setTextLineMatrix(a, b, c, d, e, f) {
34320 const m = this.textLineMatrix;
34321 m[0] = a;
34322 m[1] = b;
34323 m[2] = c;
34324 m[3] = d;
34325 m[4] = e;
34326 m[5] = f;
34327 }
34328 translateTextMatrix(x, y) {
34329 const m = this.textMatrix;
34330 m[4] = m[0] * x + m[2] * y + m[4];
34331 m[5] = m[1] * x + m[3] * y + m[5];
34332 }
34333 translateTextLineMatrix(x, y) {
34334 const m = this.textLineMatrix;
34335 m[4] = m[0] * x + m[2] * y + m[4];
34336 m[5] = m[1] * x + m[3] * y + m[5];
34337 }
34338 carriageReturn() {
34339 this.translateTextLineMatrix(0, -this.leading);
34340 this.textMatrix = this.textLineMatrix.slice();
34341 }
34342 clone() {
34343 const clone = Object.create(this);
34344 clone.textMatrix = this.textMatrix.slice();
34345 clone.textLineMatrix = this.textLineMatrix.slice();
34346 clone.fontMatrix = this.fontMatrix.slice();
34347 return clone;
34348 }
34349}
34350class EvalState {
34351 constructor() {
34352 this.ctm = new Float32Array(IDENTITY_MATRIX);
34353 this.font = null;
34354 this.textRenderingMode = TextRenderingMode.FILL;
34355 this.fillColorSpace = ColorSpace.singletons.gray;
34356 this.strokeColorSpace = ColorSpace.singletons.gray;
34357 }
34358 clone() {
34359 return Object.create(this);
34360 }
34361}
34362class EvaluatorPreprocessor {
34363 static get opMap() {
34364 return shadow(this, "opMap", Object.assign(Object.create(null), {
34365 w: {
34366 id: OPS.setLineWidth,
34367 numArgs: 1,
34368 variableArgs: false
34369 },
34370 J: {
34371 id: OPS.setLineCap,
34372 numArgs: 1,
34373 variableArgs: false
34374 },
34375 j: {
34376 id: OPS.setLineJoin,
34377 numArgs: 1,
34378 variableArgs: false
34379 },
34380 M: {
34381 id: OPS.setMiterLimit,
34382 numArgs: 1,
34383 variableArgs: false
34384 },
34385 d: {
34386 id: OPS.setDash,
34387 numArgs: 2,
34388 variableArgs: false
34389 },
34390 ri: {
34391 id: OPS.setRenderingIntent,
34392 numArgs: 1,
34393 variableArgs: false
34394 },
34395 i: {
34396 id: OPS.setFlatness,
34397 numArgs: 1,
34398 variableArgs: false
34399 },
34400 gs: {
34401 id: OPS.setGState,
34402 numArgs: 1,
34403 variableArgs: false
34404 },
34405 q: {
34406 id: OPS.save,
34407 numArgs: 0,
34408 variableArgs: false
34409 },
34410 Q: {
34411 id: OPS.restore,
34412 numArgs: 0,
34413 variableArgs: false
34414 },
34415 cm: {
34416 id: OPS.transform,
34417 numArgs: 6,
34418 variableArgs: false
34419 },
34420 m: {
34421 id: OPS.moveTo,
34422 numArgs: 2,
34423 variableArgs: false
34424 },
34425 l: {
34426 id: OPS.lineTo,
34427 numArgs: 2,
34428 variableArgs: false
34429 },
34430 c: {
34431 id: OPS.curveTo,
34432 numArgs: 6,
34433 variableArgs: false
34434 },
34435 v: {
34436 id: OPS.curveTo2,
34437 numArgs: 4,
34438 variableArgs: false
34439 },
34440 y: {
34441 id: OPS.curveTo3,
34442 numArgs: 4,
34443 variableArgs: false
34444 },
34445 h: {
34446 id: OPS.closePath,
34447 numArgs: 0,
34448 variableArgs: false
34449 },
34450 re: {
34451 id: OPS.rectangle,
34452 numArgs: 4,
34453 variableArgs: false
34454 },
34455 S: {
34456 id: OPS.stroke,
34457 numArgs: 0,
34458 variableArgs: false
34459 },
34460 s: {
34461 id: OPS.closeStroke,
34462 numArgs: 0,
34463 variableArgs: false
34464 },
34465 f: {
34466 id: OPS.fill,
34467 numArgs: 0,
34468 variableArgs: false
34469 },
34470 F: {
34471 id: OPS.fill,
34472 numArgs: 0,
34473 variableArgs: false
34474 },
34475 "f*": {
34476 id: OPS.eoFill,
34477 numArgs: 0,
34478 variableArgs: false
34479 },
34480 B: {
34481 id: OPS.fillStroke,
34482 numArgs: 0,
34483 variableArgs: false
34484 },
34485 "B*": {
34486 id: OPS.eoFillStroke,
34487 numArgs: 0,
34488 variableArgs: false
34489 },
34490 b: {
34491 id: OPS.closeFillStroke,
34492 numArgs: 0,
34493 variableArgs: false
34494 },
34495 "b*": {
34496 id: OPS.closeEOFillStroke,
34497 numArgs: 0,
34498 variableArgs: false
34499 },
34500 n: {
34501 id: OPS.endPath,
34502 numArgs: 0,
34503 variableArgs: false
34504 },
34505 W: {
34506 id: OPS.clip,
34507 numArgs: 0,
34508 variableArgs: false
34509 },
34510 "W*": {
34511 id: OPS.eoClip,
34512 numArgs: 0,
34513 variableArgs: false
34514 },
34515 BT: {
34516 id: OPS.beginText,
34517 numArgs: 0,
34518 variableArgs: false
34519 },
34520 ET: {
34521 id: OPS.endText,
34522 numArgs: 0,
34523 variableArgs: false
34524 },
34525 Tc: {
34526 id: OPS.setCharSpacing,
34527 numArgs: 1,
34528 variableArgs: false
34529 },
34530 Tw: {
34531 id: OPS.setWordSpacing,
34532 numArgs: 1,
34533 variableArgs: false
34534 },
34535 Tz: {
34536 id: OPS.setHScale,
34537 numArgs: 1,
34538 variableArgs: false
34539 },
34540 TL: {
34541 id: OPS.setLeading,
34542 numArgs: 1,
34543 variableArgs: false
34544 },
34545 Tf: {
34546 id: OPS.setFont,
34547 numArgs: 2,
34548 variableArgs: false
34549 },
34550 Tr: {
34551 id: OPS.setTextRenderingMode,
34552 numArgs: 1,
34553 variableArgs: false
34554 },
34555 Ts: {
34556 id: OPS.setTextRise,
34557 numArgs: 1,
34558 variableArgs: false
34559 },
34560 Td: {
34561 id: OPS.moveText,
34562 numArgs: 2,
34563 variableArgs: false
34564 },
34565 TD: {
34566 id: OPS.setLeadingMoveText,
34567 numArgs: 2,
34568 variableArgs: false
34569 },
34570 Tm: {
34571 id: OPS.setTextMatrix,
34572 numArgs: 6,
34573 variableArgs: false
34574 },
34575 "T*": {
34576 id: OPS.nextLine,
34577 numArgs: 0,
34578 variableArgs: false
34579 },
34580 Tj: {
34581 id: OPS.showText,
34582 numArgs: 1,
34583 variableArgs: false
34584 },
34585 TJ: {
34586 id: OPS.showSpacedText,
34587 numArgs: 1,
34588 variableArgs: false
34589 },
34590 "'": {
34591 id: OPS.nextLineShowText,
34592 numArgs: 1,
34593 variableArgs: false
34594 },
34595 '"': {
34596 id: OPS.nextLineSetSpacingShowText,
34597 numArgs: 3,
34598 variableArgs: false
34599 },
34600 d0: {
34601 id: OPS.setCharWidth,
34602 numArgs: 2,
34603 variableArgs: false
34604 },
34605 d1: {
34606 id: OPS.setCharWidthAndBounds,
34607 numArgs: 6,
34608 variableArgs: false
34609 },
34610 CS: {
34611 id: OPS.setStrokeColorSpace,
34612 numArgs: 1,
34613 variableArgs: false
34614 },
34615 cs: {
34616 id: OPS.setFillColorSpace,
34617 numArgs: 1,
34618 variableArgs: false
34619 },
34620 SC: {
34621 id: OPS.setStrokeColor,
34622 numArgs: 4,
34623 variableArgs: true
34624 },
34625 SCN: {
34626 id: OPS.setStrokeColorN,
34627 numArgs: 33,
34628 variableArgs: true
34629 },
34630 sc: {
34631 id: OPS.setFillColor,
34632 numArgs: 4,
34633 variableArgs: true
34634 },
34635 scn: {
34636 id: OPS.setFillColorN,
34637 numArgs: 33,
34638 variableArgs: true
34639 },
34640 G: {
34641 id: OPS.setStrokeGray,
34642 numArgs: 1,
34643 variableArgs: false
34644 },
34645 g: {
34646 id: OPS.setFillGray,
34647 numArgs: 1,
34648 variableArgs: false
34649 },
34650 RG: {
34651 id: OPS.setStrokeRGBColor,
34652 numArgs: 3,
34653 variableArgs: false
34654 },
34655 rg: {
34656 id: OPS.setFillRGBColor,
34657 numArgs: 3,
34658 variableArgs: false
34659 },
34660 K: {
34661 id: OPS.setStrokeCMYKColor,
34662 numArgs: 4,
34663 variableArgs: false
34664 },
34665 k: {
34666 id: OPS.setFillCMYKColor,
34667 numArgs: 4,
34668 variableArgs: false
34669 },
34670 sh: {
34671 id: OPS.shadingFill,
34672 numArgs: 1,
34673 variableArgs: false
34674 },
34675 BI: {
34676 id: OPS.beginInlineImage,
34677 numArgs: 0,
34678 variableArgs: false
34679 },
34680 ID: {
34681 id: OPS.beginImageData,
34682 numArgs: 0,
34683 variableArgs: false
34684 },
34685 EI: {
34686 id: OPS.endInlineImage,
34687 numArgs: 1,
34688 variableArgs: false
34689 },
34690 Do: {
34691 id: OPS.paintXObject,
34692 numArgs: 1,
34693 variableArgs: false
34694 },
34695 MP: {
34696 id: OPS.markPoint,
34697 numArgs: 1,
34698 variableArgs: false
34699 },
34700 DP: {
34701 id: OPS.markPointProps,
34702 numArgs: 2,
34703 variableArgs: false
34704 },
34705 BMC: {
34706 id: OPS.beginMarkedContent,
34707 numArgs: 1,
34708 variableArgs: false
34709 },
34710 BDC: {
34711 id: OPS.beginMarkedContentProps,
34712 numArgs: 2,
34713 variableArgs: false
34714 },
34715 EMC: {
34716 id: OPS.endMarkedContent,
34717 numArgs: 0,
34718 variableArgs: false
34719 },
34720 BX: {
34721 id: OPS.beginCompat,
34722 numArgs: 0,
34723 variableArgs: false
34724 },
34725 EX: {
34726 id: OPS.endCompat,
34727 numArgs: 0,
34728 variableArgs: false
34729 },
34730 BM: null,
34731 BD: null,
34732 true: null,
34733 fa: null,
34734 fal: null,
34735 fals: null,
34736 false: null,
34737 nu: null,
34738 nul: null,
34739 null: null
34740 }));
34741 }
34742 static MAX_INVALID_PATH_OPS = 10;
34743 constructor(stream, xref, stateManager = new StateManager()) {
34744 this.parser = new Parser({
34745 lexer: new Lexer(stream, EvaluatorPreprocessor.opMap),
34746 xref
34747 });
34748 this.stateManager = stateManager;
34749 this.nonProcessedArgs = [];
34750 this._isPathOp = false;
34751 this._numInvalidPathOPS = 0;
34752 }
34753 get savedStatesDepth() {
34754 return this.stateManager.stateStack.length;
34755 }
34756 read(operation) {
34757 let args = operation.args;
34758 while (true) {
34759 const obj = this.parser.getObj();
34760 if (obj instanceof Cmd) {
34761 const cmd = obj.cmd;
34762 const opSpec = EvaluatorPreprocessor.opMap[cmd];
34763 if (!opSpec) {
34764 warn(`Unknown command "${cmd}".`);
34765 continue;
34766 }
34767 const fn = opSpec.id;
34768 const numArgs = opSpec.numArgs;
34769 let argsLength = args !== null ? args.length : 0;
34770 if (!this._isPathOp) {
34771 this._numInvalidPathOPS = 0;
34772 }
34773 this._isPathOp = fn >= OPS.moveTo && fn <= OPS.endPath;
34774 if (!opSpec.variableArgs) {
34775 if (argsLength !== numArgs) {
34776 const nonProcessedArgs = this.nonProcessedArgs;
34777 while (argsLength > numArgs) {
34778 nonProcessedArgs.push(args.shift());
34779 argsLength--;
34780 }
34781 while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
34782 if (args === null) {
34783 args = [];
34784 }
34785 args.unshift(nonProcessedArgs.pop());
34786 argsLength++;
34787 }
34788 }
34789 if (argsLength < numArgs) {
34790 const partialMsg = `command ${cmd}: expected ${numArgs} args, ` + `but received ${argsLength} args.`;
34791 if (this._isPathOp && ++this._numInvalidPathOPS > EvaluatorPreprocessor.MAX_INVALID_PATH_OPS) {
34792 throw new FormatError(`Invalid ${partialMsg}`);
34793 }
34794 warn(`Skipping ${partialMsg}`);
34795 if (args !== null) {
34796 args.length = 0;
34797 }
34798 continue;
34799 }
34800 } else if (argsLength > numArgs) {
34801 info(`Command ${cmd}: expected [0, ${numArgs}] args, ` + `but received ${argsLength} args.`);
34802 }
34803 this.preprocessCommand(fn, args);
34804 operation.fn = fn;
34805 operation.args = args;
34806 return true;
34807 }
34808 if (obj === EOF) {
34809 return false;
34810 }
34811 if (obj !== null) {
34812 if (args === null) {
34813 args = [];
34814 }
34815 args.push(obj);
34816 if (args.length > 33) {
34817 throw new FormatError("Too many arguments");
34818 }
34819 }
34820 }
34821 }
34822 preprocessCommand(fn, args) {
34823 switch (fn | 0) {
34824 case OPS.save:
34825 this.stateManager.save();
34826 break;
34827 case OPS.restore:
34828 this.stateManager.restore();
34829 break;
34830 case OPS.transform:
34831 this.stateManager.transform(args);
34832 break;
34833 }
34834 }
34835}
34836
34837;// CONCATENATED MODULE: ./src/core/default_appearance.js
34838
34839
34840
34841
34842
34843
34844
34845
34846class DefaultAppearanceEvaluator extends EvaluatorPreprocessor {
34847 constructor(str) {
34848 super(new StringStream(str));
34849 }
34850 parse() {
34851 const operation = {
34852 fn: 0,
34853 args: []
34854 };
34855 const result = {
34856 fontSize: 0,
34857 fontName: "",
34858 fontColor: new Uint8ClampedArray(3)
34859 };
34860 try {
34861 while (true) {
34862 operation.args.length = 0;
34863 if (!this.read(operation)) {
34864 break;
34865 }
34866 if (this.savedStatesDepth !== 0) {
34867 continue;
34868 }
34869 const {
34870 fn,
34871 args
34872 } = operation;
34873 switch (fn | 0) {
34874 case OPS.setFont:
34875 const [fontName, fontSize] = args;
34876 if (fontName instanceof Name) {
34877 result.fontName = fontName.name;
34878 }
34879 if (typeof fontSize === "number" && fontSize > 0) {
34880 result.fontSize = fontSize;
34881 }
34882 break;
34883 case OPS.setFillRGBColor:
34884 ColorSpace.singletons.rgb.getRgbItem(args, 0, result.fontColor, 0);
34885 break;
34886 case OPS.setFillGray:
34887 ColorSpace.singletons.gray.getRgbItem(args, 0, result.fontColor, 0);
34888 break;
34889 case OPS.setFillCMYKColor:
34890 ColorSpace.singletons.cmyk.getRgbItem(args, 0, result.fontColor, 0);
34891 break;
34892 }
34893 }
34894 } catch (reason) {
34895 warn(`parseDefaultAppearance - ignoring errors: "${reason}".`);
34896 }
34897 return result;
34898 }
34899}
34900function parseDefaultAppearance(str) {
34901 return new DefaultAppearanceEvaluator(str).parse();
34902}
34903class AppearanceStreamEvaluator extends EvaluatorPreprocessor {
34904 constructor(stream, evaluatorOptions, xref) {
34905 super(stream);
34906 this.stream = stream;
34907 this.evaluatorOptions = evaluatorOptions;
34908 this.xref = xref;
34909 this.resources = stream.dict?.get("Resources");
34910 }
34911 parse() {
34912 const operation = {
34913 fn: 0,
34914 args: []
34915 };
34916 let result = {
34917 scaleFactor: 1,
34918 fontSize: 0,
34919 fontName: "",
34920 fontColor: new Uint8ClampedArray(3),
34921 fillColorSpace: ColorSpace.singletons.gray
34922 };
34923 let breakLoop = false;
34924 const stack = [];
34925 try {
34926 while (true) {
34927 operation.args.length = 0;
34928 if (breakLoop || !this.read(operation)) {
34929 break;
34930 }
34931 const {
34932 fn,
34933 args
34934 } = operation;
34935 switch (fn | 0) {
34936 case OPS.save:
34937 stack.push({
34938 scaleFactor: result.scaleFactor,
34939 fontSize: result.fontSize,
34940 fontName: result.fontName,
34941 fontColor: result.fontColor.slice(),
34942 fillColorSpace: result.fillColorSpace
34943 });
34944 break;
34945 case OPS.restore:
34946 result = stack.pop() || result;
34947 break;
34948 case OPS.setTextMatrix:
34949 result.scaleFactor *= Math.hypot(args[0], args[1]);
34950 break;
34951 case OPS.setFont:
34952 const [fontName, fontSize] = args;
34953 if (fontName instanceof Name) {
34954 result.fontName = fontName.name;
34955 }
34956 if (typeof fontSize === "number" && fontSize > 0) {
34957 result.fontSize = fontSize * result.scaleFactor;
34958 }
34959 break;
34960 case OPS.setFillColorSpace:
34961 result.fillColorSpace = ColorSpace.parse({
34962 cs: args[0],
34963 xref: this.xref,
34964 resources: this.resources,
34965 pdfFunctionFactory: this._pdfFunctionFactory,
34966 localColorSpaceCache: this._localColorSpaceCache
34967 });
34968 break;
34969 case OPS.setFillColor:
34970 const cs = result.fillColorSpace;
34971 cs.getRgbItem(args, 0, result.fontColor, 0);
34972 break;
34973 case OPS.setFillRGBColor:
34974 ColorSpace.singletons.rgb.getRgbItem(args, 0, result.fontColor, 0);
34975 break;
34976 case OPS.setFillGray:
34977 ColorSpace.singletons.gray.getRgbItem(args, 0, result.fontColor, 0);
34978 break;
34979 case OPS.setFillCMYKColor:
34980 ColorSpace.singletons.cmyk.getRgbItem(args, 0, result.fontColor, 0);
34981 break;
34982 case OPS.showText:
34983 case OPS.showSpacedText:
34984 case OPS.nextLineShowText:
34985 case OPS.nextLineSetSpacingShowText:
34986 breakLoop = true;
34987 break;
34988 }
34989 }
34990 } catch (reason) {
34991 warn(`parseAppearanceStream - ignoring errors: "${reason}".`);
34992 }
34993 this.stream.reset();
34994 delete result.scaleFactor;
34995 delete result.fillColorSpace;
34996 return result;
34997 }
34998 get _localColorSpaceCache() {
34999 return shadow(this, "_localColorSpaceCache", new LocalColorSpaceCache());
35000 }
35001 get _pdfFunctionFactory() {
35002 const pdfFunctionFactory = new PDFFunctionFactory({
35003 xref: this.xref,
35004 isEvalSupported: this.evaluatorOptions.isEvalSupported
35005 });
35006 return shadow(this, "_pdfFunctionFactory", pdfFunctionFactory);
35007 }
35008}
35009function parseAppearanceStream(stream, evaluatorOptions, xref) {
35010 return new AppearanceStreamEvaluator(stream, evaluatorOptions, xref).parse();
35011}
35012function getPdfColor(color, isFill) {
35013 if (color[0] === color[1] && color[1] === color[2]) {
35014 const gray = color[0] / 255;
35015 return `${numberToString(gray)} ${isFill ? "g" : "G"}`;
35016 }
35017 return Array.from(color, c => numberToString(c / 255)).join(" ") + ` ${isFill ? "rg" : "RG"}`;
35018}
35019function createDefaultAppearance({
35020 fontSize,
35021 fontName,
35022 fontColor
35023}) {
35024 return `/${escapePDFName(fontName)} ${fontSize} Tf ${getPdfColor(fontColor, true)}`;
35025}
35026class FakeUnicodeFont {
35027 constructor(xref, fontFamily) {
35028 this.xref = xref;
35029 this.widths = null;
35030 this.firstChar = Infinity;
35031 this.lastChar = -Infinity;
35032 this.fontFamily = fontFamily;
35033 const canvas = new OffscreenCanvas(1, 1);
35034 this.ctxMeasure = canvas.getContext("2d");
35035 if (!FakeUnicodeFont._fontNameId) {
35036 FakeUnicodeFont._fontNameId = 1;
35037 }
35038 this.fontName = Name.get(`InvalidPDFjsFont_${fontFamily}_${FakeUnicodeFont._fontNameId++}`);
35039 }
35040 get fontDescriptorRef() {
35041 if (!FakeUnicodeFont._fontDescriptorRef) {
35042 const fontDescriptor = new Dict(this.xref);
35043 fontDescriptor.set("Type", Name.get("FontDescriptor"));
35044 fontDescriptor.set("FontName", this.fontName);
35045 fontDescriptor.set("FontFamily", "MyriadPro Regular");
35046 fontDescriptor.set("FontBBox", [0, 0, 0, 0]);
35047 fontDescriptor.set("FontStretch", Name.get("Normal"));
35048 fontDescriptor.set("FontWeight", 400);
35049 fontDescriptor.set("ItalicAngle", 0);
35050 FakeUnicodeFont._fontDescriptorRef = this.xref.getNewPersistentRef(fontDescriptor);
35051 }
35052 return FakeUnicodeFont._fontDescriptorRef;
35053 }
35054 get descendantFontRef() {
35055 const descendantFont = new Dict(this.xref);
35056 descendantFont.set("BaseFont", this.fontName);
35057 descendantFont.set("Type", Name.get("Font"));
35058 descendantFont.set("Subtype", Name.get("CIDFontType0"));
35059 descendantFont.set("CIDToGIDMap", Name.get("Identity"));
35060 descendantFont.set("FirstChar", this.firstChar);
35061 descendantFont.set("LastChar", this.lastChar);
35062 descendantFont.set("FontDescriptor", this.fontDescriptorRef);
35063 descendantFont.set("DW", 1000);
35064 const widths = [];
35065 const chars = [...this.widths.entries()].sort();
35066 let currentChar = null;
35067 let currentWidths = null;
35068 for (const [char, width] of chars) {
35069 if (!currentChar) {
35070 currentChar = char;
35071 currentWidths = [width];
35072 continue;
35073 }
35074 if (char === currentChar + currentWidths.length) {
35075 currentWidths.push(width);
35076 } else {
35077 widths.push(currentChar, currentWidths);
35078 currentChar = char;
35079 currentWidths = [width];
35080 }
35081 }
35082 if (currentChar) {
35083 widths.push(currentChar, currentWidths);
35084 }
35085 descendantFont.set("W", widths);
35086 const cidSystemInfo = new Dict(this.xref);
35087 cidSystemInfo.set("Ordering", "Identity");
35088 cidSystemInfo.set("Registry", "Adobe");
35089 cidSystemInfo.set("Supplement", 0);
35090 descendantFont.set("CIDSystemInfo", cidSystemInfo);
35091 return this.xref.getNewPersistentRef(descendantFont);
35092 }
35093 get baseFontRef() {
35094 const baseFont = new Dict(this.xref);
35095 baseFont.set("BaseFont", this.fontName);
35096 baseFont.set("Type", Name.get("Font"));
35097 baseFont.set("Subtype", Name.get("Type0"));
35098 baseFont.set("Encoding", Name.get("Identity-H"));
35099 baseFont.set("DescendantFonts", [this.descendantFontRef]);
35100 baseFont.set("ToUnicode", Name.get("Identity-H"));
35101 return this.xref.getNewPersistentRef(baseFont);
35102 }
35103 get resources() {
35104 const resources = new Dict(this.xref);
35105 const font = new Dict(this.xref);
35106 font.set(this.fontName.name, this.baseFontRef);
35107 resources.set("Font", font);
35108 return resources;
35109 }
35110 _createContext() {
35111 this.widths = new Map();
35112 this.ctxMeasure.font = `1000px ${this.fontFamily}`;
35113 return this.ctxMeasure;
35114 }
35115 createFontResources(text) {
35116 const ctx = this._createContext();
35117 for (const line of text.split(/\r\n?|\n/)) {
35118 for (const char of line.split("")) {
35119 const code = char.charCodeAt(0);
35120 if (this.widths.has(code)) {
35121 continue;
35122 }
35123 const metrics = ctx.measureText(char);
35124 const width = Math.ceil(metrics.width);
35125 this.widths.set(code, width);
35126 this.firstChar = Math.min(code, this.firstChar);
35127 this.lastChar = Math.max(code, this.lastChar);
35128 }
35129 }
35130 return this.resources;
35131 }
35132 static getFirstPositionInfo(rect, rotation, fontSize) {
35133 const [x1, y1, x2, y2] = rect;
35134 let w = x2 - x1;
35135 let h = y2 - y1;
35136 if (rotation % 180 !== 0) {
35137 [w, h] = [h, w];
35138 }
35139 const lineHeight = LINE_FACTOR * fontSize;
35140 const lineDescent = LINE_DESCENT_FACTOR * fontSize;
35141 return {
35142 coords: [0, h + lineDescent - lineHeight],
35143 bbox: [0, 0, w, h],
35144 matrix: rotation !== 0 ? getRotationMatrix(rotation, h, lineHeight) : undefined
35145 };
35146 }
35147 createAppearance(text, rect, rotation, fontSize, bgColor, strokeAlpha) {
35148 const ctx = this._createContext();
35149 const lines = [];
35150 let maxWidth = -Infinity;
35151 for (const line of text.split(/\r\n?|\n/)) {
35152 lines.push(line);
35153 const lineWidth = ctx.measureText(line).width;
35154 maxWidth = Math.max(maxWidth, lineWidth);
35155 for (const code of codePointIter(line)) {
35156 const char = String.fromCodePoint(code);
35157 let width = this.widths.get(code);
35158 if (width === undefined) {
35159 const metrics = ctx.measureText(char);
35160 width = Math.ceil(metrics.width);
35161 this.widths.set(code, width);
35162 this.firstChar = Math.min(code, this.firstChar);
35163 this.lastChar = Math.max(code, this.lastChar);
35164 }
35165 }
35166 }
35167 maxWidth *= fontSize / 1000;
35168 const [x1, y1, x2, y2] = rect;
35169 let w = x2 - x1;
35170 let h = y2 - y1;
35171 if (rotation % 180 !== 0) {
35172 [w, h] = [h, w];
35173 }
35174 let hscale = 1;
35175 if (maxWidth > w) {
35176 hscale = w / maxWidth;
35177 }
35178 let vscale = 1;
35179 const lineHeight = LINE_FACTOR * fontSize;
35180 const lineDescent = LINE_DESCENT_FACTOR * fontSize;
35181 const maxHeight = lineHeight * lines.length;
35182 if (maxHeight > h) {
35183 vscale = h / maxHeight;
35184 }
35185 const fscale = Math.min(hscale, vscale);
35186 const newFontSize = fontSize * fscale;
35187 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`];
35188 const {
35189 resources
35190 } = this;
35191 strokeAlpha = typeof strokeAlpha === "number" && strokeAlpha >= 0 && strokeAlpha <= 1 ? strokeAlpha : 1;
35192 if (strokeAlpha !== 1) {
35193 buffer.push("/R0 gs");
35194 const extGState = new Dict(this.xref);
35195 const r0 = new Dict(this.xref);
35196 r0.set("ca", strokeAlpha);
35197 r0.set("CA", strokeAlpha);
35198 r0.set("Type", Name.get("ExtGState"));
35199 extGState.set("R0", r0);
35200 resources.set("ExtGState", extGState);
35201 }
35202 const vShift = numberToString(lineHeight);
35203 for (const line of lines) {
35204 buffer.push(`0 -${vShift} Td <${stringToUTF16HexString(line)}> Tj`);
35205 }
35206 buffer.push("ET", "Q");
35207 const appearance = buffer.join("\n");
35208 const appearanceStreamDict = new Dict(this.xref);
35209 appearanceStreamDict.set("Subtype", Name.get("Form"));
35210 appearanceStreamDict.set("Type", Name.get("XObject"));
35211 appearanceStreamDict.set("BBox", [0, 0, w, h]);
35212 appearanceStreamDict.set("Length", appearance.length);
35213 appearanceStreamDict.set("Resources", resources);
35214 if (rotation) {
35215 const matrix = getRotationMatrix(rotation, w, h);
35216 appearanceStreamDict.set("Matrix", matrix);
35217 }
35218 const ap = new StringStream(appearance);
35219 ap.dict = appearanceStreamDict;
35220 return ap;
35221 }
35222}
35223
35224;// CONCATENATED MODULE: ./src/core/name_number_tree.js
35225
35226
35227class NameOrNumberTree {
35228 constructor(root, xref, type) {
35229 if (this.constructor === NameOrNumberTree) {
35230 unreachable("Cannot initialize NameOrNumberTree.");
35231 }
35232 this.root = root;
35233 this.xref = xref;
35234 this._type = type;
35235 }
35236 getAll() {
35237 const map = new Map();
35238 if (!this.root) {
35239 return map;
35240 }
35241 const xref = this.xref;
35242 const processed = new RefSet();
35243 processed.put(this.root);
35244 const queue = [this.root];
35245 while (queue.length > 0) {
35246 const obj = xref.fetchIfRef(queue.shift());
35247 if (!(obj instanceof Dict)) {
35248 continue;
35249 }
35250 if (obj.has("Kids")) {
35251 const kids = obj.get("Kids");
35252 if (!Array.isArray(kids)) {
35253 continue;
35254 }
35255 for (const kid of kids) {
35256 if (processed.has(kid)) {
35257 throw new FormatError(`Duplicate entry in "${this._type}" tree.`);
35258 }
35259 queue.push(kid);
35260 processed.put(kid);
35261 }
35262 continue;
35263 }
35264 const entries = obj.get(this._type);
35265 if (!Array.isArray(entries)) {
35266 continue;
35267 }
35268 for (let i = 0, ii = entries.length; i < ii; i += 2) {
35269 map.set(xref.fetchIfRef(entries[i]), xref.fetchIfRef(entries[i + 1]));
35270 }
35271 }
35272 return map;
35273 }
35274 get(key) {
35275 if (!this.root) {
35276 return null;
35277 }
35278 const xref = this.xref;
35279 let kidsOrEntries = xref.fetchIfRef(this.root);
35280 let loopCount = 0;
35281 const MAX_LEVELS = 10;
35282 while (kidsOrEntries.has("Kids")) {
35283 if (++loopCount > MAX_LEVELS) {
35284 warn(`Search depth limit reached for "${this._type}" tree.`);
35285 return null;
35286 }
35287 const kids = kidsOrEntries.get("Kids");
35288 if (!Array.isArray(kids)) {
35289 return null;
35290 }
35291 let l = 0,
35292 r = kids.length - 1;
35293 while (l <= r) {
35294 const m = l + r >> 1;
35295 const kid = xref.fetchIfRef(kids[m]);
35296 const limits = kid.get("Limits");
35297 if (key < xref.fetchIfRef(limits[0])) {
35298 r = m - 1;
35299 } else if (key > xref.fetchIfRef(limits[1])) {
35300 l = m + 1;
35301 } else {
35302 kidsOrEntries = kid;
35303 break;
35304 }
35305 }
35306 if (l > r) {
35307 return null;
35308 }
35309 }
35310 const entries = kidsOrEntries.get(this._type);
35311 if (Array.isArray(entries)) {
35312 let l = 0,
35313 r = entries.length - 2;
35314 while (l <= r) {
35315 const tmp = l + r >> 1,
35316 m = tmp + (tmp & 1);
35317 const currentKey = xref.fetchIfRef(entries[m]);
35318 if (key < currentKey) {
35319 r = m - 2;
35320 } else if (key > currentKey) {
35321 l = m + 2;
35322 } else {
35323 return xref.fetchIfRef(entries[m + 1]);
35324 }
35325 }
35326 }
35327 return null;
35328 }
35329}
35330class NameTree extends NameOrNumberTree {
35331 constructor(root, xref) {
35332 super(root, xref, "Names");
35333 }
35334}
35335class NumberTree extends NameOrNumberTree {
35336 constructor(root, xref) {
35337 super(root, xref, "Nums");
35338 }
35339}
35340
35341;// CONCATENATED MODULE: ./src/core/cleanup_helper.js
35342
35343
35344
35345function clearGlobalCaches() {
35346 clearPatternCaches();
35347 clearPrimitiveCaches();
35348 clearUnicodeCaches();
35349}
35350
35351;// CONCATENATED MODULE: ./src/core/file_spec.js
35352
35353
35354
35355function pickPlatformItem(dict) {
35356 if (dict.has("UF")) {
35357 return dict.get("UF");
35358 } else if (dict.has("F")) {
35359 return dict.get("F");
35360 } else if (dict.has("Unix")) {
35361 return dict.get("Unix");
35362 } else if (dict.has("Mac")) {
35363 return dict.get("Mac");
35364 } else if (dict.has("DOS")) {
35365 return dict.get("DOS");
35366 }
35367 return null;
35368}
35369class FileSpec {
35370 #contentAvailable = false;
35371 constructor(root, xref, skipContent = false) {
35372 if (!(root instanceof Dict)) {
35373 return;
35374 }
35375 this.xref = xref;
35376 this.root = root;
35377 if (root.has("FS")) {
35378 this.fs = root.get("FS");
35379 }
35380 this.description = root.has("Desc") ? stringToPDFString(root.get("Desc")) : "";
35381 if (root.has("RF")) {
35382 warn("Related file specifications are not supported");
35383 }
35384 if (!skipContent) {
35385 if (root.has("EF")) {
35386 this.#contentAvailable = true;
35387 } else {
35388 warn("Non-embedded file specifications are not supported");
35389 }
35390 }
35391 }
35392 get filename() {
35393 if (!this._filename && this.root) {
35394 const filename = pickPlatformItem(this.root) || "unnamed";
35395 this._filename = stringToPDFString(filename).replaceAll("\\\\", "\\").replaceAll("\\/", "/").replaceAll("\\", "/");
35396 }
35397 return this._filename;
35398 }
35399 get content() {
35400 if (!this.#contentAvailable) {
35401 return null;
35402 }
35403 if (!this.contentRef && this.root) {
35404 this.contentRef = pickPlatformItem(this.root.get("EF"));
35405 }
35406 let content = null;
35407 if (this.contentRef) {
35408 const fileObj = this.xref.fetchIfRef(this.contentRef);
35409 if (fileObj instanceof BaseStream) {
35410 content = fileObj.getBytes();
35411 } else {
35412 warn("Embedded file specification points to non-existing/invalid content");
35413 }
35414 } else {
35415 warn("Embedded file specification does not have a content");
35416 }
35417 return content;
35418 }
35419 get serializable() {
35420 return {
35421 filename: this.filename,
35422 content: this.content
35423 };
35424 }
35425}
35426
35427;// CONCATENATED MODULE: ./src/core/xml_parser.js
35428
35429const XMLParserErrorCode = {
35430 NoError: 0,
35431 EndOfDocument: -1,
35432 UnterminatedCdat: -2,
35433 UnterminatedXmlDeclaration: -3,
35434 UnterminatedDoctypeDeclaration: -4,
35435 UnterminatedComment: -5,
35436 MalformedElement: -6,
35437 OutOfMemory: -7,
35438 UnterminatedAttributeValue: -8,
35439 UnterminatedElement: -9,
35440 ElementNeverBegun: -10
35441};
35442function isWhitespace(s, index) {
35443 const ch = s[index];
35444 return ch === " " || ch === "\n" || ch === "\r" || ch === "\t";
35445}
35446function isWhitespaceString(s) {
35447 for (let i = 0, ii = s.length; i < ii; i++) {
35448 if (!isWhitespace(s, i)) {
35449 return false;
35450 }
35451 }
35452 return true;
35453}
35454class XMLParserBase {
35455 _resolveEntities(s) {
35456 return s.replaceAll(/&([^;]+);/g, (all, entity) => {
35457 if (entity.substring(0, 2) === "#x") {
35458 return String.fromCodePoint(parseInt(entity.substring(2), 16));
35459 } else if (entity.substring(0, 1) === "#") {
35460 return String.fromCodePoint(parseInt(entity.substring(1), 10));
35461 }
35462 switch (entity) {
35463 case "lt":
35464 return "<";
35465 case "gt":
35466 return ">";
35467 case "amp":
35468 return "&";
35469 case "quot":
35470 return '"';
35471 case "apos":
35472 return "'";
35473 }
35474 return this.onResolveEntity(entity);
35475 });
35476 }
35477 _parseContent(s, start) {
35478 const attributes = [];
35479 let pos = start;
35480 function skipWs() {
35481 while (pos < s.length && isWhitespace(s, pos)) {
35482 ++pos;
35483 }
35484 }
35485 while (pos < s.length && !isWhitespace(s, pos) && s[pos] !== ">" && s[pos] !== "/") {
35486 ++pos;
35487 }
35488 const name = s.substring(start, pos);
35489 skipWs();
35490 while (pos < s.length && s[pos] !== ">" && s[pos] !== "/" && s[pos] !== "?") {
35491 skipWs();
35492 let attrName = "",
35493 attrValue = "";
35494 while (pos < s.length && !isWhitespace(s, pos) && s[pos] !== "=") {
35495 attrName += s[pos];
35496 ++pos;
35497 }
35498 skipWs();
35499 if (s[pos] !== "=") {
35500 return null;
35501 }
35502 ++pos;
35503 skipWs();
35504 const attrEndChar = s[pos];
35505 if (attrEndChar !== '"' && attrEndChar !== "'") {
35506 return null;
35507 }
35508 const attrEndIndex = s.indexOf(attrEndChar, ++pos);
35509 if (attrEndIndex < 0) {
35510 return null;
35511 }
35512 attrValue = s.substring(pos, attrEndIndex);
35513 attributes.push({
35514 name: attrName,
35515 value: this._resolveEntities(attrValue)
35516 });
35517 pos = attrEndIndex + 1;
35518 skipWs();
35519 }
35520 return {
35521 name,
35522 attributes,
35523 parsed: pos - start
35524 };
35525 }
35526 _parseProcessingInstruction(s, start) {
35527 let pos = start;
35528 function skipWs() {
35529 while (pos < s.length && isWhitespace(s, pos)) {
35530 ++pos;
35531 }
35532 }
35533 while (pos < s.length && !isWhitespace(s, pos) && s[pos] !== ">" && s[pos] !== "?" && s[pos] !== "/") {
35534 ++pos;
35535 }
35536 const name = s.substring(start, pos);
35537 skipWs();
35538 const attrStart = pos;
35539 while (pos < s.length && (s[pos] !== "?" || s[pos + 1] !== ">")) {
35540 ++pos;
35541 }
35542 const value = s.substring(attrStart, pos);
35543 return {
35544 name,
35545 value,
35546 parsed: pos - start
35547 };
35548 }
35549 parseXml(s) {
35550 let i = 0;
35551 while (i < s.length) {
35552 const ch = s[i];
35553 let j = i;
35554 if (ch === "<") {
35555 ++j;
35556 const ch2 = s[j];
35557 let q;
35558 switch (ch2) {
35559 case "/":
35560 ++j;
35561 q = s.indexOf(">", j);
35562 if (q < 0) {
35563 this.onError(XMLParserErrorCode.UnterminatedElement);
35564 return;
35565 }
35566 this.onEndElement(s.substring(j, q));
35567 j = q + 1;
35568 break;
35569 case "?":
35570 ++j;
35571 const pi = this._parseProcessingInstruction(s, j);
35572 if (s.substring(j + pi.parsed, j + pi.parsed + 2) !== "?>") {
35573 this.onError(XMLParserErrorCode.UnterminatedXmlDeclaration);
35574 return;
35575 }
35576 this.onPi(pi.name, pi.value);
35577 j += pi.parsed + 2;
35578 break;
35579 case "!":
35580 if (s.substring(j + 1, j + 3) === "--") {
35581 q = s.indexOf("-->", j + 3);
35582 if (q < 0) {
35583 this.onError(XMLParserErrorCode.UnterminatedComment);
35584 return;
35585 }
35586 this.onComment(s.substring(j + 3, q));
35587 j = q + 3;
35588 } else if (s.substring(j + 1, j + 8) === "[CDATA[") {
35589 q = s.indexOf("]]>", j + 8);
35590 if (q < 0) {
35591 this.onError(XMLParserErrorCode.UnterminatedCdat);
35592 return;
35593 }
35594 this.onCdata(s.substring(j + 8, q));
35595 j = q + 3;
35596 } else if (s.substring(j + 1, j + 8) === "DOCTYPE") {
35597 const q2 = s.indexOf("[", j + 8);
35598 let complexDoctype = false;
35599 q = s.indexOf(">", j + 8);
35600 if (q < 0) {
35601 this.onError(XMLParserErrorCode.UnterminatedDoctypeDeclaration);
35602 return;
35603 }
35604 if (q2 > 0 && q > q2) {
35605 q = s.indexOf("]>", j + 8);
35606 if (q < 0) {
35607 this.onError(XMLParserErrorCode.UnterminatedDoctypeDeclaration);
35608 return;
35609 }
35610 complexDoctype = true;
35611 }
35612 const doctypeContent = s.substring(j + 8, q + (complexDoctype ? 1 : 0));
35613 this.onDoctype(doctypeContent);
35614 j = q + (complexDoctype ? 2 : 1);
35615 } else {
35616 this.onError(XMLParserErrorCode.MalformedElement);
35617 return;
35618 }
35619 break;
35620 default:
35621 const content = this._parseContent(s, j);
35622 if (content === null) {
35623 this.onError(XMLParserErrorCode.MalformedElement);
35624 return;
35625 }
35626 let isClosed = false;
35627 if (s.substring(j + content.parsed, j + content.parsed + 2) === "/>") {
35628 isClosed = true;
35629 } else if (s.substring(j + content.parsed, j + content.parsed + 1) !== ">") {
35630 this.onError(XMLParserErrorCode.UnterminatedElement);
35631 return;
35632 }
35633 this.onBeginElement(content.name, content.attributes, isClosed);
35634 j += content.parsed + (isClosed ? 2 : 1);
35635 break;
35636 }
35637 } else {
35638 while (j < s.length && s[j] !== "<") {
35639 j++;
35640 }
35641 const text = s.substring(i, j);
35642 this.onText(this._resolveEntities(text));
35643 }
35644 i = j;
35645 }
35646 }
35647 onResolveEntity(name) {
35648 return `&${name};`;
35649 }
35650 onPi(name, value) {}
35651 onComment(text) {}
35652 onCdata(text) {}
35653 onDoctype(doctypeContent) {}
35654 onText(text) {}
35655 onBeginElement(name, attributes, isEmpty) {}
35656 onEndElement(name) {}
35657 onError(code) {}
35658}
35659class SimpleDOMNode {
35660 constructor(nodeName, nodeValue) {
35661 this.nodeName = nodeName;
35662 this.nodeValue = nodeValue;
35663 Object.defineProperty(this, "parentNode", {
35664 value: null,
35665 writable: true
35666 });
35667 }
35668 get firstChild() {
35669 return this.childNodes?.[0];
35670 }
35671 get nextSibling() {
35672 const childNodes = this.parentNode.childNodes;
35673 if (!childNodes) {
35674 return undefined;
35675 }
35676 const index = childNodes.indexOf(this);
35677 if (index === -1) {
35678 return undefined;
35679 }
35680 return childNodes[index + 1];
35681 }
35682 get textContent() {
35683 if (!this.childNodes) {
35684 return this.nodeValue || "";
35685 }
35686 return this.childNodes.map(function (child) {
35687 return child.textContent;
35688 }).join("");
35689 }
35690 get children() {
35691 return this.childNodes || [];
35692 }
35693 hasChildNodes() {
35694 return this.childNodes?.length > 0;
35695 }
35696 searchNode(paths, pos) {
35697 if (pos >= paths.length) {
35698 return this;
35699 }
35700 const component = paths[pos];
35701 if (component.name.startsWith("#") && pos < paths.length - 1) {
35702 return this.searchNode(paths, pos + 1);
35703 }
35704 const stack = [];
35705 let node = this;
35706 while (true) {
35707 if (component.name === node.nodeName) {
35708 if (component.pos === 0) {
35709 const res = node.searchNode(paths, pos + 1);
35710 if (res !== null) {
35711 return res;
35712 }
35713 } else if (stack.length === 0) {
35714 return null;
35715 } else {
35716 const [parent] = stack.pop();
35717 let siblingPos = 0;
35718 for (const child of parent.childNodes) {
35719 if (component.name === child.nodeName) {
35720 if (siblingPos === component.pos) {
35721 return child.searchNode(paths, pos + 1);
35722 }
35723 siblingPos++;
35724 }
35725 }
35726 return node.searchNode(paths, pos + 1);
35727 }
35728 }
35729 if (node.childNodes?.length > 0) {
35730 stack.push([node, 0]);
35731 node = node.childNodes[0];
35732 } else if (stack.length === 0) {
35733 return null;
35734 } else {
35735 while (stack.length !== 0) {
35736 const [parent, currentPos] = stack.pop();
35737 const newPos = currentPos + 1;
35738 if (newPos < parent.childNodes.length) {
35739 stack.push([parent, newPos]);
35740 node = parent.childNodes[newPos];
35741 break;
35742 }
35743 }
35744 if (stack.length === 0) {
35745 return null;
35746 }
35747 }
35748 }
35749 }
35750 dump(buffer) {
35751 if (this.nodeName === "#text") {
35752 buffer.push(encodeToXmlString(this.nodeValue));
35753 return;
35754 }
35755 buffer.push(`<${this.nodeName}`);
35756 if (this.attributes) {
35757 for (const attribute of this.attributes) {
35758 buffer.push(` ${attribute.name}="${encodeToXmlString(attribute.value)}"`);
35759 }
35760 }
35761 if (this.hasChildNodes()) {
35762 buffer.push(">");
35763 for (const child of this.childNodes) {
35764 child.dump(buffer);
35765 }
35766 buffer.push(`</${this.nodeName}>`);
35767 } else if (this.nodeValue) {
35768 buffer.push(`>${encodeToXmlString(this.nodeValue)}</${this.nodeName}>`);
35769 } else {
35770 buffer.push("/>");
35771 }
35772 }
35773}
35774class SimpleXMLParser extends XMLParserBase {
35775 constructor({
35776 hasAttributes = false,
35777 lowerCaseName = false
35778 }) {
35779 super();
35780 this._currentFragment = null;
35781 this._stack = null;
35782 this._errorCode = XMLParserErrorCode.NoError;
35783 this._hasAttributes = hasAttributes;
35784 this._lowerCaseName = lowerCaseName;
35785 }
35786 parseFromString(data) {
35787 this._currentFragment = [];
35788 this._stack = [];
35789 this._errorCode = XMLParserErrorCode.NoError;
35790 this.parseXml(data);
35791 if (this._errorCode !== XMLParserErrorCode.NoError) {
35792 return undefined;
35793 }
35794 const [documentElement] = this._currentFragment;
35795 if (!documentElement) {
35796 return undefined;
35797 }
35798 return {
35799 documentElement
35800 };
35801 }
35802 onText(text) {
35803 if (isWhitespaceString(text)) {
35804 return;
35805 }
35806 const node = new SimpleDOMNode("#text", text);
35807 this._currentFragment.push(node);
35808 }
35809 onCdata(text) {
35810 const node = new SimpleDOMNode("#text", text);
35811 this._currentFragment.push(node);
35812 }
35813 onBeginElement(name, attributes, isEmpty) {
35814 if (this._lowerCaseName) {
35815 name = name.toLowerCase();
35816 }
35817 const node = new SimpleDOMNode(name);
35818 node.childNodes = [];
35819 if (this._hasAttributes) {
35820 node.attributes = attributes;
35821 }
35822 this._currentFragment.push(node);
35823 if (isEmpty) {
35824 return;
35825 }
35826 this._stack.push(this._currentFragment);
35827 this._currentFragment = node.childNodes;
35828 }
35829 onEndElement(name) {
35830 this._currentFragment = this._stack.pop() || [];
35831 const lastElement = this._currentFragment.at(-1);
35832 if (!lastElement) {
35833 return null;
35834 }
35835 for (const childNode of lastElement.childNodes) {
35836 childNode.parentNode = lastElement;
35837 }
35838 return lastElement;
35839 }
35840 onError(code) {
35841 this._errorCode = code;
35842 }
35843}
35844
35845;// CONCATENATED MODULE: ./src/core/metadata_parser.js
35846
35847class MetadataParser {
35848 constructor(data) {
35849 data = this._repair(data);
35850 const parser = new SimpleXMLParser({
35851 lowerCaseName: true
35852 });
35853 const xmlDocument = parser.parseFromString(data);
35854 this._metadataMap = new Map();
35855 this._data = data;
35856 if (xmlDocument) {
35857 this._parse(xmlDocument);
35858 }
35859 }
35860 _repair(data) {
35861 return data.replace(/^[^<]+/, "").replaceAll(/>\\376\\377([^<]+)/g, function (all, codes) {
35862 const bytes = codes.replaceAll(/\\([0-3])([0-7])([0-7])/g, function (code, d1, d2, d3) {
35863 return String.fromCharCode(d1 * 64 + d2 * 8 + d3 * 1);
35864 }).replaceAll(/&(amp|apos|gt|lt|quot);/g, function (str, name) {
35865 switch (name) {
35866 case "amp":
35867 return "&";
35868 case "apos":
35869 return "'";
35870 case "gt":
35871 return ">";
35872 case "lt":
35873 return "<";
35874 case "quot":
35875 return '"';
35876 }
35877 throw new Error(`_repair: ${name} isn't defined.`);
35878 });
35879 const charBuf = [">"];
35880 for (let i = 0, ii = bytes.length; i < ii; i += 2) {
35881 const code = bytes.charCodeAt(i) * 256 + bytes.charCodeAt(i + 1);
35882 if (code >= 32 && code < 127 && code !== 60 && code !== 62 && code !== 38) {
35883 charBuf.push(String.fromCharCode(code));
35884 } else {
35885 charBuf.push("&#x" + (0x10000 + code).toString(16).substring(1) + ";");
35886 }
35887 }
35888 return charBuf.join("");
35889 });
35890 }
35891 _getSequence(entry) {
35892 const name = entry.nodeName;
35893 if (name !== "rdf:bag" && name !== "rdf:seq" && name !== "rdf:alt") {
35894 return null;
35895 }
35896 return entry.childNodes.filter(node => node.nodeName === "rdf:li");
35897 }
35898 _parseArray(entry) {
35899 if (!entry.hasChildNodes()) {
35900 return;
35901 }
35902 const [seqNode] = entry.childNodes;
35903 const sequence = this._getSequence(seqNode) || [];
35904 this._metadataMap.set(entry.nodeName, sequence.map(node => node.textContent.trim()));
35905 }
35906 _parse(xmlDocument) {
35907 let rdf = xmlDocument.documentElement;
35908 if (rdf.nodeName !== "rdf:rdf") {
35909 rdf = rdf.firstChild;
35910 while (rdf && rdf.nodeName !== "rdf:rdf") {
35911 rdf = rdf.nextSibling;
35912 }
35913 }
35914 if (!rdf || rdf.nodeName !== "rdf:rdf" || !rdf.hasChildNodes()) {
35915 return;
35916 }
35917 for (const desc of rdf.childNodes) {
35918 if (desc.nodeName !== "rdf:description") {
35919 continue;
35920 }
35921 for (const entry of desc.childNodes) {
35922 const name = entry.nodeName;
35923 switch (name) {
35924 case "#text":
35925 continue;
35926 case "dc:creator":
35927 case "dc:subject":
35928 this._parseArray(entry);
35929 continue;
35930 }
35931 this._metadataMap.set(name, entry.textContent.trim());
35932 }
35933 }
35934 }
35935 get serializable() {
35936 return {
35937 parsedData: this._metadataMap,
35938 rawData: this._data
35939 };
35940 }
35941}
35942
35943;// CONCATENATED MODULE: ./src/core/decrypt_stream.js
35944
35945const chunkSize = 512;
35946class DecryptStream extends DecodeStream {
35947 constructor(str, maybeLength, decrypt) {
35948 super(maybeLength);
35949 this.str = str;
35950 this.dict = str.dict;
35951 this.decrypt = decrypt;
35952 this.nextChunk = null;
35953 this.initialized = false;
35954 }
35955 readBlock() {
35956 let chunk;
35957 if (this.initialized) {
35958 chunk = this.nextChunk;
35959 } else {
35960 chunk = this.str.getBytes(chunkSize);
35961 this.initialized = true;
35962 }
35963 if (!chunk || chunk.length === 0) {
35964 this.eof = true;
35965 return;
35966 }
35967 this.nextChunk = this.str.getBytes(chunkSize);
35968 const hasMoreData = this.nextChunk?.length > 0;
35969 const decrypt = this.decrypt;
35970 chunk = decrypt(chunk, !hasMoreData);
35971 const bufferLength = this.bufferLength,
35972 newLength = bufferLength + chunk.length,
35973 buffer = this.ensureBuffer(newLength);
35974 buffer.set(chunk, bufferLength);
35975 this.bufferLength = newLength;
35976 }
35977}
35978
35979;// CONCATENATED MODULE: ./src/core/crypto.js
35980
35981
35982
35983class ARCFourCipher {
35984 constructor(key) {
35985 this.a = 0;
35986 this.b = 0;
35987 const s = new Uint8Array(256);
35988 const keyLength = key.length;
35989 for (let i = 0; i < 256; ++i) {
35990 s[i] = i;
35991 }
35992 for (let i = 0, j = 0; i < 256; ++i) {
35993 const tmp = s[i];
35994 j = j + tmp + key[i % keyLength] & 0xff;
35995 s[i] = s[j];
35996 s[j] = tmp;
35997 }
35998 this.s = s;
35999 }
36000 encryptBlock(data) {
36001 let a = this.a,
36002 b = this.b;
36003 const s = this.s;
36004 const n = data.length;
36005 const output = new Uint8Array(n);
36006 for (let i = 0; i < n; ++i) {
36007 a = a + 1 & 0xff;
36008 const tmp = s[a];
36009 b = b + tmp & 0xff;
36010 const tmp2 = s[b];
36011 s[a] = tmp2;
36012 s[b] = tmp;
36013 output[i] = data[i] ^ s[tmp + tmp2 & 0xff];
36014 }
36015 this.a = a;
36016 this.b = b;
36017 return output;
36018 }
36019 decryptBlock(data) {
36020 return this.encryptBlock(data);
36021 }
36022 encrypt(data) {
36023 return this.encryptBlock(data);
36024 }
36025}
36026const calculateMD5 = function calculateMD5Closure() {
36027 const 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]);
36028 const 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]);
36029 function hash(data, offset, length) {
36030 let h0 = 1732584193,
36031 h1 = -271733879,
36032 h2 = -1732584194,
36033 h3 = 271733878;
36034 const paddedLength = length + 72 & ~63;
36035 const padded = new Uint8Array(paddedLength);
36036 let i, j;
36037 for (i = 0; i < length; ++i) {
36038 padded[i] = data[offset++];
36039 }
36040 padded[i++] = 0x80;
36041 const n = paddedLength - 8;
36042 while (i < n) {
36043 padded[i++] = 0;
36044 }
36045 padded[i++] = length << 3 & 0xff;
36046 padded[i++] = length >> 5 & 0xff;
36047 padded[i++] = length >> 13 & 0xff;
36048 padded[i++] = length >> 21 & 0xff;
36049 padded[i++] = length >>> 29 & 0xff;
36050 padded[i++] = 0;
36051 padded[i++] = 0;
36052 padded[i++] = 0;
36053 const w = new Int32Array(16);
36054 for (i = 0; i < paddedLength;) {
36055 for (j = 0; j < 16; ++j, i += 4) {
36056 w[j] = padded[i] | padded[i + 1] << 8 | padded[i + 2] << 16 | padded[i + 3] << 24;
36057 }
36058 let a = h0,
36059 b = h1,
36060 c = h2,
36061 d = h3,
36062 f,
36063 g;
36064 for (j = 0; j < 64; ++j) {
36065 if (j < 16) {
36066 f = b & c | ~b & d;
36067 g = j;
36068 } else if (j < 32) {
36069 f = d & b | ~d & c;
36070 g = 5 * j + 1 & 15;
36071 } else if (j < 48) {
36072 f = b ^ c ^ d;
36073 g = 3 * j + 5 & 15;
36074 } else {
36075 f = c ^ (b | ~d);
36076 g = 7 * j & 15;
36077 }
36078 const tmp = d,
36079 rotateArg = a + f + k[j] + w[g] | 0,
36080 rotate = r[j];
36081 d = c;
36082 c = b;
36083 b = b + (rotateArg << rotate | rotateArg >>> 32 - rotate) | 0;
36084 a = tmp;
36085 }
36086 h0 = h0 + a | 0;
36087 h1 = h1 + b | 0;
36088 h2 = h2 + c | 0;
36089 h3 = h3 + d | 0;
36090 }
36091 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]);
36092 }
36093 return hash;
36094}();
36095class Word64 {
36096 constructor(highInteger, lowInteger) {
36097 this.high = highInteger | 0;
36098 this.low = lowInteger | 0;
36099 }
36100 and(word) {
36101 this.high &= word.high;
36102 this.low &= word.low;
36103 }
36104 xor(word) {
36105 this.high ^= word.high;
36106 this.low ^= word.low;
36107 }
36108 or(word) {
36109 this.high |= word.high;
36110 this.low |= word.low;
36111 }
36112 shiftRight(places) {
36113 if (places >= 32) {
36114 this.low = this.high >>> places - 32 | 0;
36115 this.high = 0;
36116 } else {
36117 this.low = this.low >>> places | this.high << 32 - places;
36118 this.high = this.high >>> places | 0;
36119 }
36120 }
36121 shiftLeft(places) {
36122 if (places >= 32) {
36123 this.high = this.low << places - 32;
36124 this.low = 0;
36125 } else {
36126 this.high = this.high << places | this.low >>> 32 - places;
36127 this.low <<= places;
36128 }
36129 }
36130 rotateRight(places) {
36131 let low, high;
36132 if (places & 32) {
36133 high = this.low;
36134 low = this.high;
36135 } else {
36136 low = this.low;
36137 high = this.high;
36138 }
36139 places &= 31;
36140 this.low = low >>> places | high << 32 - places;
36141 this.high = high >>> places | low << 32 - places;
36142 }
36143 not() {
36144 this.high = ~this.high;
36145 this.low = ~this.low;
36146 }
36147 add(word) {
36148 const lowAdd = (this.low >>> 0) + (word.low >>> 0);
36149 let highAdd = (this.high >>> 0) + (word.high >>> 0);
36150 if (lowAdd > 0xffffffff) {
36151 highAdd += 1;
36152 }
36153 this.low = lowAdd | 0;
36154 this.high = highAdd | 0;
36155 }
36156 copyTo(bytes, offset) {
36157 bytes[offset] = this.high >>> 24 & 0xff;
36158 bytes[offset + 1] = this.high >> 16 & 0xff;
36159 bytes[offset + 2] = this.high >> 8 & 0xff;
36160 bytes[offset + 3] = this.high & 0xff;
36161 bytes[offset + 4] = this.low >>> 24 & 0xff;
36162 bytes[offset + 5] = this.low >> 16 & 0xff;
36163 bytes[offset + 6] = this.low >> 8 & 0xff;
36164 bytes[offset + 7] = this.low & 0xff;
36165 }
36166 assign(word) {
36167 this.high = word.high;
36168 this.low = word.low;
36169 }
36170}
36171const calculateSHA256 = function calculateSHA256Closure() {
36172 function rotr(x, n) {
36173 return x >>> n | x << 32 - n;
36174 }
36175 function ch(x, y, z) {
36176 return x & y ^ ~x & z;
36177 }
36178 function maj(x, y, z) {
36179 return x & y ^ x & z ^ y & z;
36180 }
36181 function sigma(x) {
36182 return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
36183 }
36184 function sigmaPrime(x) {
36185 return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
36186 }
36187 function littleSigma(x) {
36188 return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
36189 }
36190 function littleSigmaPrime(x) {
36191 return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
36192 }
36193 const 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];
36194 function hash(data, offset, length) {
36195 let h0 = 0x6a09e667,
36196 h1 = 0xbb67ae85,
36197 h2 = 0x3c6ef372,
36198 h3 = 0xa54ff53a,
36199 h4 = 0x510e527f,
36200 h5 = 0x9b05688c,
36201 h6 = 0x1f83d9ab,
36202 h7 = 0x5be0cd19;
36203 const paddedLength = Math.ceil((length + 9) / 64) * 64;
36204 const padded = new Uint8Array(paddedLength);
36205 let i, j;
36206 for (i = 0; i < length; ++i) {
36207 padded[i] = data[offset++];
36208 }
36209 padded[i++] = 0x80;
36210 const n = paddedLength - 8;
36211 while (i < n) {
36212 padded[i++] = 0;
36213 }
36214 padded[i++] = 0;
36215 padded[i++] = 0;
36216 padded[i++] = 0;
36217 padded[i++] = length >>> 29 & 0xff;
36218 padded[i++] = length >> 21 & 0xff;
36219 padded[i++] = length >> 13 & 0xff;
36220 padded[i++] = length >> 5 & 0xff;
36221 padded[i++] = length << 3 & 0xff;
36222 const w = new Uint32Array(64);
36223 for (i = 0; i < paddedLength;) {
36224 for (j = 0; j < 16; ++j) {
36225 w[j] = padded[i] << 24 | padded[i + 1] << 16 | padded[i + 2] << 8 | padded[i + 3];
36226 i += 4;
36227 }
36228 for (j = 16; j < 64; ++j) {
36229 w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] + littleSigma(w[j - 15]) + w[j - 16] | 0;
36230 }
36231 let a = h0,
36232 b = h1,
36233 c = h2,
36234 d = h3,
36235 e = h4,
36236 f = h5,
36237 g = h6,
36238 h = h7,
36239 t1,
36240 t2;
36241 for (j = 0; j < 64; ++j) {
36242 t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
36243 t2 = sigma(a) + maj(a, b, c);
36244 h = g;
36245 g = f;
36246 f = e;
36247 e = d + t1 | 0;
36248 d = c;
36249 c = b;
36250 b = a;
36251 a = t1 + t2 | 0;
36252 }
36253 h0 = h0 + a | 0;
36254 h1 = h1 + b | 0;
36255 h2 = h2 + c | 0;
36256 h3 = h3 + d | 0;
36257 h4 = h4 + e | 0;
36258 h5 = h5 + f | 0;
36259 h6 = h6 + g | 0;
36260 h7 = h7 + h | 0;
36261 }
36262 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]);
36263 }
36264 return hash;
36265}();
36266const calculateSHA512 = function calculateSHA512Closure() {
36267 function ch(result, x, y, z, tmp) {
36268 result.assign(x);
36269 result.and(y);
36270 tmp.assign(x);
36271 tmp.not();
36272 tmp.and(z);
36273 result.xor(tmp);
36274 }
36275 function maj(result, x, y, z, tmp) {
36276 result.assign(x);
36277 result.and(y);
36278 tmp.assign(x);
36279 tmp.and(z);
36280 result.xor(tmp);
36281 tmp.assign(y);
36282 tmp.and(z);
36283 result.xor(tmp);
36284 }
36285 function sigma(result, x, tmp) {
36286 result.assign(x);
36287 result.rotateRight(28);
36288 tmp.assign(x);
36289 tmp.rotateRight(34);
36290 result.xor(tmp);
36291 tmp.assign(x);
36292 tmp.rotateRight(39);
36293 result.xor(tmp);
36294 }
36295 function sigmaPrime(result, x, tmp) {
36296 result.assign(x);
36297 result.rotateRight(14);
36298 tmp.assign(x);
36299 tmp.rotateRight(18);
36300 result.xor(tmp);
36301 tmp.assign(x);
36302 tmp.rotateRight(41);
36303 result.xor(tmp);
36304 }
36305 function littleSigma(result, x, tmp) {
36306 result.assign(x);
36307 result.rotateRight(1);
36308 tmp.assign(x);
36309 tmp.rotateRight(8);
36310 result.xor(tmp);
36311 tmp.assign(x);
36312 tmp.shiftRight(7);
36313 result.xor(tmp);
36314 }
36315 function littleSigmaPrime(result, x, tmp) {
36316 result.assign(x);
36317 result.rotateRight(19);
36318 tmp.assign(x);
36319 tmp.rotateRight(61);
36320 result.xor(tmp);
36321 tmp.assign(x);
36322 tmp.shiftRight(6);
36323 result.xor(tmp);
36324 }
36325 const 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)];
36326 function hash(data, offset, length, mode384 = false) {
36327 let h0, h1, h2, h3, h4, h5, h6, h7;
36328 if (!mode384) {
36329 h0 = new Word64(0x6a09e667, 0xf3bcc908);
36330 h1 = new Word64(0xbb67ae85, 0x84caa73b);
36331 h2 = new Word64(0x3c6ef372, 0xfe94f82b);
36332 h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
36333 h4 = new Word64(0x510e527f, 0xade682d1);
36334 h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
36335 h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
36336 h7 = new Word64(0x5be0cd19, 0x137e2179);
36337 } else {
36338 h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
36339 h1 = new Word64(0x629a292a, 0x367cd507);
36340 h2 = new Word64(0x9159015a, 0x3070dd17);
36341 h3 = new Word64(0x152fecd8, 0xf70e5939);
36342 h4 = new Word64(0x67332667, 0xffc00b31);
36343 h5 = new Word64(0x8eb44a87, 0x68581511);
36344 h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
36345 h7 = new Word64(0x47b5481d, 0xbefa4fa4);
36346 }
36347 const paddedLength = Math.ceil((length + 17) / 128) * 128;
36348 const padded = new Uint8Array(paddedLength);
36349 let i, j;
36350 for (i = 0; i < length; ++i) {
36351 padded[i] = data[offset++];
36352 }
36353 padded[i++] = 0x80;
36354 const n = paddedLength - 16;
36355 while (i < n) {
36356 padded[i++] = 0;
36357 }
36358 padded[i++] = 0;
36359 padded[i++] = 0;
36360 padded[i++] = 0;
36361 padded[i++] = 0;
36362 padded[i++] = 0;
36363 padded[i++] = 0;
36364 padded[i++] = 0;
36365 padded[i++] = 0;
36366 padded[i++] = 0;
36367 padded[i++] = 0;
36368 padded[i++] = 0;
36369 padded[i++] = length >>> 29 & 0xff;
36370 padded[i++] = length >> 21 & 0xff;
36371 padded[i++] = length >> 13 & 0xff;
36372 padded[i++] = length >> 5 & 0xff;
36373 padded[i++] = length << 3 & 0xff;
36374 const w = new Array(80);
36375 for (i = 0; i < 80; i++) {
36376 w[i] = new Word64(0, 0);
36377 }
36378 let a = new Word64(0, 0),
36379 b = new Word64(0, 0),
36380 c = new Word64(0, 0);
36381 let d = new Word64(0, 0),
36382 e = new Word64(0, 0),
36383 f = new Word64(0, 0);
36384 let g = new Word64(0, 0),
36385 h = new Word64(0, 0);
36386 const t1 = new Word64(0, 0),
36387 t2 = new Word64(0, 0);
36388 const tmp1 = new Word64(0, 0),
36389 tmp2 = new Word64(0, 0);
36390 let tmp3;
36391 for (i = 0; i < paddedLength;) {
36392 for (j = 0; j < 16; ++j) {
36393 w[j].high = padded[i] << 24 | padded[i + 1] << 16 | padded[i + 2] << 8 | padded[i + 3];
36394 w[j].low = padded[i + 4] << 24 | padded[i + 5] << 16 | padded[i + 6] << 8 | padded[i + 7];
36395 i += 8;
36396 }
36397 for (j = 16; j < 80; ++j) {
36398 tmp3 = w[j];
36399 littleSigmaPrime(tmp3, w[j - 2], tmp2);
36400 tmp3.add(w[j - 7]);
36401 littleSigma(tmp1, w[j - 15], tmp2);
36402 tmp3.add(tmp1);
36403 tmp3.add(w[j - 16]);
36404 }
36405 a.assign(h0);
36406 b.assign(h1);
36407 c.assign(h2);
36408 d.assign(h3);
36409 e.assign(h4);
36410 f.assign(h5);
36411 g.assign(h6);
36412 h.assign(h7);
36413 for (j = 0; j < 80; ++j) {
36414 t1.assign(h);
36415 sigmaPrime(tmp1, e, tmp2);
36416 t1.add(tmp1);
36417 ch(tmp1, e, f, g, tmp2);
36418 t1.add(tmp1);
36419 t1.add(k[j]);
36420 t1.add(w[j]);
36421 sigma(t2, a, tmp2);
36422 maj(tmp1, a, b, c, tmp2);
36423 t2.add(tmp1);
36424 tmp3 = h;
36425 h = g;
36426 g = f;
36427 f = e;
36428 d.add(t1);
36429 e = d;
36430 d = c;
36431 c = b;
36432 b = a;
36433 tmp3.assign(t1);
36434 tmp3.add(t2);
36435 a = tmp3;
36436 }
36437 h0.add(a);
36438 h1.add(b);
36439 h2.add(c);
36440 h3.add(d);
36441 h4.add(e);
36442 h5.add(f);
36443 h6.add(g);
36444 h7.add(h);
36445 }
36446 let result;
36447 if (!mode384) {
36448 result = new Uint8Array(64);
36449 h0.copyTo(result, 0);
36450 h1.copyTo(result, 8);
36451 h2.copyTo(result, 16);
36452 h3.copyTo(result, 24);
36453 h4.copyTo(result, 32);
36454 h5.copyTo(result, 40);
36455 h6.copyTo(result, 48);
36456 h7.copyTo(result, 56);
36457 } else {
36458 result = new Uint8Array(48);
36459 h0.copyTo(result, 0);
36460 h1.copyTo(result, 8);
36461 h2.copyTo(result, 16);
36462 h3.copyTo(result, 24);
36463 h4.copyTo(result, 32);
36464 h5.copyTo(result, 40);
36465 }
36466 return result;
36467 }
36468 return hash;
36469}();
36470function calculateSHA384(data, offset, length) {
36471 return calculateSHA512(data, offset, length, true);
36472}
36473class NullCipher {
36474 decryptBlock(data) {
36475 return data;
36476 }
36477 encrypt(data) {
36478 return data;
36479 }
36480}
36481class AESBaseCipher {
36482 constructor() {
36483 if (this.constructor === AESBaseCipher) {
36484 unreachable("Cannot initialize AESBaseCipher.");
36485 }
36486 this._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]);
36487 this._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]);
36488 this._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, 0x51f4a750, 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]);
36489 this._mixCol = new Uint8Array(256);
36490 for (let i = 0; i < 256; i++) {
36491 this._mixCol[i] = i < 128 ? i << 1 : i << 1 ^ 0x1b;
36492 }
36493 this.buffer = new Uint8Array(16);
36494 this.bufferPosition = 0;
36495 }
36496 _expandKey(cipherKey) {
36497 unreachable("Cannot call `_expandKey` on the base class");
36498 }
36499 _decrypt(input, key) {
36500 let t, u, v;
36501 const state = new Uint8Array(16);
36502 state.set(input);
36503 for (let j = 0, k = this._keySize; j < 16; ++j, ++k) {
36504 state[j] ^= key[k];
36505 }
36506 for (let i = this._cyclesOfRepetition - 1; i >= 1; --i) {
36507 t = state[13];
36508 state[13] = state[9];
36509 state[9] = state[5];
36510 state[5] = state[1];
36511 state[1] = t;
36512 t = state[14];
36513 u = state[10];
36514 state[14] = state[6];
36515 state[10] = state[2];
36516 state[6] = t;
36517 state[2] = u;
36518 t = state[15];
36519 u = state[11];
36520 v = state[7];
36521 state[15] = state[3];
36522 state[11] = t;
36523 state[7] = u;
36524 state[3] = v;
36525 for (let j = 0; j < 16; ++j) {
36526 state[j] = this._inv_s[state[j]];
36527 }
36528 for (let j = 0, k = i * 16; j < 16; ++j, ++k) {
36529 state[j] ^= key[k];
36530 }
36531 for (let j = 0; j < 16; j += 4) {
36532 const s0 = this._mix[state[j]];
36533 const s1 = this._mix[state[j + 1]];
36534 const s2 = this._mix[state[j + 2]];
36535 const s3 = this._mix[state[j + 3]];
36536 t = s0 ^ s1 >>> 8 ^ s1 << 24 ^ s2 >>> 16 ^ s2 << 16 ^ s3 >>> 24 ^ s3 << 8;
36537 state[j] = t >>> 24 & 0xff;
36538 state[j + 1] = t >> 16 & 0xff;
36539 state[j + 2] = t >> 8 & 0xff;
36540 state[j + 3] = t & 0xff;
36541 }
36542 }
36543 t = state[13];
36544 state[13] = state[9];
36545 state[9] = state[5];
36546 state[5] = state[1];
36547 state[1] = t;
36548 t = state[14];
36549 u = state[10];
36550 state[14] = state[6];
36551 state[10] = state[2];
36552 state[6] = t;
36553 state[2] = u;
36554 t = state[15];
36555 u = state[11];
36556 v = state[7];
36557 state[15] = state[3];
36558 state[11] = t;
36559 state[7] = u;
36560 state[3] = v;
36561 for (let j = 0; j < 16; ++j) {
36562 state[j] = this._inv_s[state[j]];
36563 state[j] ^= key[j];
36564 }
36565 return state;
36566 }
36567 _encrypt(input, key) {
36568 const s = this._s;
36569 let t, u, v;
36570 const state = new Uint8Array(16);
36571 state.set(input);
36572 for (let j = 0; j < 16; ++j) {
36573 state[j] ^= key[j];
36574 }
36575 for (let i = 1; i < this._cyclesOfRepetition; i++) {
36576 for (let j = 0; j < 16; ++j) {
36577 state[j] = s[state[j]];
36578 }
36579 v = state[1];
36580 state[1] = state[5];
36581 state[5] = state[9];
36582 state[9] = state[13];
36583 state[13] = v;
36584 v = state[2];
36585 u = state[6];
36586 state[2] = state[10];
36587 state[6] = state[14];
36588 state[10] = v;
36589 state[14] = u;
36590 v = state[3];
36591 u = state[7];
36592 t = state[11];
36593 state[3] = state[15];
36594 state[7] = v;
36595 state[11] = u;
36596 state[15] = t;
36597 for (let j = 0; j < 16; j += 4) {
36598 const s0 = state[j + 0];
36599 const s1 = state[j + 1];
36600 const s2 = state[j + 2];
36601 const s3 = state[j + 3];
36602 t = s0 ^ s1 ^ s2 ^ s3;
36603 state[j + 0] ^= t ^ this._mixCol[s0 ^ s1];
36604 state[j + 1] ^= t ^ this._mixCol[s1 ^ s2];
36605 state[j + 2] ^= t ^ this._mixCol[s2 ^ s3];
36606 state[j + 3] ^= t ^ this._mixCol[s3 ^ s0];
36607 }
36608 for (let j = 0, k = i * 16; j < 16; ++j, ++k) {
36609 state[j] ^= key[k];
36610 }
36611 }
36612 for (let j = 0; j < 16; ++j) {
36613 state[j] = s[state[j]];
36614 }
36615 v = state[1];
36616 state[1] = state[5];
36617 state[5] = state[9];
36618 state[9] = state[13];
36619 state[13] = v;
36620 v = state[2];
36621 u = state[6];
36622 state[2] = state[10];
36623 state[6] = state[14];
36624 state[10] = v;
36625 state[14] = u;
36626 v = state[3];
36627 u = state[7];
36628 t = state[11];
36629 state[3] = state[15];
36630 state[7] = v;
36631 state[11] = u;
36632 state[15] = t;
36633 for (let j = 0, k = this._keySize; j < 16; ++j, ++k) {
36634 state[j] ^= key[k];
36635 }
36636 return state;
36637 }
36638 _decryptBlock2(data, finalize) {
36639 const sourceLength = data.length;
36640 let buffer = this.buffer,
36641 bufferLength = this.bufferPosition;
36642 const result = [];
36643 let iv = this.iv;
36644 for (let i = 0; i < sourceLength; ++i) {
36645 buffer[bufferLength] = data[i];
36646 ++bufferLength;
36647 if (bufferLength < 16) {
36648 continue;
36649 }
36650 const plain = this._decrypt(buffer, this._key);
36651 for (let j = 0; j < 16; ++j) {
36652 plain[j] ^= iv[j];
36653 }
36654 iv = buffer;
36655 result.push(plain);
36656 buffer = new Uint8Array(16);
36657 bufferLength = 0;
36658 }
36659 this.buffer = buffer;
36660 this.bufferLength = bufferLength;
36661 this.iv = iv;
36662 if (result.length === 0) {
36663 return new Uint8Array(0);
36664 }
36665 let outputLength = 16 * result.length;
36666 if (finalize) {
36667 const lastBlock = result.at(-1);
36668 let psLen = lastBlock[15];
36669 if (psLen <= 16) {
36670 for (let i = 15, ii = 16 - psLen; i >= ii; --i) {
36671 if (lastBlock[i] !== psLen) {
36672 psLen = 0;
36673 break;
36674 }
36675 }
36676 outputLength -= psLen;
36677 result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
36678 }
36679 }
36680 const output = new Uint8Array(outputLength);
36681 for (let i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
36682 output.set(result[i], j);
36683 }
36684 return output;
36685 }
36686 decryptBlock(data, finalize, iv = null) {
36687 const sourceLength = data.length;
36688 const buffer = this.buffer;
36689 let bufferLength = this.bufferPosition;
36690 if (iv) {
36691 this.iv = iv;
36692 } else {
36693 for (let i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
36694 buffer[bufferLength] = data[i];
36695 }
36696 if (bufferLength < 16) {
36697 this.bufferLength = bufferLength;
36698 return new Uint8Array(0);
36699 }
36700 this.iv = buffer;
36701 data = data.subarray(16);
36702 }
36703 this.buffer = new Uint8Array(16);
36704 this.bufferLength = 0;
36705 this.decryptBlock = this._decryptBlock2;
36706 return this.decryptBlock(data, finalize);
36707 }
36708 encrypt(data, iv) {
36709 const sourceLength = data.length;
36710 let buffer = this.buffer,
36711 bufferLength = this.bufferPosition;
36712 const result = [];
36713 if (!iv) {
36714 iv = new Uint8Array(16);
36715 }
36716 for (let i = 0; i < sourceLength; ++i) {
36717 buffer[bufferLength] = data[i];
36718 ++bufferLength;
36719 if (bufferLength < 16) {
36720 continue;
36721 }
36722 for (let j = 0; j < 16; ++j) {
36723 buffer[j] ^= iv[j];
36724 }
36725 const cipher = this._encrypt(buffer, this._key);
36726 iv = cipher;
36727 result.push(cipher);
36728 buffer = new Uint8Array(16);
36729 bufferLength = 0;
36730 }
36731 this.buffer = buffer;
36732 this.bufferLength = bufferLength;
36733 this.iv = iv;
36734 if (result.length === 0) {
36735 return new Uint8Array(0);
36736 }
36737 const outputLength = 16 * result.length;
36738 const output = new Uint8Array(outputLength);
36739 for (let i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
36740 output.set(result[i], j);
36741 }
36742 return output;
36743 }
36744}
36745class AES128Cipher extends AESBaseCipher {
36746 constructor(key) {
36747 super();
36748 this._cyclesOfRepetition = 10;
36749 this._keySize = 160;
36750 this._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]);
36751 this._key = this._expandKey(key);
36752 }
36753 _expandKey(cipherKey) {
36754 const b = 176;
36755 const s = this._s;
36756 const rcon = this._rcon;
36757 const result = new Uint8Array(b);
36758 result.set(cipherKey);
36759 for (let j = 16, i = 1; j < b; ++i) {
36760 let t1 = result[j - 3];
36761 let t2 = result[j - 2];
36762 let t3 = result[j - 1];
36763 let t4 = result[j - 4];
36764 t1 = s[t1];
36765 t2 = s[t2];
36766 t3 = s[t3];
36767 t4 = s[t4];
36768 t1 ^= rcon[i];
36769 for (let n = 0; n < 4; ++n) {
36770 result[j] = t1 ^= result[j - 16];
36771 j++;
36772 result[j] = t2 ^= result[j - 16];
36773 j++;
36774 result[j] = t3 ^= result[j - 16];
36775 j++;
36776 result[j] = t4 ^= result[j - 16];
36777 j++;
36778 }
36779 }
36780 return result;
36781 }
36782}
36783class AES256Cipher extends AESBaseCipher {
36784 constructor(key) {
36785 super();
36786 this._cyclesOfRepetition = 14;
36787 this._keySize = 224;
36788 this._key = this._expandKey(key);
36789 }
36790 _expandKey(cipherKey) {
36791 const b = 240;
36792 const s = this._s;
36793 const result = new Uint8Array(b);
36794 result.set(cipherKey);
36795 let r = 1;
36796 let t1, t2, t3, t4;
36797 for (let j = 32, i = 1; j < b; ++i) {
36798 if (j % 32 === 16) {
36799 t1 = s[t1];
36800 t2 = s[t2];
36801 t3 = s[t3];
36802 t4 = s[t4];
36803 } else if (j % 32 === 0) {
36804 t1 = result[j - 3];
36805 t2 = result[j - 2];
36806 t3 = result[j - 1];
36807 t4 = result[j - 4];
36808 t1 = s[t1];
36809 t2 = s[t2];
36810 t3 = s[t3];
36811 t4 = s[t4];
36812 t1 ^= r;
36813 if ((r <<= 1) >= 256) {
36814 r = (r ^ 0x1b) & 0xff;
36815 }
36816 }
36817 for (let n = 0; n < 4; ++n) {
36818 result[j] = t1 ^= result[j - 32];
36819 j++;
36820 result[j] = t2 ^= result[j - 32];
36821 j++;
36822 result[j] = t3 ^= result[j - 32];
36823 j++;
36824 result[j] = t4 ^= result[j - 32];
36825 j++;
36826 }
36827 }
36828 return result;
36829 }
36830}
36831class PDF17 {
36832 checkOwnerPassword(password, ownerValidationSalt, userBytes, ownerPassword) {
36833 const hashData = new Uint8Array(password.length + 56);
36834 hashData.set(password, 0);
36835 hashData.set(ownerValidationSalt, password.length);
36836 hashData.set(userBytes, password.length + ownerValidationSalt.length);
36837 const result = calculateSHA256(hashData, 0, hashData.length);
36838 return isArrayEqual(result, ownerPassword);
36839 }
36840 checkUserPassword(password, userValidationSalt, userPassword) {
36841 const hashData = new Uint8Array(password.length + 8);
36842 hashData.set(password, 0);
36843 hashData.set(userValidationSalt, password.length);
36844 const result = calculateSHA256(hashData, 0, hashData.length);
36845 return isArrayEqual(result, userPassword);
36846 }
36847 getOwnerKey(password, ownerKeySalt, userBytes, ownerEncryption) {
36848 const hashData = new Uint8Array(password.length + 56);
36849 hashData.set(password, 0);
36850 hashData.set(ownerKeySalt, password.length);
36851 hashData.set(userBytes, password.length + ownerKeySalt.length);
36852 const key = calculateSHA256(hashData, 0, hashData.length);
36853 const cipher = new AES256Cipher(key);
36854 return cipher.decryptBlock(ownerEncryption, false, new Uint8Array(16));
36855 }
36856 getUserKey(password, userKeySalt, userEncryption) {
36857 const hashData = new Uint8Array(password.length + 8);
36858 hashData.set(password, 0);
36859 hashData.set(userKeySalt, password.length);
36860 const key = calculateSHA256(hashData, 0, hashData.length);
36861 const cipher = new AES256Cipher(key);
36862 return cipher.decryptBlock(userEncryption, false, new Uint8Array(16));
36863 }
36864}
36865class PDF20 {
36866 _hash(password, input, userBytes) {
36867 let k = calculateSHA256(input, 0, input.length).subarray(0, 32);
36868 let e = [0];
36869 let i = 0;
36870 while (i < 64 || e.at(-1) > i - 32) {
36871 const combinedLength = password.length + k.length + userBytes.length,
36872 combinedArray = new Uint8Array(combinedLength);
36873 let writeOffset = 0;
36874 combinedArray.set(password, writeOffset);
36875 writeOffset += password.length;
36876 combinedArray.set(k, writeOffset);
36877 writeOffset += k.length;
36878 combinedArray.set(userBytes, writeOffset);
36879 const k1 = new Uint8Array(combinedLength * 64);
36880 for (let j = 0, pos = 0; j < 64; j++, pos += combinedLength) {
36881 k1.set(combinedArray, pos);
36882 }
36883 const cipher = new AES128Cipher(k.subarray(0, 16));
36884 e = cipher.encrypt(k1, k.subarray(16, 32));
36885 const remainder = e.slice(0, 16).reduce((a, b) => a + b, 0) % 3;
36886 if (remainder === 0) {
36887 k = calculateSHA256(e, 0, e.length);
36888 } else if (remainder === 1) {
36889 k = calculateSHA384(e, 0, e.length);
36890 } else if (remainder === 2) {
36891 k = calculateSHA512(e, 0, e.length);
36892 }
36893 i++;
36894 }
36895 return k.subarray(0, 32);
36896 }
36897 checkOwnerPassword(password, ownerValidationSalt, userBytes, ownerPassword) {
36898 const hashData = new Uint8Array(password.length + 56);
36899 hashData.set(password, 0);
36900 hashData.set(ownerValidationSalt, password.length);
36901 hashData.set(userBytes, password.length + ownerValidationSalt.length);
36902 const result = this._hash(password, hashData, userBytes);
36903 return isArrayEqual(result, ownerPassword);
36904 }
36905 checkUserPassword(password, userValidationSalt, userPassword) {
36906 const hashData = new Uint8Array(password.length + 8);
36907 hashData.set(password, 0);
36908 hashData.set(userValidationSalt, password.length);
36909 const result = this._hash(password, hashData, []);
36910 return isArrayEqual(result, userPassword);
36911 }
36912 getOwnerKey(password, ownerKeySalt, userBytes, ownerEncryption) {
36913 const hashData = new Uint8Array(password.length + 56);
36914 hashData.set(password, 0);
36915 hashData.set(ownerKeySalt, password.length);
36916 hashData.set(userBytes, password.length + ownerKeySalt.length);
36917 const key = this._hash(password, hashData, userBytes);
36918 const cipher = new AES256Cipher(key);
36919 return cipher.decryptBlock(ownerEncryption, false, new Uint8Array(16));
36920 }
36921 getUserKey(password, userKeySalt, userEncryption) {
36922 const hashData = new Uint8Array(password.length + 8);
36923 hashData.set(password, 0);
36924 hashData.set(userKeySalt, password.length);
36925 const key = this._hash(password, hashData, []);
36926 const cipher = new AES256Cipher(key);
36927 return cipher.decryptBlock(userEncryption, false, new Uint8Array(16));
36928 }
36929}
36930class CipherTransform {
36931 constructor(stringCipherConstructor, streamCipherConstructor) {
36932 this.StringCipherConstructor = stringCipherConstructor;
36933 this.StreamCipherConstructor = streamCipherConstructor;
36934 }
36935 createStream(stream, length) {
36936 const cipher = new this.StreamCipherConstructor();
36937 return new DecryptStream(stream, length, function cipherTransformDecryptStream(data, finalize) {
36938 return cipher.decryptBlock(data, finalize);
36939 });
36940 }
36941 decryptString(s) {
36942 const cipher = new this.StringCipherConstructor();
36943 let data = stringToBytes(s);
36944 data = cipher.decryptBlock(data, true);
36945 return bytesToString(data);
36946 }
36947 encryptString(s) {
36948 const cipher = new this.StringCipherConstructor();
36949 if (cipher instanceof AESBaseCipher) {
36950 const strLen = s.length;
36951 const pad = 16 - strLen % 16;
36952 s += String.fromCharCode(pad).repeat(pad);
36953 const iv = new Uint8Array(16);
36954 if (typeof crypto !== "undefined") {
36955 crypto.getRandomValues(iv);
36956 } else {
36957 for (let i = 0; i < 16; i++) {
36958 iv[i] = Math.floor(256 * Math.random());
36959 }
36960 }
36961 let data = stringToBytes(s);
36962 data = cipher.encrypt(data, iv);
36963 const buf = new Uint8Array(16 + data.length);
36964 buf.set(iv);
36965 buf.set(data, 16);
36966 return bytesToString(buf);
36967 }
36968 let data = stringToBytes(s);
36969 data = cipher.encrypt(data);
36970 return bytesToString(data);
36971 }
36972}
36973class CipherTransformFactory {
36974 static #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]);
36975 #createEncryptionKey20(revision, password, ownerPassword, ownerValidationSalt, ownerKeySalt, uBytes, userPassword, userValidationSalt, userKeySalt, ownerEncryption, userEncryption, perms) {
36976 if (password) {
36977 const passwordLength = Math.min(127, password.length);
36978 password = password.subarray(0, passwordLength);
36979 } else {
36980 password = [];
36981 }
36982 const pdfAlgorithm = revision === 6 ? new PDF20() : new PDF17();
36983 if (pdfAlgorithm.checkUserPassword(password, userValidationSalt, userPassword)) {
36984 return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
36985 } else if (password.length && pdfAlgorithm.checkOwnerPassword(password, ownerValidationSalt, uBytes, ownerPassword)) {
36986 return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes, ownerEncryption);
36987 }
36988 return null;
36989 }
36990 #prepareKeyData(fileId, password, ownerPassword, userPassword, flags, revision, keyLength, encryptMetadata) {
36991 const hashDataSize = 40 + ownerPassword.length + fileId.length;
36992 const hashData = new Uint8Array(hashDataSize);
36993 let i = 0,
36994 j,
36995 n;
36996 if (password) {
36997 n = Math.min(32, password.length);
36998 for (; i < n; ++i) {
36999 hashData[i] = password[i];
37000 }
37001 }
37002 j = 0;
37003 while (i < 32) {
37004 hashData[i++] = CipherTransformFactory.#defaultPasswordBytes[j++];
37005 }
37006 for (j = 0, n = ownerPassword.length; j < n; ++j) {
37007 hashData[i++] = ownerPassword[j];
37008 }
37009 hashData[i++] = flags & 0xff;
37010 hashData[i++] = flags >> 8 & 0xff;
37011 hashData[i++] = flags >> 16 & 0xff;
37012 hashData[i++] = flags >>> 24 & 0xff;
37013 for (j = 0, n = fileId.length; j < n; ++j) {
37014 hashData[i++] = fileId[j];
37015 }
37016 if (revision >= 4 && !encryptMetadata) {
37017 hashData[i++] = 0xff;
37018 hashData[i++] = 0xff;
37019 hashData[i++] = 0xff;
37020 hashData[i++] = 0xff;
37021 }
37022 let hash = calculateMD5(hashData, 0, i);
37023 const keyLengthInBytes = keyLength >> 3;
37024 if (revision >= 3) {
37025 for (j = 0; j < 50; ++j) {
37026 hash = calculateMD5(hash, 0, keyLengthInBytes);
37027 }
37028 }
37029 const encryptionKey = hash.subarray(0, keyLengthInBytes);
37030 let cipher, checkData;
37031 if (revision >= 3) {
37032 for (i = 0; i < 32; ++i) {
37033 hashData[i] = CipherTransformFactory.#defaultPasswordBytes[i];
37034 }
37035 for (j = 0, n = fileId.length; j < n; ++j) {
37036 hashData[i++] = fileId[j];
37037 }
37038 cipher = new ARCFourCipher(encryptionKey);
37039 checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
37040 n = encryptionKey.length;
37041 const derivedKey = new Uint8Array(n);
37042 for (j = 1; j <= 19; ++j) {
37043 for (let k = 0; k < n; ++k) {
37044 derivedKey[k] = encryptionKey[k] ^ j;
37045 }
37046 cipher = new ARCFourCipher(derivedKey);
37047 checkData = cipher.encryptBlock(checkData);
37048 }
37049 for (j = 0, n = checkData.length; j < n; ++j) {
37050 if (userPassword[j] !== checkData[j]) {
37051 return null;
37052 }
37053 }
37054 } else {
37055 cipher = new ARCFourCipher(encryptionKey);
37056 checkData = cipher.encryptBlock(CipherTransformFactory.#defaultPasswordBytes);
37057 for (j = 0, n = checkData.length; j < n; ++j) {
37058 if (userPassword[j] !== checkData[j]) {
37059 return null;
37060 }
37061 }
37062 }
37063 return encryptionKey;
37064 }
37065 #decodeUserPassword(password, ownerPassword, revision, keyLength) {
37066 const hashData = new Uint8Array(32);
37067 let i = 0;
37068 const n = Math.min(32, password.length);
37069 for (; i < n; ++i) {
37070 hashData[i] = password[i];
37071 }
37072 let j = 0;
37073 while (i < 32) {
37074 hashData[i++] = CipherTransformFactory.#defaultPasswordBytes[j++];
37075 }
37076 let hash = calculateMD5(hashData, 0, i);
37077 const keyLengthInBytes = keyLength >> 3;
37078 if (revision >= 3) {
37079 for (j = 0; j < 50; ++j) {
37080 hash = calculateMD5(hash, 0, hash.length);
37081 }
37082 }
37083 let cipher, userPassword;
37084 if (revision >= 3) {
37085 userPassword = ownerPassword;
37086 const derivedKey = new Uint8Array(keyLengthInBytes);
37087 for (j = 19; j >= 0; j--) {
37088 for (let k = 0; k < keyLengthInBytes; ++k) {
37089 derivedKey[k] = hash[k] ^ j;
37090 }
37091 cipher = new ARCFourCipher(derivedKey);
37092 userPassword = cipher.encryptBlock(userPassword);
37093 }
37094 } else {
37095 cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
37096 userPassword = cipher.encryptBlock(ownerPassword);
37097 }
37098 return userPassword;
37099 }
37100 #buildObjectKey(num, gen, encryptionKey, isAes = false) {
37101 const key = new Uint8Array(encryptionKey.length + 9);
37102 const n = encryptionKey.length;
37103 let i;
37104 for (i = 0; i < n; ++i) {
37105 key[i] = encryptionKey[i];
37106 }
37107 key[i++] = num & 0xff;
37108 key[i++] = num >> 8 & 0xff;
37109 key[i++] = num >> 16 & 0xff;
37110 key[i++] = gen & 0xff;
37111 key[i++] = gen >> 8 & 0xff;
37112 if (isAes) {
37113 key[i++] = 0x73;
37114 key[i++] = 0x41;
37115 key[i++] = 0x6c;
37116 key[i++] = 0x54;
37117 }
37118 const hash = calculateMD5(key, 0, i);
37119 return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
37120 }
37121 #buildCipherConstructor(cf, name, num, gen, key) {
37122 if (!(name instanceof Name)) {
37123 throw new FormatError("Invalid crypt filter name.");
37124 }
37125 const self = this;
37126 const cryptFilter = cf.get(name.name);
37127 const cfm = cryptFilter?.get("CFM");
37128 if (!cfm || cfm.name === "None") {
37129 return function () {
37130 return new NullCipher();
37131 };
37132 }
37133 if (cfm.name === "V2") {
37134 return function () {
37135 return new ARCFourCipher(self.#buildObjectKey(num, gen, key, false));
37136 };
37137 }
37138 if (cfm.name === "AESV2") {
37139 return function () {
37140 return new AES128Cipher(self.#buildObjectKey(num, gen, key, true));
37141 };
37142 }
37143 if (cfm.name === "AESV3") {
37144 return function () {
37145 return new AES256Cipher(key);
37146 };
37147 }
37148 throw new FormatError("Unknown crypto method");
37149 }
37150 constructor(dict, fileId, password) {
37151 const filter = dict.get("Filter");
37152 if (!isName(filter, "Standard")) {
37153 throw new FormatError("unknown encryption method");
37154 }
37155 this.filterName = filter.name;
37156 this.dict = dict;
37157 const algorithm = dict.get("V");
37158 if (!Number.isInteger(algorithm) || algorithm !== 1 && algorithm !== 2 && algorithm !== 4 && algorithm !== 5) {
37159 throw new FormatError("unsupported encryption algorithm");
37160 }
37161 this.algorithm = algorithm;
37162 let keyLength = dict.get("Length");
37163 if (!keyLength) {
37164 if (algorithm <= 3) {
37165 keyLength = 40;
37166 } else {
37167 const cfDict = dict.get("CF");
37168 const streamCryptoName = dict.get("StmF");
37169 if (cfDict instanceof Dict && streamCryptoName instanceof Name) {
37170 cfDict.suppressEncryption = true;
37171 const handlerDict = cfDict.get(streamCryptoName.name);
37172 keyLength = handlerDict?.get("Length") || 128;
37173 if (keyLength < 40) {
37174 keyLength <<= 3;
37175 }
37176 }
37177 }
37178 }
37179 if (!Number.isInteger(keyLength) || keyLength < 40 || keyLength % 8 !== 0) {
37180 throw new FormatError("invalid key length");
37181 }
37182 const ownerBytes = stringToBytes(dict.get("O")),
37183 userBytes = stringToBytes(dict.get("U"));
37184 const ownerPassword = ownerBytes.subarray(0, 32);
37185 const userPassword = userBytes.subarray(0, 32);
37186 const flags = dict.get("P");
37187 const revision = dict.get("R");
37188 const encryptMetadata = (algorithm === 4 || algorithm === 5) && dict.get("EncryptMetadata") !== false;
37189 this.encryptMetadata = encryptMetadata;
37190 const fileIdBytes = stringToBytes(fileId);
37191 let passwordBytes;
37192 if (password) {
37193 if (revision === 6) {
37194 try {
37195 password = utf8StringToString(password);
37196 } catch {
37197 warn("CipherTransformFactory: Unable to convert UTF8 encoded password.");
37198 }
37199 }
37200 passwordBytes = stringToBytes(password);
37201 }
37202 let encryptionKey;
37203 if (algorithm !== 5) {
37204 encryptionKey = this.#prepareKeyData(fileIdBytes, passwordBytes, ownerPassword, userPassword, flags, revision, keyLength, encryptMetadata);
37205 } else {
37206 const ownerValidationSalt = ownerBytes.subarray(32, 40);
37207 const ownerKeySalt = ownerBytes.subarray(40, 48);
37208 const uBytes = userBytes.subarray(0, 48);
37209 const userValidationSalt = userBytes.subarray(32, 40);
37210 const userKeySalt = userBytes.subarray(40, 48);
37211 const ownerEncryption = stringToBytes(dict.get("OE"));
37212 const userEncryption = stringToBytes(dict.get("UE"));
37213 const perms = stringToBytes(dict.get("Perms"));
37214 encryptionKey = this.#createEncryptionKey20(revision, passwordBytes, ownerPassword, ownerValidationSalt, ownerKeySalt, uBytes, userPassword, userValidationSalt, userKeySalt, ownerEncryption, userEncryption, perms);
37215 }
37216 if (!encryptionKey && !password) {
37217 throw new PasswordException("No password given", PasswordResponses.NEED_PASSWORD);
37218 } else if (!encryptionKey && password) {
37219 const decodedPassword = this.#decodeUserPassword(passwordBytes, ownerPassword, revision, keyLength);
37220 encryptionKey = this.#prepareKeyData(fileIdBytes, decodedPassword, ownerPassword, userPassword, flags, revision, keyLength, encryptMetadata);
37221 }
37222 if (!encryptionKey) {
37223 throw new PasswordException("Incorrect Password", PasswordResponses.INCORRECT_PASSWORD);
37224 }
37225 this.encryptionKey = encryptionKey;
37226 if (algorithm >= 4) {
37227 const cf = dict.get("CF");
37228 if (cf instanceof Dict) {
37229 cf.suppressEncryption = true;
37230 }
37231 this.cf = cf;
37232 this.stmf = dict.get("StmF") || Name.get("Identity");
37233 this.strf = dict.get("StrF") || Name.get("Identity");
37234 this.eff = dict.get("EFF") || this.stmf;
37235 }
37236 }
37237 createCipherTransform(num, gen) {
37238 if (this.algorithm === 4 || this.algorithm === 5) {
37239 return new CipherTransform(this.#buildCipherConstructor(this.cf, this.strf, num, gen, this.encryptionKey), this.#buildCipherConstructor(this.cf, this.stmf, num, gen, this.encryptionKey));
37240 }
37241 const key = this.#buildObjectKey(num, gen, this.encryptionKey, false);
37242 const cipherConstructor = function () {
37243 return new ARCFourCipher(key);
37244 };
37245 return new CipherTransform(cipherConstructor, cipherConstructor);
37246 }
37247}
37248
37249;// CONCATENATED MODULE: ./src/core/writer.js
37250
37251
37252
37253
37254
37255
37256
37257async function writeObject(ref, obj, buffer, {
37258 encrypt = null
37259}) {
37260 const transform = encrypt?.createCipherTransform(ref.num, ref.gen);
37261 buffer.push(`${ref.num} ${ref.gen} obj\n`);
37262 if (obj instanceof Dict) {
37263 await writeDict(obj, buffer, transform);
37264 } else if (obj instanceof BaseStream) {
37265 await writeStream(obj, buffer, transform);
37266 } else if (Array.isArray(obj) || ArrayBuffer.isView(obj)) {
37267 await writeArray(obj, buffer, transform);
37268 }
37269 buffer.push("\nendobj\n");
37270}
37271async function writeDict(dict, buffer, transform) {
37272 buffer.push("<<");
37273 for (const key of dict.getKeys()) {
37274 buffer.push(` /${escapePDFName(key)} `);
37275 await writeValue(dict.getRaw(key), buffer, transform);
37276 }
37277 buffer.push(">>");
37278}
37279async function writeStream(stream, buffer, transform) {
37280 let bytes = stream.getBytes();
37281 const {
37282 dict
37283 } = stream;
37284 const [filter, params] = await Promise.all([dict.getAsync("Filter"), dict.getAsync("DecodeParms")]);
37285 const filterZero = Array.isArray(filter) ? await dict.xref.fetchIfRefAsync(filter[0]) : filter;
37286 const isFilterZeroFlateDecode = isName(filterZero, "FlateDecode");
37287 const MIN_LENGTH_FOR_COMPRESSING = 256;
37288 if (typeof CompressionStream !== "undefined" && (bytes.length >= MIN_LENGTH_FOR_COMPRESSING || isFilterZeroFlateDecode)) {
37289 try {
37290 const cs = new CompressionStream("deflate");
37291 const writer = cs.writable.getWriter();
37292 writer.write(bytes);
37293 writer.close();
37294 const buf = await new Response(cs.readable).arrayBuffer();
37295 bytes = new Uint8Array(buf);
37296 let newFilter, newParams;
37297 if (!filter) {
37298 newFilter = Name.get("FlateDecode");
37299 } else if (!isFilterZeroFlateDecode) {
37300 newFilter = Array.isArray(filter) ? [Name.get("FlateDecode"), ...filter] : [Name.get("FlateDecode"), filter];
37301 if (params) {
37302 newParams = Array.isArray(params) ? [null, ...params] : [null, params];
37303 }
37304 }
37305 if (newFilter) {
37306 dict.set("Filter", newFilter);
37307 }
37308 if (newParams) {
37309 dict.set("DecodeParms", newParams);
37310 }
37311 } catch (ex) {
37312 info(`writeStream - cannot compress data: "${ex}".`);
37313 }
37314 }
37315 let string = bytesToString(bytes);
37316 if (transform) {
37317 string = transform.encryptString(string);
37318 }
37319 dict.set("Length", string.length);
37320 await writeDict(dict, buffer, transform);
37321 buffer.push(" stream\n", string, "\nendstream");
37322}
37323async function writeArray(array, buffer, transform) {
37324 buffer.push("[");
37325 let first = true;
37326 for (const val of array) {
37327 if (!first) {
37328 buffer.push(" ");
37329 } else {
37330 first = false;
37331 }
37332 await writeValue(val, buffer, transform);
37333 }
37334 buffer.push("]");
37335}
37336async function writeValue(value, buffer, transform) {
37337 if (value instanceof Name) {
37338 buffer.push(`/${escapePDFName(value.name)}`);
37339 } else if (value instanceof Ref) {
37340 buffer.push(`${value.num} ${value.gen} R`);
37341 } else if (Array.isArray(value) || ArrayBuffer.isView(value)) {
37342 await writeArray(value, buffer, transform);
37343 } else if (typeof value === "string") {
37344 if (transform) {
37345 value = transform.encryptString(value);
37346 }
37347 buffer.push(`(${escapeString(value)})`);
37348 } else if (typeof value === "number") {
37349 buffer.push(numberToString(value));
37350 } else if (typeof value === "boolean") {
37351 buffer.push(value.toString());
37352 } else if (value instanceof Dict) {
37353 await writeDict(value, buffer, transform);
37354 } else if (value instanceof BaseStream) {
37355 await writeStream(value, buffer, transform);
37356 } else if (value === null) {
37357 buffer.push("null");
37358 } else {
37359 warn(`Unhandled value in writer: ${typeof value}, please file a bug.`);
37360 }
37361}
37362function writeInt(number, size, offset, buffer) {
37363 for (let i = size + offset - 1; i > offset - 1; i--) {
37364 buffer[i] = number & 0xff;
37365 number >>= 8;
37366 }
37367 return offset + size;
37368}
37369function writeString(string, offset, buffer) {
37370 for (let i = 0, len = string.length; i < len; i++) {
37371 buffer[offset + i] = string.charCodeAt(i) & 0xff;
37372 }
37373}
37374function computeMD5(filesize, xrefInfo) {
37375 const time = Math.floor(Date.now() / 1000);
37376 const filename = xrefInfo.filename || "";
37377 const md5Buffer = [time.toString(), filename, filesize.toString()];
37378 let md5BufferLen = md5Buffer.reduce((a, str) => a + str.length, 0);
37379 for (const value of Object.values(xrefInfo.info)) {
37380 md5Buffer.push(value);
37381 md5BufferLen += value.length;
37382 }
37383 const array = new Uint8Array(md5BufferLen);
37384 let offset = 0;
37385 for (const str of md5Buffer) {
37386 writeString(str, offset, array);
37387 offset += str.length;
37388 }
37389 return bytesToString(calculateMD5(array));
37390}
37391function writeXFADataForAcroform(str, newRefs) {
37392 const xml = new SimpleXMLParser({
37393 hasAttributes: true
37394 }).parseFromString(str);
37395 for (const {
37396 xfa
37397 } of newRefs) {
37398 if (!xfa) {
37399 continue;
37400 }
37401 const {
37402 path,
37403 value
37404 } = xfa;
37405 if (!path) {
37406 continue;
37407 }
37408 const nodePath = parseXFAPath(path);
37409 let node = xml.documentElement.searchNode(nodePath, 0);
37410 if (!node && nodePath.length > 1) {
37411 node = xml.documentElement.searchNode([nodePath.at(-1)], 0);
37412 }
37413 if (node) {
37414 node.childNodes = Array.isArray(value) ? value.map(val => new SimpleDOMNode("value", val)) : [new SimpleDOMNode("#text", value)];
37415 } else {
37416 warn(`Node not found for path: ${path}`);
37417 }
37418 }
37419 const buffer = [];
37420 xml.documentElement.dump(buffer);
37421 return buffer.join("");
37422}
37423async function updateAcroform({
37424 xref,
37425 acroForm,
37426 acroFormRef,
37427 hasXfa,
37428 hasXfaDatasetsEntry,
37429 xfaDatasetsRef,
37430 needAppearances,
37431 newRefs
37432}) {
37433 if (hasXfa && !hasXfaDatasetsEntry && !xfaDatasetsRef) {
37434 warn("XFA - Cannot save it");
37435 }
37436 if (!needAppearances && (!hasXfa || !xfaDatasetsRef || hasXfaDatasetsEntry)) {
37437 return;
37438 }
37439 const dict = acroForm.clone();
37440 if (hasXfa && !hasXfaDatasetsEntry) {
37441 const newXfa = acroForm.get("XFA").slice();
37442 newXfa.splice(2, 0, "datasets");
37443 newXfa.splice(3, 0, xfaDatasetsRef);
37444 dict.set("XFA", newXfa);
37445 }
37446 if (needAppearances) {
37447 dict.set("NeedAppearances", true);
37448 }
37449 const buffer = [];
37450 await writeObject(acroFormRef, dict, buffer, xref);
37451 newRefs.push({
37452 ref: acroFormRef,
37453 data: buffer.join("")
37454 });
37455}
37456function updateXFA({
37457 xfaData,
37458 xfaDatasetsRef,
37459 newRefs,
37460 xref
37461}) {
37462 if (xfaData === null) {
37463 const datasets = xref.fetchIfRef(xfaDatasetsRef);
37464 xfaData = writeXFADataForAcroform(datasets.getString(), newRefs);
37465 }
37466 const encrypt = xref.encrypt;
37467 if (encrypt) {
37468 const transform = encrypt.createCipherTransform(xfaDatasetsRef.num, xfaDatasetsRef.gen);
37469 xfaData = transform.encryptString(xfaData);
37470 }
37471 const data = `${xfaDatasetsRef.num} ${xfaDatasetsRef.gen} obj\n` + `<< /Type /EmbeddedFile /Length ${xfaData.length}>>\nstream\n` + xfaData + "\nendstream\nendobj\n";
37472 newRefs.push({
37473 ref: xfaDatasetsRef,
37474 data
37475 });
37476}
37477async function getXRefTable(xrefInfo, baseOffset, newRefs, newXref, buffer) {
37478 buffer.push("xref\n");
37479 const indexes = getIndexes(newRefs);
37480 let indexesPosition = 0;
37481 for (const {
37482 ref,
37483 data
37484 } of newRefs) {
37485 if (ref.num === indexes[indexesPosition]) {
37486 buffer.push(`${indexes[indexesPosition]} ${indexes[indexesPosition + 1]}\n`);
37487 indexesPosition += 2;
37488 }
37489 buffer.push(`${baseOffset.toString().padStart(10, "0")} ${Math.min(ref.gen, 0xffff).toString().padStart(5, "0")} n\r\n`);
37490 baseOffset += data.length;
37491 }
37492 computeIDs(baseOffset, xrefInfo, newXref);
37493 buffer.push("trailer\n");
37494 await writeDict(newXref, buffer);
37495 buffer.push("\nstartxref\n", baseOffset.toString(), "\n%%EOF\n");
37496}
37497function getIndexes(newRefs) {
37498 const indexes = [];
37499 for (const {
37500 ref
37501 } of newRefs) {
37502 if (ref.num === indexes.at(-2) + indexes.at(-1)) {
37503 indexes[indexes.length - 1] += 1;
37504 } else {
37505 indexes.push(ref.num, 1);
37506 }
37507 }
37508 return indexes;
37509}
37510async function getXRefStreamTable(xrefInfo, baseOffset, newRefs, newXref, buffer) {
37511 const xrefTableData = [];
37512 let maxOffset = 0;
37513 let maxGen = 0;
37514 for (const {
37515 ref,
37516 data
37517 } of newRefs) {
37518 maxOffset = Math.max(maxOffset, baseOffset);
37519 const gen = Math.min(ref.gen, 0xffff);
37520 maxGen = Math.max(maxGen, gen);
37521 xrefTableData.push([1, baseOffset, gen]);
37522 baseOffset += data.length;
37523 }
37524 newXref.set("Index", getIndexes(newRefs));
37525 const offsetSize = getSizeInBytes(maxOffset);
37526 const maxGenSize = getSizeInBytes(maxGen);
37527 const sizes = [1, offsetSize, maxGenSize];
37528 newXref.set("W", sizes);
37529 computeIDs(baseOffset, xrefInfo, newXref);
37530 const structSize = sizes.reduce((a, x) => a + x, 0);
37531 const data = new Uint8Array(structSize * xrefTableData.length);
37532 const stream = new Stream(data);
37533 stream.dict = newXref;
37534 let offset = 0;
37535 for (const [type, objOffset, gen] of xrefTableData) {
37536 offset = writeInt(type, sizes[0], offset, data);
37537 offset = writeInt(objOffset, sizes[1], offset, data);
37538 offset = writeInt(gen, sizes[2], offset, data);
37539 }
37540 await writeObject(xrefInfo.newRef, stream, buffer, {});
37541 buffer.push("startxref\n", baseOffset.toString(), "\n%%EOF\n");
37542}
37543function computeIDs(baseOffset, xrefInfo, newXref) {
37544 if (Array.isArray(xrefInfo.fileIds) && xrefInfo.fileIds.length > 0) {
37545 const md5 = computeMD5(baseOffset, xrefInfo);
37546 newXref.set("ID", [xrefInfo.fileIds[0], md5]);
37547 }
37548}
37549function getTrailerDict(xrefInfo, newRefs, useXrefStream) {
37550 const newXref = new Dict(null);
37551 newXref.set("Prev", xrefInfo.startXRef);
37552 const refForXrefTable = xrefInfo.newRef;
37553 if (useXrefStream) {
37554 newRefs.push({
37555 ref: refForXrefTable,
37556 data: ""
37557 });
37558 newXref.set("Size", refForXrefTable.num + 1);
37559 newXref.set("Type", Name.get("XRef"));
37560 } else {
37561 newXref.set("Size", refForXrefTable.num);
37562 }
37563 if (xrefInfo.rootRef !== null) {
37564 newXref.set("Root", xrefInfo.rootRef);
37565 }
37566 if (xrefInfo.infoRef !== null) {
37567 newXref.set("Info", xrefInfo.infoRef);
37568 }
37569 if (xrefInfo.encryptRef !== null) {
37570 newXref.set("Encrypt", xrefInfo.encryptRef);
37571 }
37572 return newXref;
37573}
37574async function incrementalUpdate({
37575 originalData,
37576 xrefInfo,
37577 newRefs,
37578 xref = null,
37579 hasXfa = false,
37580 xfaDatasetsRef = null,
37581 hasXfaDatasetsEntry = false,
37582 needAppearances,
37583 acroFormRef = null,
37584 acroForm = null,
37585 xfaData = null,
37586 useXrefStream = false
37587}) {
37588 await updateAcroform({
37589 xref,
37590 acroForm,
37591 acroFormRef,
37592 hasXfa,
37593 hasXfaDatasetsEntry,
37594 xfaDatasetsRef,
37595 needAppearances,
37596 newRefs
37597 });
37598 if (hasXfa) {
37599 updateXFA({
37600 xfaData,
37601 xfaDatasetsRef,
37602 newRefs,
37603 xref
37604 });
37605 }
37606 let buffer, baseOffset;
37607 const lastByte = originalData.at(-1);
37608 if (lastByte === 0x0a || lastByte === 0x0d) {
37609 buffer = [];
37610 baseOffset = originalData.length;
37611 } else {
37612 buffer = ["\n"];
37613 baseOffset = originalData.length + 1;
37614 }
37615 const newXref = getTrailerDict(xrefInfo, newRefs, useXrefStream);
37616 newRefs = newRefs.sort((a, b) => a.ref.num - b.ref.num);
37617 for (const {
37618 data
37619 } of newRefs) {
37620 buffer.push(data);
37621 }
37622 await (useXrefStream ? getXRefStreamTable(xrefInfo, baseOffset, newRefs, newXref, buffer) : getXRefTable(xrefInfo, baseOffset, newRefs, newXref, buffer));
37623 const totalLength = buffer.reduce((a, str) => a + str.length, originalData.length);
37624 const array = new Uint8Array(totalLength);
37625 array.set(originalData);
37626 let offset = originalData.length;
37627 for (const str of buffer) {
37628 writeString(str, offset, array);
37629 offset += str.length;
37630 }
37631 return array;
37632}
37633
37634;// CONCATENATED MODULE: ./src/core/struct_tree.js
37635
37636
37637
37638
37639const MAX_DEPTH = 40;
37640const StructElementType = {
37641 PAGE_CONTENT: 1,
37642 STREAM_CONTENT: 2,
37643 OBJECT: 3,
37644 ANNOTATION: 4,
37645 ELEMENT: 5
37646};
37647class StructTreeRoot {
37648 constructor(rootDict, rootRef) {
37649 this.dict = rootDict;
37650 this.ref = rootRef instanceof Ref ? rootRef : null;
37651 this.roleMap = new Map();
37652 this.structParentIds = null;
37653 }
37654 init() {
37655 this.readRoleMap();
37656 }
37657 #addIdToPage(pageRef, id, type) {
37658 if (!(pageRef instanceof Ref) || id < 0) {
37659 return;
37660 }
37661 this.structParentIds ||= new RefSetCache();
37662 let ids = this.structParentIds.get(pageRef);
37663 if (!ids) {
37664 ids = [];
37665 this.structParentIds.put(pageRef, ids);
37666 }
37667 ids.push([id, type]);
37668 }
37669 addAnnotationIdToPage(pageRef, id) {
37670 this.#addIdToPage(pageRef, id, StructElementType.ANNOTATION);
37671 }
37672 readRoleMap() {
37673 const roleMapDict = this.dict.get("RoleMap");
37674 if (!(roleMapDict instanceof Dict)) {
37675 return;
37676 }
37677 roleMapDict.forEach((key, value) => {
37678 if (!(value instanceof Name)) {
37679 return;
37680 }
37681 this.roleMap.set(key, value.name);
37682 });
37683 }
37684 static async canCreateStructureTree({
37685 catalogRef,
37686 pdfManager,
37687 newAnnotationsByPage
37688 }) {
37689 if (!(catalogRef instanceof Ref)) {
37690 warn("Cannot save the struct tree: no catalog reference.");
37691 return false;
37692 }
37693 let nextKey = 0;
37694 let hasNothingToUpdate = true;
37695 for (const [pageIndex, elements] of newAnnotationsByPage) {
37696 const {
37697 ref: pageRef
37698 } = await pdfManager.getPage(pageIndex);
37699 if (!(pageRef instanceof Ref)) {
37700 warn(`Cannot save the struct tree: page ${pageIndex} has no ref.`);
37701 hasNothingToUpdate = true;
37702 break;
37703 }
37704 for (const element of elements) {
37705 if (element.accessibilityData?.type) {
37706 element.parentTreeId = nextKey++;
37707 hasNothingToUpdate = false;
37708 }
37709 }
37710 }
37711 if (hasNothingToUpdate) {
37712 for (const elements of newAnnotationsByPage.values()) {
37713 for (const element of elements) {
37714 delete element.parentTreeId;
37715 }
37716 }
37717 return false;
37718 }
37719 return true;
37720 }
37721 static async createStructureTree({
37722 newAnnotationsByPage,
37723 xref,
37724 catalogRef,
37725 pdfManager,
37726 newRefs
37727 }) {
37728 const root = pdfManager.catalog.cloneDict();
37729 const structTreeRootRef = xref.getNewTemporaryRef();
37730 root.set("StructTreeRoot", structTreeRootRef);
37731 const buffer = [];
37732 await writeObject(catalogRef, root, buffer, xref);
37733 newRefs.push({
37734 ref: catalogRef,
37735 data: buffer.join("")
37736 });
37737 const structTreeRoot = new Dict(xref);
37738 structTreeRoot.set("Type", Name.get("StructTreeRoot"));
37739 const parentTreeRef = xref.getNewTemporaryRef();
37740 structTreeRoot.set("ParentTree", parentTreeRef);
37741 const kids = [];
37742 structTreeRoot.set("K", kids);
37743 const parentTree = new Dict(xref);
37744 const nums = [];
37745 parentTree.set("Nums", nums);
37746 const nextKey = await this.#writeKids({
37747 newAnnotationsByPage,
37748 structTreeRootRef,
37749 kids,
37750 nums,
37751 xref,
37752 pdfManager,
37753 newRefs,
37754 buffer
37755 });
37756 structTreeRoot.set("ParentTreeNextKey", nextKey);
37757 buffer.length = 0;
37758 await writeObject(parentTreeRef, parentTree, buffer, xref);
37759 newRefs.push({
37760 ref: parentTreeRef,
37761 data: buffer.join("")
37762 });
37763 buffer.length = 0;
37764 await writeObject(structTreeRootRef, structTreeRoot, buffer, xref);
37765 newRefs.push({
37766 ref: structTreeRootRef,
37767 data: buffer.join("")
37768 });
37769 }
37770 async canUpdateStructTree({
37771 pdfManager,
37772 xref,
37773 newAnnotationsByPage
37774 }) {
37775 if (!this.ref) {
37776 warn("Cannot update the struct tree: no root reference.");
37777 return false;
37778 }
37779 let nextKey = this.dict.get("ParentTreeNextKey");
37780 if (!Number.isInteger(nextKey) || nextKey < 0) {
37781 warn("Cannot update the struct tree: invalid next key.");
37782 return false;
37783 }
37784 const parentTree = this.dict.get("ParentTree");
37785 if (!(parentTree instanceof Dict)) {
37786 warn("Cannot update the struct tree: ParentTree isn't a dict.");
37787 return false;
37788 }
37789 const nums = parentTree.get("Nums");
37790 if (!Array.isArray(nums)) {
37791 warn("Cannot update the struct tree: nums isn't an array.");
37792 return false;
37793 }
37794 const numberTree = new NumberTree(parentTree, xref);
37795 for (const pageIndex of newAnnotationsByPage.keys()) {
37796 const {
37797 pageDict
37798 } = await pdfManager.getPage(pageIndex);
37799 if (!pageDict.has("StructParents")) {
37800 continue;
37801 }
37802 const id = pageDict.get("StructParents");
37803 if (!Number.isInteger(id) || !Array.isArray(numberTree.get(id))) {
37804 warn(`Cannot save the struct tree: page ${pageIndex} has a wrong id.`);
37805 return false;
37806 }
37807 }
37808 let hasNothingToUpdate = true;
37809 for (const [pageIndex, elements] of newAnnotationsByPage) {
37810 const {
37811 pageDict
37812 } = await pdfManager.getPage(pageIndex);
37813 StructTreeRoot.#collectParents({
37814 elements,
37815 xref: this.dict.xref,
37816 pageDict,
37817 numberTree
37818 });
37819 for (const element of elements) {
37820 if (element.accessibilityData?.type) {
37821 element.parentTreeId = nextKey++;
37822 hasNothingToUpdate = false;
37823 }
37824 }
37825 }
37826 if (hasNothingToUpdate) {
37827 for (const elements of newAnnotationsByPage.values()) {
37828 for (const element of elements) {
37829 delete element.parentTreeId;
37830 delete element.structTreeParent;
37831 }
37832 }
37833 return false;
37834 }
37835 return true;
37836 }
37837 async updateStructureTree({
37838 newAnnotationsByPage,
37839 pdfManager,
37840 newRefs
37841 }) {
37842 const xref = this.dict.xref;
37843 const structTreeRoot = this.dict.clone();
37844 const structTreeRootRef = this.ref;
37845 let parentTreeRef = structTreeRoot.getRaw("ParentTree");
37846 let parentTree;
37847 if (parentTreeRef instanceof Ref) {
37848 parentTree = xref.fetch(parentTreeRef);
37849 } else {
37850 parentTree = parentTreeRef;
37851 parentTreeRef = xref.getNewTemporaryRef();
37852 structTreeRoot.set("ParentTree", parentTreeRef);
37853 }
37854 parentTree = parentTree.clone();
37855 let nums = parentTree.getRaw("Nums");
37856 let numsRef = null;
37857 if (nums instanceof Ref) {
37858 numsRef = nums;
37859 nums = xref.fetch(numsRef);
37860 }
37861 nums = nums.slice();
37862 if (!numsRef) {
37863 parentTree.set("Nums", nums);
37864 }
37865 let kids = structTreeRoot.getRaw("K");
37866 let kidsRef = null;
37867 if (kids instanceof Ref) {
37868 kidsRef = kids;
37869 kids = xref.fetch(kidsRef);
37870 } else {
37871 kidsRef = xref.getNewTemporaryRef();
37872 structTreeRoot.set("K", kidsRef);
37873 }
37874 kids = Array.isArray(kids) ? kids.slice() : [kids];
37875 const buffer = [];
37876 const newNextkey = await StructTreeRoot.#writeKids({
37877 newAnnotationsByPage,
37878 structTreeRootRef,
37879 kids,
37880 nums,
37881 xref,
37882 pdfManager,
37883 newRefs,
37884 buffer
37885 });
37886 structTreeRoot.set("ParentTreeNextKey", newNextkey);
37887 buffer.length = 0;
37888 await writeObject(kidsRef, kids, buffer, xref);
37889 newRefs.push({
37890 ref: kidsRef,
37891 data: buffer.join("")
37892 });
37893 if (numsRef) {
37894 buffer.length = 0;
37895 await writeObject(numsRef, nums, buffer, xref);
37896 newRefs.push({
37897 ref: numsRef,
37898 data: buffer.join("")
37899 });
37900 }
37901 buffer.length = 0;
37902 await writeObject(parentTreeRef, parentTree, buffer, xref);
37903 newRefs.push({
37904 ref: parentTreeRef,
37905 data: buffer.join("")
37906 });
37907 buffer.length = 0;
37908 await writeObject(structTreeRootRef, structTreeRoot, buffer, xref);
37909 newRefs.push({
37910 ref: structTreeRootRef,
37911 data: buffer.join("")
37912 });
37913 }
37914 static async #writeKids({
37915 newAnnotationsByPage,
37916 structTreeRootRef,
37917 kids,
37918 nums,
37919 xref,
37920 pdfManager,
37921 newRefs,
37922 buffer
37923 }) {
37924 const objr = Name.get("OBJR");
37925 let nextKey = -Infinity;
37926 for (const [pageIndex, elements] of newAnnotationsByPage) {
37927 const {
37928 ref: pageRef
37929 } = await pdfManager.getPage(pageIndex);
37930 const isPageRef = pageRef instanceof Ref;
37931 for (const {
37932 accessibilityData,
37933 ref,
37934 parentTreeId,
37935 structTreeParent
37936 } of elements) {
37937 if (!accessibilityData?.type) {
37938 continue;
37939 }
37940 const {
37941 type,
37942 title,
37943 lang,
37944 alt,
37945 expanded,
37946 actualText
37947 } = accessibilityData;
37948 nextKey = Math.max(nextKey, parentTreeId);
37949 const tagRef = xref.getNewTemporaryRef();
37950 const tagDict = new Dict(xref);
37951 tagDict.set("S", Name.get(type));
37952 if (title) {
37953 tagDict.set("T", title);
37954 }
37955 if (lang) {
37956 tagDict.set("Lang", lang);
37957 }
37958 if (alt) {
37959 tagDict.set("Alt", alt);
37960 }
37961 if (expanded) {
37962 tagDict.set("E", expanded);
37963 }
37964 if (actualText) {
37965 tagDict.set("ActualText", actualText);
37966 }
37967 if (structTreeParent) {
37968 await this.#updateParentTag({
37969 structTreeParent,
37970 tagDict,
37971 newTagRef: tagRef,
37972 fallbackRef: structTreeRootRef,
37973 xref,
37974 newRefs,
37975 buffer
37976 });
37977 } else {
37978 tagDict.set("P", structTreeRootRef);
37979 }
37980 const objDict = new Dict(xref);
37981 tagDict.set("K", objDict);
37982 objDict.set("Type", objr);
37983 if (isPageRef) {
37984 objDict.set("Pg", pageRef);
37985 }
37986 objDict.set("Obj", ref);
37987 buffer.length = 0;
37988 await writeObject(tagRef, tagDict, buffer, xref);
37989 newRefs.push({
37990 ref: tagRef,
37991 data: buffer.join("")
37992 });
37993 nums.push(parentTreeId, tagRef);
37994 kids.push(tagRef);
37995 }
37996 }
37997 return nextKey + 1;
37998 }
37999 static #collectParents({
38000 elements,
38001 xref,
38002 pageDict,
38003 numberTree
38004 }) {
38005 const idToElement = new Map();
38006 for (const element of elements) {
38007 if (element.structTreeParentId) {
38008 const id = parseInt(element.structTreeParentId.split("_mc")[1], 10);
38009 idToElement.set(id, element);
38010 }
38011 }
38012 const id = pageDict.get("StructParents");
38013 if (!Number.isInteger(id)) {
38014 return;
38015 }
38016 const parentArray = numberTree.get(id);
38017 const updateElement = (kid, pageKid, kidRef) => {
38018 const element = idToElement.get(kid);
38019 if (element) {
38020 const parentRef = pageKid.getRaw("P");
38021 const parentDict = xref.fetchIfRef(parentRef);
38022 if (parentRef instanceof Ref && parentDict instanceof Dict) {
38023 element.structTreeParent = {
38024 ref: kidRef,
38025 dict: pageKid
38026 };
38027 }
38028 return true;
38029 }
38030 return false;
38031 };
38032 for (const kidRef of parentArray) {
38033 if (!(kidRef instanceof Ref)) {
38034 continue;
38035 }
38036 const pageKid = xref.fetch(kidRef);
38037 const k = pageKid.get("K");
38038 if (Number.isInteger(k)) {
38039 updateElement(k, pageKid, kidRef);
38040 continue;
38041 }
38042 if (!Array.isArray(k)) {
38043 continue;
38044 }
38045 for (let kid of k) {
38046 kid = xref.fetchIfRef(kid);
38047 if (Number.isInteger(kid) && updateElement(kid, pageKid, kidRef)) {
38048 break;
38049 }
38050 }
38051 }
38052 }
38053 static async #updateParentTag({
38054 structTreeParent: {
38055 ref,
38056 dict
38057 },
38058 tagDict,
38059 newTagRef,
38060 fallbackRef,
38061 xref,
38062 newRefs,
38063 buffer
38064 }) {
38065 const parentRef = dict.getRaw("P");
38066 let parentDict = xref.fetchIfRef(parentRef);
38067 tagDict.set("P", parentRef);
38068 let saveParentDict = false;
38069 let parentKids;
38070 let parentKidsRef = parentDict.getRaw("K");
38071 if (!(parentKidsRef instanceof Ref)) {
38072 parentKids = parentKidsRef;
38073 parentKidsRef = xref.getNewTemporaryRef();
38074 parentDict = parentDict.clone();
38075 parentDict.set("K", parentKidsRef);
38076 saveParentDict = true;
38077 } else {
38078 parentKids = xref.fetch(parentKidsRef);
38079 }
38080 if (Array.isArray(parentKids)) {
38081 const index = parentKids.indexOf(ref);
38082 if (index >= 0) {
38083 parentKids = parentKids.slice();
38084 parentKids.splice(index + 1, 0, newTagRef);
38085 } else {
38086 warn("Cannot update the struct tree: parent kid not found.");
38087 tagDict.set("P", fallbackRef);
38088 return;
38089 }
38090 } else if (parentKids instanceof Dict) {
38091 parentKids = [parentKidsRef, newTagRef];
38092 parentKidsRef = xref.getNewTemporaryRef();
38093 parentDict.set("K", parentKidsRef);
38094 saveParentDict = true;
38095 }
38096 buffer.length = 0;
38097 await writeObject(parentKidsRef, parentKids, buffer, xref);
38098 newRefs.push({
38099 ref: parentKidsRef,
38100 data: buffer.join("")
38101 });
38102 if (!saveParentDict) {
38103 return;
38104 }
38105 buffer.length = 0;
38106 await writeObject(parentRef, parentDict, buffer, xref);
38107 newRefs.push({
38108 ref: parentRef,
38109 data: buffer.join("")
38110 });
38111 }
38112}
38113class StructElementNode {
38114 constructor(tree, dict) {
38115 this.tree = tree;
38116 this.dict = dict;
38117 this.kids = [];
38118 this.parseKids();
38119 }
38120 get role() {
38121 const nameObj = this.dict.get("S");
38122 const name = nameObj instanceof Name ? nameObj.name : "";
38123 const {
38124 root
38125 } = this.tree;
38126 if (root.roleMap.has(name)) {
38127 return root.roleMap.get(name);
38128 }
38129 return name;
38130 }
38131 parseKids() {
38132 let pageObjId = null;
38133 const objRef = this.dict.getRaw("Pg");
38134 if (objRef instanceof Ref) {
38135 pageObjId = objRef.toString();
38136 }
38137 const kids = this.dict.get("K");
38138 if (Array.isArray(kids)) {
38139 for (const kid of kids) {
38140 const element = this.parseKid(pageObjId, kid);
38141 if (element) {
38142 this.kids.push(element);
38143 }
38144 }
38145 } else {
38146 const element = this.parseKid(pageObjId, kids);
38147 if (element) {
38148 this.kids.push(element);
38149 }
38150 }
38151 }
38152 parseKid(pageObjId, kid) {
38153 if (Number.isInteger(kid)) {
38154 if (this.tree.pageDict.objId !== pageObjId) {
38155 return null;
38156 }
38157 return new StructElement({
38158 type: StructElementType.PAGE_CONTENT,
38159 mcid: kid,
38160 pageObjId
38161 });
38162 }
38163 let kidDict = null;
38164 if (kid instanceof Ref) {
38165 kidDict = this.dict.xref.fetch(kid);
38166 } else if (kid instanceof Dict) {
38167 kidDict = kid;
38168 }
38169 if (!kidDict) {
38170 return null;
38171 }
38172 const pageRef = kidDict.getRaw("Pg");
38173 if (pageRef instanceof Ref) {
38174 pageObjId = pageRef.toString();
38175 }
38176 const type = kidDict.get("Type") instanceof Name ? kidDict.get("Type").name : null;
38177 if (type === "MCR") {
38178 if (this.tree.pageDict.objId !== pageObjId) {
38179 return null;
38180 }
38181 const kidRef = kidDict.getRaw("Stm");
38182 return new StructElement({
38183 type: StructElementType.STREAM_CONTENT,
38184 refObjId: kidRef instanceof Ref ? kidRef.toString() : null,
38185 pageObjId,
38186 mcid: kidDict.get("MCID")
38187 });
38188 }
38189 if (type === "OBJR") {
38190 if (this.tree.pageDict.objId !== pageObjId) {
38191 return null;
38192 }
38193 const kidRef = kidDict.getRaw("Obj");
38194 return new StructElement({
38195 type: StructElementType.OBJECT,
38196 refObjId: kidRef instanceof Ref ? kidRef.toString() : null,
38197 pageObjId
38198 });
38199 }
38200 return new StructElement({
38201 type: StructElementType.ELEMENT,
38202 dict: kidDict
38203 });
38204 }
38205}
38206class StructElement {
38207 constructor({
38208 type,
38209 dict = null,
38210 mcid = null,
38211 pageObjId = null,
38212 refObjId = null
38213 }) {
38214 this.type = type;
38215 this.dict = dict;
38216 this.mcid = mcid;
38217 this.pageObjId = pageObjId;
38218 this.refObjId = refObjId;
38219 this.parentNode = null;
38220 }
38221}
38222class StructTreePage {
38223 constructor(structTreeRoot, pageDict) {
38224 this.root = structTreeRoot;
38225 this.rootDict = structTreeRoot ? structTreeRoot.dict : null;
38226 this.pageDict = pageDict;
38227 this.nodes = [];
38228 }
38229 parse(pageRef) {
38230 if (!this.root || !this.rootDict) {
38231 return;
38232 }
38233 const parentTree = this.rootDict.get("ParentTree");
38234 if (!parentTree) {
38235 return;
38236 }
38237 const id = this.pageDict.get("StructParents");
38238 const ids = pageRef instanceof Ref && this.root.structParentIds?.get(pageRef);
38239 if (!Number.isInteger(id) && !ids) {
38240 return;
38241 }
38242 const map = new Map();
38243 const numberTree = new NumberTree(parentTree, this.rootDict.xref);
38244 if (Number.isInteger(id)) {
38245 const parentArray = numberTree.get(id);
38246 if (Array.isArray(parentArray)) {
38247 for (const ref of parentArray) {
38248 if (ref instanceof Ref) {
38249 this.addNode(this.rootDict.xref.fetch(ref), map);
38250 }
38251 }
38252 }
38253 }
38254 if (!ids) {
38255 return;
38256 }
38257 for (const [elemId, type] of ids) {
38258 const obj = numberTree.get(elemId);
38259 if (obj) {
38260 const elem = this.addNode(this.rootDict.xref.fetchIfRef(obj), map);
38261 if (elem?.kids?.length === 1 && elem.kids[0].type === StructElementType.OBJECT) {
38262 elem.kids[0].type = type;
38263 }
38264 }
38265 }
38266 }
38267 addNode(dict, map, level = 0) {
38268 if (level > MAX_DEPTH) {
38269 warn("StructTree MAX_DEPTH reached.");
38270 return null;
38271 }
38272 if (map.has(dict)) {
38273 return map.get(dict);
38274 }
38275 const element = new StructElementNode(this, dict);
38276 map.set(dict, element);
38277 const parent = dict.get("P");
38278 if (!parent || isName(parent.get("Type"), "StructTreeRoot")) {
38279 if (!this.addTopLevelNode(dict, element)) {
38280 map.delete(dict);
38281 }
38282 return element;
38283 }
38284 const parentNode = this.addNode(parent, map, level + 1);
38285 if (!parentNode) {
38286 return element;
38287 }
38288 let save = false;
38289 for (const kid of parentNode.kids) {
38290 if (kid.type === StructElementType.ELEMENT && kid.dict === dict) {
38291 kid.parentNode = element;
38292 save = true;
38293 }
38294 }
38295 if (!save) {
38296 map.delete(dict);
38297 }
38298 return element;
38299 }
38300 addTopLevelNode(dict, element) {
38301 const obj = this.rootDict.get("K");
38302 if (!obj) {
38303 return false;
38304 }
38305 if (obj instanceof Dict) {
38306 if (obj.objId !== dict.objId) {
38307 return false;
38308 }
38309 this.nodes[0] = element;
38310 return true;
38311 }
38312 if (!Array.isArray(obj)) {
38313 return true;
38314 }
38315 let save = false;
38316 for (let i = 0; i < obj.length; i++) {
38317 const kidRef = obj[i];
38318 if (kidRef?.toString() === dict.objId) {
38319 this.nodes[i] = element;
38320 save = true;
38321 }
38322 }
38323 return save;
38324 }
38325 get serializable() {
38326 function nodeToSerializable(node, parent, level = 0) {
38327 if (level > MAX_DEPTH) {
38328 warn("StructTree too deep to be fully serialized.");
38329 return;
38330 }
38331 const obj = Object.create(null);
38332 obj.role = node.role;
38333 obj.children = [];
38334 parent.children.push(obj);
38335 const alt = node.dict.get("Alt");
38336 if (typeof alt === "string") {
38337 obj.alt = stringToPDFString(alt);
38338 }
38339 const lang = node.dict.get("Lang");
38340 if (typeof lang === "string") {
38341 obj.lang = stringToPDFString(lang);
38342 }
38343 for (const kid of node.kids) {
38344 const kidElement = kid.type === StructElementType.ELEMENT ? kid.parentNode : null;
38345 if (kidElement) {
38346 nodeToSerializable(kidElement, obj, level + 1);
38347 continue;
38348 } else if (kid.type === StructElementType.PAGE_CONTENT || kid.type === StructElementType.STREAM_CONTENT) {
38349 obj.children.push({
38350 type: "content",
38351 id: `p${kid.pageObjId}_mc${kid.mcid}`
38352 });
38353 } else if (kid.type === StructElementType.OBJECT) {
38354 obj.children.push({
38355 type: "object",
38356 id: kid.refObjId
38357 });
38358 } else if (kid.type === StructElementType.ANNOTATION) {
38359 obj.children.push({
38360 type: "annotation",
38361 id: `${AnnotationPrefix}${kid.refObjId}`
38362 });
38363 }
38364 }
38365 }
38366 const root = Object.create(null);
38367 root.children = [];
38368 root.role = "Root";
38369 for (const child of this.nodes) {
38370 if (!child) {
38371 continue;
38372 }
38373 nodeToSerializable(child, root);
38374 }
38375 return root;
38376 }
38377}
38378
38379;// CONCATENATED MODULE: ./src/core/catalog.js
38380
38381
38382
38383
38384
38385
38386
38387
38388
38389
38390
38391function fetchDestination(dest) {
38392 if (dest instanceof Dict) {
38393 dest = dest.get("D");
38394 }
38395 return Array.isArray(dest) ? dest : null;
38396}
38397function fetchRemoteDest(action) {
38398 let dest = action.get("D");
38399 if (dest) {
38400 if (dest instanceof Name) {
38401 dest = dest.name;
38402 }
38403 if (typeof dest === "string") {
38404 return stringToPDFString(dest);
38405 } else if (Array.isArray(dest)) {
38406 return JSON.stringify(dest);
38407 }
38408 }
38409 return null;
38410}
38411class Catalog {
38412 constructor(pdfManager, xref) {
38413 this.pdfManager = pdfManager;
38414 this.xref = xref;
38415 this._catDict = xref.getCatalogObj();
38416 if (!(this._catDict instanceof Dict)) {
38417 throw new FormatError("Catalog object is not a dictionary.");
38418 }
38419 this.toplevelPagesDict;
38420 this._actualNumPages = null;
38421 this.fontCache = new RefSetCache();
38422 this.builtInCMapCache = new Map();
38423 this.standardFontDataCache = new Map();
38424 this.globalImageCache = new GlobalImageCache();
38425 this.pageKidsCountCache = new RefSetCache();
38426 this.pageIndexCache = new RefSetCache();
38427 this.nonBlendModesSet = new RefSet();
38428 this.systemFontCache = new Map();
38429 }
38430 cloneDict() {
38431 return this._catDict.clone();
38432 }
38433 get version() {
38434 const version = this._catDict.get("Version");
38435 if (version instanceof Name) {
38436 if (PDF_VERSION_REGEXP.test(version.name)) {
38437 return shadow(this, "version", version.name);
38438 }
38439 warn(`Invalid PDF catalog version: ${version.name}`);
38440 }
38441 return shadow(this, "version", null);
38442 }
38443 get lang() {
38444 const lang = this._catDict.get("Lang");
38445 return shadow(this, "lang", typeof lang === "string" ? stringToPDFString(lang) : null);
38446 }
38447 get needsRendering() {
38448 const needsRendering = this._catDict.get("NeedsRendering");
38449 return shadow(this, "needsRendering", typeof needsRendering === "boolean" ? needsRendering : false);
38450 }
38451 get collection() {
38452 let collection = null;
38453 try {
38454 const obj = this._catDict.get("Collection");
38455 if (obj instanceof Dict && obj.size > 0) {
38456 collection = obj;
38457 }
38458 } catch (ex) {
38459 if (ex instanceof MissingDataException) {
38460 throw ex;
38461 }
38462 info("Cannot fetch Collection entry; assuming no collection is present.");
38463 }
38464 return shadow(this, "collection", collection);
38465 }
38466 get acroForm() {
38467 let acroForm = null;
38468 try {
38469 const obj = this._catDict.get("AcroForm");
38470 if (obj instanceof Dict && obj.size > 0) {
38471 acroForm = obj;
38472 }
38473 } catch (ex) {
38474 if (ex instanceof MissingDataException) {
38475 throw ex;
38476 }
38477 info("Cannot fetch AcroForm entry; assuming no forms are present.");
38478 }
38479 return shadow(this, "acroForm", acroForm);
38480 }
38481 get acroFormRef() {
38482 const value = this._catDict.getRaw("AcroForm");
38483 return shadow(this, "acroFormRef", value instanceof Ref ? value : null);
38484 }
38485 get metadata() {
38486 const streamRef = this._catDict.getRaw("Metadata");
38487 if (!(streamRef instanceof Ref)) {
38488 return shadow(this, "metadata", null);
38489 }
38490 let metadata = null;
38491 try {
38492 const stream = this.xref.fetch(streamRef, !this.xref.encrypt?.encryptMetadata);
38493 if (stream instanceof BaseStream && stream.dict instanceof Dict) {
38494 const type = stream.dict.get("Type");
38495 const subtype = stream.dict.get("Subtype");
38496 if (isName(type, "Metadata") && isName(subtype, "XML")) {
38497 const data = stringToUTF8String(stream.getString());
38498 if (data) {
38499 metadata = new MetadataParser(data).serializable;
38500 }
38501 }
38502 }
38503 } catch (ex) {
38504 if (ex instanceof MissingDataException) {
38505 throw ex;
38506 }
38507 info(`Skipping invalid Metadata: "${ex}".`);
38508 }
38509 return shadow(this, "metadata", metadata);
38510 }
38511 get markInfo() {
38512 let markInfo = null;
38513 try {
38514 markInfo = this._readMarkInfo();
38515 } catch (ex) {
38516 if (ex instanceof MissingDataException) {
38517 throw ex;
38518 }
38519 warn("Unable to read mark info.");
38520 }
38521 return shadow(this, "markInfo", markInfo);
38522 }
38523 _readMarkInfo() {
38524 const obj = this._catDict.get("MarkInfo");
38525 if (!(obj instanceof Dict)) {
38526 return null;
38527 }
38528 const markInfo = {
38529 Marked: false,
38530 UserProperties: false,
38531 Suspects: false
38532 };
38533 for (const key in markInfo) {
38534 const value = obj.get(key);
38535 if (typeof value === "boolean") {
38536 markInfo[key] = value;
38537 }
38538 }
38539 return markInfo;
38540 }
38541 get structTreeRoot() {
38542 let structTree = null;
38543 try {
38544 structTree = this._readStructTreeRoot();
38545 } catch (ex) {
38546 if (ex instanceof MissingDataException) {
38547 throw ex;
38548 }
38549 warn("Unable read to structTreeRoot info.");
38550 }
38551 return shadow(this, "structTreeRoot", structTree);
38552 }
38553 _readStructTreeRoot() {
38554 const rawObj = this._catDict.getRaw("StructTreeRoot");
38555 const obj = this.xref.fetchIfRef(rawObj);
38556 if (!(obj instanceof Dict)) {
38557 return null;
38558 }
38559 const root = new StructTreeRoot(obj, rawObj);
38560 root.init();
38561 return root;
38562 }
38563 get toplevelPagesDict() {
38564 const pagesObj = this._catDict.get("Pages");
38565 if (!(pagesObj instanceof Dict)) {
38566 throw new FormatError("Invalid top-level pages dictionary.");
38567 }
38568 return shadow(this, "toplevelPagesDict", pagesObj);
38569 }
38570 get documentOutline() {
38571 let obj = null;
38572 try {
38573 obj = this._readDocumentOutline();
38574 } catch (ex) {
38575 if (ex instanceof MissingDataException) {
38576 throw ex;
38577 }
38578 warn("Unable to read document outline.");
38579 }
38580 return shadow(this, "documentOutline", obj);
38581 }
38582 _readDocumentOutline() {
38583 let obj = this._catDict.get("Outlines");
38584 if (!(obj instanceof Dict)) {
38585 return null;
38586 }
38587 obj = obj.getRaw("First");
38588 if (!(obj instanceof Ref)) {
38589 return null;
38590 }
38591 const root = {
38592 items: []
38593 };
38594 const queue = [{
38595 obj,
38596 parent: root
38597 }];
38598 const processed = new RefSet();
38599 processed.put(obj);
38600 const xref = this.xref,
38601 blackColor = new Uint8ClampedArray(3);
38602 while (queue.length > 0) {
38603 const i = queue.shift();
38604 const outlineDict = xref.fetchIfRef(i.obj);
38605 if (outlineDict === null) {
38606 continue;
38607 }
38608 if (!outlineDict.has("Title")) {
38609 warn("Invalid outline item encountered.");
38610 }
38611 const data = {
38612 url: null,
38613 dest: null,
38614 action: null
38615 };
38616 Catalog.parseDestDictionary({
38617 destDict: outlineDict,
38618 resultObj: data,
38619 docBaseUrl: this.baseUrl,
38620 docAttachments: this.attachments
38621 });
38622 const title = outlineDict.get("Title");
38623 const flags = outlineDict.get("F") || 0;
38624 const color = outlineDict.getArray("C");
38625 const count = outlineDict.get("Count");
38626 let rgbColor = blackColor;
38627 if (Array.isArray(color) && color.length === 3 && (color[0] !== 0 || color[1] !== 0 || color[2] !== 0)) {
38628 rgbColor = ColorSpace.singletons.rgb.getRgb(color, 0);
38629 }
38630 const outlineItem = {
38631 action: data.action,
38632 attachment: data.attachment,
38633 dest: data.dest,
38634 url: data.url,
38635 unsafeUrl: data.unsafeUrl,
38636 newWindow: data.newWindow,
38637 setOCGState: data.setOCGState,
38638 title: typeof title === "string" ? stringToPDFString(title) : "",
38639 color: rgbColor,
38640 count: Number.isInteger(count) ? count : undefined,
38641 bold: !!(flags & 2),
38642 italic: !!(flags & 1),
38643 items: []
38644 };
38645 i.parent.items.push(outlineItem);
38646 obj = outlineDict.getRaw("First");
38647 if (obj instanceof Ref && !processed.has(obj)) {
38648 queue.push({
38649 obj,
38650 parent: outlineItem
38651 });
38652 processed.put(obj);
38653 }
38654 obj = outlineDict.getRaw("Next");
38655 if (obj instanceof Ref && !processed.has(obj)) {
38656 queue.push({
38657 obj,
38658 parent: i.parent
38659 });
38660 processed.put(obj);
38661 }
38662 }
38663 return root.items.length > 0 ? root.items : null;
38664 }
38665 get permissions() {
38666 let permissions = null;
38667 try {
38668 permissions = this._readPermissions();
38669 } catch (ex) {
38670 if (ex instanceof MissingDataException) {
38671 throw ex;
38672 }
38673 warn("Unable to read permissions.");
38674 }
38675 return shadow(this, "permissions", permissions);
38676 }
38677 _readPermissions() {
38678 const encrypt = this.xref.trailer.get("Encrypt");
38679 if (!(encrypt instanceof Dict)) {
38680 return null;
38681 }
38682 let flags = encrypt.get("P");
38683 if (typeof flags !== "number") {
38684 return null;
38685 }
38686 flags += 2 ** 32;
38687 const permissions = [];
38688 for (const key in PermissionFlag) {
38689 const value = PermissionFlag[key];
38690 if (flags & value) {
38691 permissions.push(value);
38692 }
38693 }
38694 return permissions;
38695 }
38696 get optionalContentConfig() {
38697 let config = null;
38698 try {
38699 const properties = this._catDict.get("OCProperties");
38700 if (!properties) {
38701 return shadow(this, "optionalContentConfig", null);
38702 }
38703 const defaultConfig = properties.get("D");
38704 if (!defaultConfig) {
38705 return shadow(this, "optionalContentConfig", null);
38706 }
38707 const groupsData = properties.get("OCGs");
38708 if (!Array.isArray(groupsData)) {
38709 return shadow(this, "optionalContentConfig", null);
38710 }
38711 const groups = [];
38712 const groupRefs = new RefSet();
38713 for (const groupRef of groupsData) {
38714 if (!(groupRef instanceof Ref) || groupRefs.has(groupRef)) {
38715 continue;
38716 }
38717 groupRefs.put(groupRef);
38718 groups.push(this.#readOptionalContentGroup(groupRef));
38719 }
38720 config = this.#readOptionalContentConfig(defaultConfig, groupRefs);
38721 config.groups = groups;
38722 } catch (ex) {
38723 if (ex instanceof MissingDataException) {
38724 throw ex;
38725 }
38726 warn(`Unable to read optional content config: ${ex}`);
38727 }
38728 return shadow(this, "optionalContentConfig", config);
38729 }
38730 #readOptionalContentGroup(groupRef) {
38731 const group = this.xref.fetch(groupRef);
38732 const obj = {
38733 id: groupRef.toString(),
38734 name: null,
38735 intent: null,
38736 usage: {
38737 print: null,
38738 view: null
38739 }
38740 };
38741 const name = group.get("Name");
38742 if (typeof name === "string") {
38743 obj.name = stringToPDFString(name);
38744 }
38745 let intent = group.getArray("Intent");
38746 if (!Array.isArray(intent)) {
38747 intent = [intent];
38748 }
38749 if (intent.every(i => i instanceof Name)) {
38750 obj.intent = intent.map(i => i.name);
38751 }
38752 const usage = group.get("Usage");
38753 if (!(usage instanceof Dict)) {
38754 return obj;
38755 }
38756 const usageObj = obj.usage;
38757 const print = usage.get("Print");
38758 if (print instanceof Dict) {
38759 const printState = print.get("PrintState");
38760 if (printState instanceof Name) {
38761 switch (printState.name) {
38762 case "ON":
38763 case "OFF":
38764 usageObj.print = {
38765 printState: printState.name
38766 };
38767 }
38768 }
38769 }
38770 const view = usage.get("View");
38771 if (view instanceof Dict) {
38772 const viewState = view.get("ViewState");
38773 if (viewState instanceof Name) {
38774 switch (viewState.name) {
38775 case "ON":
38776 case "OFF":
38777 usageObj.view = {
38778 viewState: viewState.name
38779 };
38780 }
38781 }
38782 }
38783 return obj;
38784 }
38785 #readOptionalContentConfig(config, contentGroupRefs) {
38786 function parseOnOff(refs) {
38787 const onParsed = [];
38788 if (Array.isArray(refs)) {
38789 for (const value of refs) {
38790 if (!(value instanceof Ref)) {
38791 continue;
38792 }
38793 if (contentGroupRefs.has(value)) {
38794 onParsed.push(value.toString());
38795 }
38796 }
38797 }
38798 return onParsed;
38799 }
38800 function parseOrder(refs, nestedLevels = 0) {
38801 if (!Array.isArray(refs)) {
38802 return null;
38803 }
38804 const order = [];
38805 for (const value of refs) {
38806 if (value instanceof Ref && contentGroupRefs.has(value)) {
38807 parsedOrderRefs.put(value);
38808 order.push(value.toString());
38809 continue;
38810 }
38811 const nestedOrder = parseNestedOrder(value, nestedLevels);
38812 if (nestedOrder) {
38813 order.push(nestedOrder);
38814 }
38815 }
38816 if (nestedLevels > 0) {
38817 return order;
38818 }
38819 const hiddenGroups = [];
38820 for (const groupRef of contentGroupRefs) {
38821 if (parsedOrderRefs.has(groupRef)) {
38822 continue;
38823 }
38824 hiddenGroups.push(groupRef.toString());
38825 }
38826 if (hiddenGroups.length) {
38827 order.push({
38828 name: null,
38829 order: hiddenGroups
38830 });
38831 }
38832 return order;
38833 }
38834 function parseNestedOrder(ref, nestedLevels) {
38835 if (++nestedLevels > MAX_NESTED_LEVELS) {
38836 warn("parseNestedOrder - reached MAX_NESTED_LEVELS.");
38837 return null;
38838 }
38839 const value = xref.fetchIfRef(ref);
38840 if (!Array.isArray(value)) {
38841 return null;
38842 }
38843 const nestedName = xref.fetchIfRef(value[0]);
38844 if (typeof nestedName !== "string") {
38845 return null;
38846 }
38847 const nestedOrder = parseOrder(value.slice(1), nestedLevels);
38848 if (!nestedOrder || !nestedOrder.length) {
38849 return null;
38850 }
38851 return {
38852 name: stringToPDFString(nestedName),
38853 order: nestedOrder
38854 };
38855 }
38856 const xref = this.xref,
38857 parsedOrderRefs = new RefSet(),
38858 MAX_NESTED_LEVELS = 10;
38859 return {
38860 name: typeof config.get("Name") === "string" ? stringToPDFString(config.get("Name")) : null,
38861 creator: typeof config.get("Creator") === "string" ? stringToPDFString(config.get("Creator")) : null,
38862 baseState: config.get("BaseState") instanceof Name ? config.get("BaseState").name : null,
38863 on: parseOnOff(config.get("ON")),
38864 off: parseOnOff(config.get("OFF")),
38865 order: parseOrder(config.get("Order")),
38866 groups: null
38867 };
38868 }
38869 setActualNumPages(num = null) {
38870 this._actualNumPages = num;
38871 }
38872 get hasActualNumPages() {
38873 return this._actualNumPages !== null;
38874 }
38875 get _pagesCount() {
38876 const obj = this.toplevelPagesDict.get("Count");
38877 if (!Number.isInteger(obj)) {
38878 throw new FormatError("Page count in top-level pages dictionary is not an integer.");
38879 }
38880 return shadow(this, "_pagesCount", obj);
38881 }
38882 get numPages() {
38883 return this.hasActualNumPages ? this._actualNumPages : this._pagesCount;
38884 }
38885 get destinations() {
38886 const obj = this._readDests(),
38887 dests = Object.create(null);
38888 if (obj instanceof NameTree) {
38889 for (const [key, value] of obj.getAll()) {
38890 const dest = fetchDestination(value);
38891 if (dest) {
38892 dests[stringToPDFString(key)] = dest;
38893 }
38894 }
38895 } else if (obj instanceof Dict) {
38896 obj.forEach(function (key, value) {
38897 const dest = fetchDestination(value);
38898 if (dest) {
38899 dests[key] = dest;
38900 }
38901 });
38902 }
38903 return shadow(this, "destinations", dests);
38904 }
38905 getDestination(id) {
38906 const obj = this._readDests();
38907 if (obj instanceof NameTree) {
38908 const dest = fetchDestination(obj.get(id));
38909 if (dest) {
38910 return dest;
38911 }
38912 const allDest = this.destinations[id];
38913 if (allDest) {
38914 warn(`Found "${id}" at an incorrect position in the NameTree.`);
38915 return allDest;
38916 }
38917 } else if (obj instanceof Dict) {
38918 const dest = fetchDestination(obj.get(id));
38919 if (dest) {
38920 return dest;
38921 }
38922 }
38923 return null;
38924 }
38925 _readDests() {
38926 const obj = this._catDict.get("Names");
38927 if (obj?.has("Dests")) {
38928 return new NameTree(obj.getRaw("Dests"), this.xref);
38929 } else if (this._catDict.has("Dests")) {
38930 return this._catDict.get("Dests");
38931 }
38932 return undefined;
38933 }
38934 get pageLabels() {
38935 let obj = null;
38936 try {
38937 obj = this._readPageLabels();
38938 } catch (ex) {
38939 if (ex instanceof MissingDataException) {
38940 throw ex;
38941 }
38942 warn("Unable to read page labels.");
38943 }
38944 return shadow(this, "pageLabels", obj);
38945 }
38946 _readPageLabels() {
38947 const obj = this._catDict.getRaw("PageLabels");
38948 if (!obj) {
38949 return null;
38950 }
38951 const pageLabels = new Array(this.numPages);
38952 let style = null,
38953 prefix = "";
38954 const numberTree = new NumberTree(obj, this.xref);
38955 const nums = numberTree.getAll();
38956 let currentLabel = "",
38957 currentIndex = 1;
38958 for (let i = 0, ii = this.numPages; i < ii; i++) {
38959 const labelDict = nums.get(i);
38960 if (labelDict !== undefined) {
38961 if (!(labelDict instanceof Dict)) {
38962 throw new FormatError("PageLabel is not a dictionary.");
38963 }
38964 if (labelDict.has("Type") && !isName(labelDict.get("Type"), "PageLabel")) {
38965 throw new FormatError("Invalid type in PageLabel dictionary.");
38966 }
38967 if (labelDict.has("S")) {
38968 const s = labelDict.get("S");
38969 if (!(s instanceof Name)) {
38970 throw new FormatError("Invalid style in PageLabel dictionary.");
38971 }
38972 style = s.name;
38973 } else {
38974 style = null;
38975 }
38976 if (labelDict.has("P")) {
38977 const p = labelDict.get("P");
38978 if (typeof p !== "string") {
38979 throw new FormatError("Invalid prefix in PageLabel dictionary.");
38980 }
38981 prefix = stringToPDFString(p);
38982 } else {
38983 prefix = "";
38984 }
38985 if (labelDict.has("St")) {
38986 const st = labelDict.get("St");
38987 if (!(Number.isInteger(st) && st >= 1)) {
38988 throw new FormatError("Invalid start in PageLabel dictionary.");
38989 }
38990 currentIndex = st;
38991 } else {
38992 currentIndex = 1;
38993 }
38994 }
38995 switch (style) {
38996 case "D":
38997 currentLabel = currentIndex;
38998 break;
38999 case "R":
39000 case "r":
39001 currentLabel = toRomanNumerals(currentIndex, style === "r");
39002 break;
39003 case "A":
39004 case "a":
39005 const LIMIT = 26;
39006 const A_UPPER_CASE = 0x41,
39007 A_LOWER_CASE = 0x61;
39008 const baseCharCode = style === "a" ? A_LOWER_CASE : A_UPPER_CASE;
39009 const letterIndex = currentIndex - 1;
39010 const character = String.fromCharCode(baseCharCode + letterIndex % LIMIT);
39011 currentLabel = character.repeat(Math.floor(letterIndex / LIMIT) + 1);
39012 break;
39013 default:
39014 if (style) {
39015 throw new FormatError(`Invalid style "${style}" in PageLabel dictionary.`);
39016 }
39017 currentLabel = "";
39018 }
39019 pageLabels[i] = prefix + currentLabel;
39020 currentIndex++;
39021 }
39022 return pageLabels;
39023 }
39024 get pageLayout() {
39025 const obj = this._catDict.get("PageLayout");
39026 let pageLayout = "";
39027 if (obj instanceof Name) {
39028 switch (obj.name) {
39029 case "SinglePage":
39030 case "OneColumn":
39031 case "TwoColumnLeft":
39032 case "TwoColumnRight":
39033 case "TwoPageLeft":
39034 case "TwoPageRight":
39035 pageLayout = obj.name;
39036 }
39037 }
39038 return shadow(this, "pageLayout", pageLayout);
39039 }
39040 get pageMode() {
39041 const obj = this._catDict.get("PageMode");
39042 let pageMode = "UseNone";
39043 if (obj instanceof Name) {
39044 switch (obj.name) {
39045 case "UseNone":
39046 case "UseOutlines":
39047 case "UseThumbs":
39048 case "FullScreen":
39049 case "UseOC":
39050 case "UseAttachments":
39051 pageMode = obj.name;
39052 }
39053 }
39054 return shadow(this, "pageMode", pageMode);
39055 }
39056 get viewerPreferences() {
39057 const obj = this._catDict.get("ViewerPreferences");
39058 if (!(obj instanceof Dict)) {
39059 return shadow(this, "viewerPreferences", null);
39060 }
39061 let prefs = null;
39062 for (const key of obj.getKeys()) {
39063 const value = obj.get(key);
39064 let prefValue;
39065 switch (key) {
39066 case "HideToolbar":
39067 case "HideMenubar":
39068 case "HideWindowUI":
39069 case "FitWindow":
39070 case "CenterWindow":
39071 case "DisplayDocTitle":
39072 case "PickTrayByPDFSize":
39073 if (typeof value === "boolean") {
39074 prefValue = value;
39075 }
39076 break;
39077 case "NonFullScreenPageMode":
39078 if (value instanceof Name) {
39079 switch (value.name) {
39080 case "UseNone":
39081 case "UseOutlines":
39082 case "UseThumbs":
39083 case "UseOC":
39084 prefValue = value.name;
39085 break;
39086 default:
39087 prefValue = "UseNone";
39088 }
39089 }
39090 break;
39091 case "Direction":
39092 if (value instanceof Name) {
39093 switch (value.name) {
39094 case "L2R":
39095 case "R2L":
39096 prefValue = value.name;
39097 break;
39098 default:
39099 prefValue = "L2R";
39100 }
39101 }
39102 break;
39103 case "ViewArea":
39104 case "ViewClip":
39105 case "PrintArea":
39106 case "PrintClip":
39107 if (value instanceof Name) {
39108 switch (value.name) {
39109 case "MediaBox":
39110 case "CropBox":
39111 case "BleedBox":
39112 case "TrimBox":
39113 case "ArtBox":
39114 prefValue = value.name;
39115 break;
39116 default:
39117 prefValue = "CropBox";
39118 }
39119 }
39120 break;
39121 case "PrintScaling":
39122 if (value instanceof Name) {
39123 switch (value.name) {
39124 case "None":
39125 case "AppDefault":
39126 prefValue = value.name;
39127 break;
39128 default:
39129 prefValue = "AppDefault";
39130 }
39131 }
39132 break;
39133 case "Duplex":
39134 if (value instanceof Name) {
39135 switch (value.name) {
39136 case "Simplex":
39137 case "DuplexFlipShortEdge":
39138 case "DuplexFlipLongEdge":
39139 prefValue = value.name;
39140 break;
39141 default:
39142 prefValue = "None";
39143 }
39144 }
39145 break;
39146 case "PrintPageRange":
39147 if (Array.isArray(value) && value.length % 2 === 0) {
39148 const isValid = value.every((page, i, arr) => Number.isInteger(page) && page > 0 && (i === 0 || page >= arr[i - 1]) && page <= this.numPages);
39149 if (isValid) {
39150 prefValue = value;
39151 }
39152 }
39153 break;
39154 case "NumCopies":
39155 if (Number.isInteger(value) && value > 0) {
39156 prefValue = value;
39157 }
39158 break;
39159 default:
39160 warn(`Ignoring non-standard key in ViewerPreferences: ${key}.`);
39161 continue;
39162 }
39163 if (prefValue === undefined) {
39164 warn(`Bad value, for key "${key}", in ViewerPreferences: ${value}.`);
39165 continue;
39166 }
39167 if (!prefs) {
39168 prefs = Object.create(null);
39169 }
39170 prefs[key] = prefValue;
39171 }
39172 return shadow(this, "viewerPreferences", prefs);
39173 }
39174 get openAction() {
39175 const obj = this._catDict.get("OpenAction");
39176 const openAction = Object.create(null);
39177 if (obj instanceof Dict) {
39178 const destDict = new Dict(this.xref);
39179 destDict.set("A", obj);
39180 const resultObj = {
39181 url: null,
39182 dest: null,
39183 action: null
39184 };
39185 Catalog.parseDestDictionary({
39186 destDict,
39187 resultObj
39188 });
39189 if (Array.isArray(resultObj.dest)) {
39190 openAction.dest = resultObj.dest;
39191 } else if (resultObj.action) {
39192 openAction.action = resultObj.action;
39193 }
39194 } else if (Array.isArray(obj)) {
39195 openAction.dest = obj;
39196 }
39197 return shadow(this, "openAction", objectSize(openAction) > 0 ? openAction : null);
39198 }
39199 get attachments() {
39200 const obj = this._catDict.get("Names");
39201 let attachments = null;
39202 if (obj instanceof Dict && obj.has("EmbeddedFiles")) {
39203 const nameTree = new NameTree(obj.getRaw("EmbeddedFiles"), this.xref);
39204 for (const [key, value] of nameTree.getAll()) {
39205 const fs = new FileSpec(value, this.xref);
39206 if (!attachments) {
39207 attachments = Object.create(null);
39208 }
39209 attachments[stringToPDFString(key)] = fs.serializable;
39210 }
39211 }
39212 return shadow(this, "attachments", attachments);
39213 }
39214 get xfaImages() {
39215 const obj = this._catDict.get("Names");
39216 let xfaImages = null;
39217 if (obj instanceof Dict && obj.has("XFAImages")) {
39218 const nameTree = new NameTree(obj.getRaw("XFAImages"), this.xref);
39219 for (const [key, value] of nameTree.getAll()) {
39220 if (!xfaImages) {
39221 xfaImages = new Dict(this.xref);
39222 }
39223 xfaImages.set(stringToPDFString(key), value);
39224 }
39225 }
39226 return shadow(this, "xfaImages", xfaImages);
39227 }
39228 _collectJavaScript() {
39229 const obj = this._catDict.get("Names");
39230 let javaScript = null;
39231 function appendIfJavaScriptDict(name, jsDict) {
39232 if (!(jsDict instanceof Dict)) {
39233 return;
39234 }
39235 if (!isName(jsDict.get("S"), "JavaScript")) {
39236 return;
39237 }
39238 let js = jsDict.get("JS");
39239 if (js instanceof BaseStream) {
39240 js = js.getString();
39241 } else if (typeof js !== "string") {
39242 return;
39243 }
39244 js = stringToPDFString(js).replaceAll("\x00", "");
39245 if (js) {
39246 (javaScript ||= new Map()).set(name, js);
39247 }
39248 }
39249 if (obj instanceof Dict && obj.has("JavaScript")) {
39250 const nameTree = new NameTree(obj.getRaw("JavaScript"), this.xref);
39251 for (const [key, value] of nameTree.getAll()) {
39252 appendIfJavaScriptDict(stringToPDFString(key), value);
39253 }
39254 }
39255 const openAction = this._catDict.get("OpenAction");
39256 if (openAction) {
39257 appendIfJavaScriptDict("OpenAction", openAction);
39258 }
39259 return javaScript;
39260 }
39261 get jsActions() {
39262 const javaScript = this._collectJavaScript();
39263 let actions = collectActions(this.xref, this._catDict, DocumentActionEventType);
39264 if (javaScript) {
39265 actions ||= Object.create(null);
39266 for (const [key, val] of javaScript) {
39267 if (key in actions) {
39268 actions[key].push(val);
39269 } else {
39270 actions[key] = [val];
39271 }
39272 }
39273 }
39274 return shadow(this, "jsActions", actions);
39275 }
39276 async fontFallback(id, handler) {
39277 const translatedFonts = await Promise.all(this.fontCache);
39278 for (const translatedFont of translatedFonts) {
39279 if (translatedFont.loadedName === id) {
39280 translatedFont.fallback(handler);
39281 return;
39282 }
39283 }
39284 }
39285 async cleanup(manuallyTriggered = false) {
39286 clearGlobalCaches();
39287 this.globalImageCache.clear(manuallyTriggered);
39288 this.pageKidsCountCache.clear();
39289 this.pageIndexCache.clear();
39290 this.nonBlendModesSet.clear();
39291 const translatedFonts = await Promise.all(this.fontCache);
39292 for (const {
39293 dict
39294 } of translatedFonts) {
39295 delete dict.cacheKey;
39296 }
39297 this.fontCache.clear();
39298 this.builtInCMapCache.clear();
39299 this.standardFontDataCache.clear();
39300 this.systemFontCache.clear();
39301 }
39302 async getPageDict(pageIndex) {
39303 const nodesToVisit = [this.toplevelPagesDict];
39304 const visitedNodes = new RefSet();
39305 const pagesRef = this._catDict.getRaw("Pages");
39306 if (pagesRef instanceof Ref) {
39307 visitedNodes.put(pagesRef);
39308 }
39309 const xref = this.xref,
39310 pageKidsCountCache = this.pageKidsCountCache,
39311 pageIndexCache = this.pageIndexCache;
39312 let currentPageIndex = 0;
39313 while (nodesToVisit.length) {
39314 const currentNode = nodesToVisit.pop();
39315 if (currentNode instanceof Ref) {
39316 const count = pageKidsCountCache.get(currentNode);
39317 if (count >= 0 && currentPageIndex + count <= pageIndex) {
39318 currentPageIndex += count;
39319 continue;
39320 }
39321 if (visitedNodes.has(currentNode)) {
39322 throw new FormatError("Pages tree contains circular reference.");
39323 }
39324 visitedNodes.put(currentNode);
39325 const obj = await xref.fetchAsync(currentNode);
39326 if (obj instanceof Dict) {
39327 let type = obj.getRaw("Type");
39328 if (type instanceof Ref) {
39329 type = await xref.fetchAsync(type);
39330 }
39331 if (isName(type, "Page") || !obj.has("Kids")) {
39332 if (!pageKidsCountCache.has(currentNode)) {
39333 pageKidsCountCache.put(currentNode, 1);
39334 }
39335 if (!pageIndexCache.has(currentNode)) {
39336 pageIndexCache.put(currentNode, currentPageIndex);
39337 }
39338 if (currentPageIndex === pageIndex) {
39339 return [obj, currentNode];
39340 }
39341 currentPageIndex++;
39342 continue;
39343 }
39344 }
39345 nodesToVisit.push(obj);
39346 continue;
39347 }
39348 if (!(currentNode instanceof Dict)) {
39349 throw new FormatError("Page dictionary kid reference points to wrong type of object.");
39350 }
39351 const {
39352 objId
39353 } = currentNode;
39354 let count = currentNode.getRaw("Count");
39355 if (count instanceof Ref) {
39356 count = await xref.fetchAsync(count);
39357 }
39358 if (Number.isInteger(count) && count >= 0) {
39359 if (objId && !pageKidsCountCache.has(objId)) {
39360 pageKidsCountCache.put(objId, count);
39361 }
39362 if (currentPageIndex + count <= pageIndex) {
39363 currentPageIndex += count;
39364 continue;
39365 }
39366 }
39367 let kids = currentNode.getRaw("Kids");
39368 if (kids instanceof Ref) {
39369 kids = await xref.fetchAsync(kids);
39370 }
39371 if (!Array.isArray(kids)) {
39372 let type = currentNode.getRaw("Type");
39373 if (type instanceof Ref) {
39374 type = await xref.fetchAsync(type);
39375 }
39376 if (isName(type, "Page") || !currentNode.has("Kids")) {
39377 if (currentPageIndex === pageIndex) {
39378 return [currentNode, null];
39379 }
39380 currentPageIndex++;
39381 continue;
39382 }
39383 throw new FormatError("Page dictionary kids object is not an array.");
39384 }
39385 for (let last = kids.length - 1; last >= 0; last--) {
39386 nodesToVisit.push(kids[last]);
39387 }
39388 }
39389 throw new Error(`Page index ${pageIndex} not found.`);
39390 }
39391 async getAllPageDicts(recoveryMode = false) {
39392 const {
39393 ignoreErrors
39394 } = this.pdfManager.evaluatorOptions;
39395 const queue = [{
39396 currentNode: this.toplevelPagesDict,
39397 posInKids: 0
39398 }];
39399 const visitedNodes = new RefSet();
39400 const pagesRef = this._catDict.getRaw("Pages");
39401 if (pagesRef instanceof Ref) {
39402 visitedNodes.put(pagesRef);
39403 }
39404 const map = new Map(),
39405 xref = this.xref,
39406 pageIndexCache = this.pageIndexCache;
39407 let pageIndex = 0;
39408 function addPageDict(pageDict, pageRef) {
39409 if (pageRef && !pageIndexCache.has(pageRef)) {
39410 pageIndexCache.put(pageRef, pageIndex);
39411 }
39412 map.set(pageIndex++, [pageDict, pageRef]);
39413 }
39414 function addPageError(error) {
39415 if (error instanceof XRefEntryException && !recoveryMode) {
39416 throw error;
39417 }
39418 if (recoveryMode && ignoreErrors && pageIndex === 0) {
39419 warn(`getAllPageDicts - Skipping invalid first page: "${error}".`);
39420 error = Dict.empty;
39421 }
39422 map.set(pageIndex++, [error, null]);
39423 }
39424 while (queue.length > 0) {
39425 const queueItem = queue.at(-1);
39426 const {
39427 currentNode,
39428 posInKids
39429 } = queueItem;
39430 let kids = currentNode.getRaw("Kids");
39431 if (kids instanceof Ref) {
39432 try {
39433 kids = await xref.fetchAsync(kids);
39434 } catch (ex) {
39435 addPageError(ex);
39436 break;
39437 }
39438 }
39439 if (!Array.isArray(kids)) {
39440 addPageError(new FormatError("Page dictionary kids object is not an array."));
39441 break;
39442 }
39443 if (posInKids >= kids.length) {
39444 queue.pop();
39445 continue;
39446 }
39447 const kidObj = kids[posInKids];
39448 let obj;
39449 if (kidObj instanceof Ref) {
39450 if (visitedNodes.has(kidObj)) {
39451 addPageError(new FormatError("Pages tree contains circular reference."));
39452 break;
39453 }
39454 visitedNodes.put(kidObj);
39455 try {
39456 obj = await xref.fetchAsync(kidObj);
39457 } catch (ex) {
39458 addPageError(ex);
39459 break;
39460 }
39461 } else {
39462 obj = kidObj;
39463 }
39464 if (!(obj instanceof Dict)) {
39465 addPageError(new FormatError("Page dictionary kid reference points to wrong type of object."));
39466 break;
39467 }
39468 let type = obj.getRaw("Type");
39469 if (type instanceof Ref) {
39470 try {
39471 type = await xref.fetchAsync(type);
39472 } catch (ex) {
39473 addPageError(ex);
39474 break;
39475 }
39476 }
39477 if (isName(type, "Page") || !obj.has("Kids")) {
39478 addPageDict(obj, kidObj instanceof Ref ? kidObj : null);
39479 } else {
39480 queue.push({
39481 currentNode: obj,
39482 posInKids: 0
39483 });
39484 }
39485 queueItem.posInKids++;
39486 }
39487 return map;
39488 }
39489 getPageIndex(pageRef) {
39490 const cachedPageIndex = this.pageIndexCache.get(pageRef);
39491 if (cachedPageIndex !== undefined) {
39492 return Promise.resolve(cachedPageIndex);
39493 }
39494 const xref = this.xref;
39495 function pagesBeforeRef(kidRef) {
39496 let total = 0,
39497 parentRef;
39498 return xref.fetchAsync(kidRef).then(function (node) {
39499 if (isRefsEqual(kidRef, pageRef) && !isDict(node, "Page") && !(node instanceof Dict && !node.has("Type") && node.has("Contents"))) {
39500 throw new FormatError("The reference does not point to a /Page dictionary.");
39501 }
39502 if (!node) {
39503 return null;
39504 }
39505 if (!(node instanceof Dict)) {
39506 throw new FormatError("Node must be a dictionary.");
39507 }
39508 parentRef = node.getRaw("Parent");
39509 return node.getAsync("Parent");
39510 }).then(function (parent) {
39511 if (!parent) {
39512 return null;
39513 }
39514 if (!(parent instanceof Dict)) {
39515 throw new FormatError("Parent must be a dictionary.");
39516 }
39517 return parent.getAsync("Kids");
39518 }).then(function (kids) {
39519 if (!kids) {
39520 return null;
39521 }
39522 const kidPromises = [];
39523 let found = false;
39524 for (const kid of kids) {
39525 if (!(kid instanceof Ref)) {
39526 throw new FormatError("Kid must be a reference.");
39527 }
39528 if (isRefsEqual(kid, kidRef)) {
39529 found = true;
39530 break;
39531 }
39532 kidPromises.push(xref.fetchAsync(kid).then(function (obj) {
39533 if (!(obj instanceof Dict)) {
39534 throw new FormatError("Kid node must be a dictionary.");
39535 }
39536 if (obj.has("Count")) {
39537 total += obj.get("Count");
39538 } else {
39539 total++;
39540 }
39541 }));
39542 }
39543 if (!found) {
39544 throw new FormatError("Kid reference not found in parent's kids.");
39545 }
39546 return Promise.all(kidPromises).then(function () {
39547 return [total, parentRef];
39548 });
39549 });
39550 }
39551 let total = 0;
39552 const next = ref => pagesBeforeRef(ref).then(args => {
39553 if (!args) {
39554 this.pageIndexCache.put(pageRef, total);
39555 return total;
39556 }
39557 const [count, parentRef] = args;
39558 total += count;
39559 return next(parentRef);
39560 });
39561 return next(pageRef);
39562 }
39563 get baseUrl() {
39564 const uri = this._catDict.get("URI");
39565 if (uri instanceof Dict) {
39566 const base = uri.get("Base");
39567 if (typeof base === "string") {
39568 const absoluteUrl = createValidAbsoluteUrl(base, null, {
39569 tryConvertEncoding: true
39570 });
39571 if (absoluteUrl) {
39572 return shadow(this, "baseUrl", absoluteUrl.href);
39573 }
39574 }
39575 }
39576 return shadow(this, "baseUrl", this.pdfManager.docBaseUrl);
39577 }
39578 static parseDestDictionary({
39579 destDict,
39580 resultObj,
39581 docBaseUrl = null,
39582 docAttachments = null
39583 }) {
39584 if (!(destDict instanceof Dict)) {
39585 warn("parseDestDictionary: `destDict` must be a dictionary.");
39586 return;
39587 }
39588 let action = destDict.get("A"),
39589 url,
39590 dest;
39591 if (!(action instanceof Dict)) {
39592 if (destDict.has("Dest")) {
39593 action = destDict.get("Dest");
39594 } else {
39595 action = destDict.get("AA");
39596 if (action instanceof Dict) {
39597 if (action.has("D")) {
39598 action = action.get("D");
39599 } else if (action.has("U")) {
39600 action = action.get("U");
39601 }
39602 }
39603 }
39604 }
39605 if (action instanceof Dict) {
39606 const actionType = action.get("S");
39607 if (!(actionType instanceof Name)) {
39608 warn("parseDestDictionary: Invalid type in Action dictionary.");
39609 return;
39610 }
39611 const actionName = actionType.name;
39612 switch (actionName) {
39613 case "ResetForm":
39614 const flags = action.get("Flags");
39615 const include = ((typeof flags === "number" ? flags : 0) & 1) === 0;
39616 const fields = [];
39617 const refs = [];
39618 for (const obj of action.get("Fields") || []) {
39619 if (obj instanceof Ref) {
39620 refs.push(obj.toString());
39621 } else if (typeof obj === "string") {
39622 fields.push(stringToPDFString(obj));
39623 }
39624 }
39625 resultObj.resetForm = {
39626 fields,
39627 refs,
39628 include
39629 };
39630 break;
39631 case "URI":
39632 url = action.get("URI");
39633 if (url instanceof Name) {
39634 url = "/" + url.name;
39635 }
39636 break;
39637 case "GoTo":
39638 dest = action.get("D");
39639 break;
39640 case "Launch":
39641 case "GoToR":
39642 const urlDict = action.get("F");
39643 if (urlDict instanceof Dict) {
39644 const fs = new FileSpec(urlDict, null, true);
39645 const {
39646 filename
39647 } = fs.serializable;
39648 url = filename;
39649 } else if (typeof urlDict === "string") {
39650 url = urlDict;
39651 }
39652 const remoteDest = fetchRemoteDest(action);
39653 if (remoteDest && typeof url === "string") {
39654 url = url.split("#", 1)[0] + "#" + remoteDest;
39655 }
39656 const newWindow = action.get("NewWindow");
39657 if (typeof newWindow === "boolean") {
39658 resultObj.newWindow = newWindow;
39659 }
39660 break;
39661 case "GoToE":
39662 const target = action.get("T");
39663 let attachment;
39664 if (docAttachments && target instanceof Dict) {
39665 const relationship = target.get("R");
39666 const name = target.get("N");
39667 if (isName(relationship, "C") && typeof name === "string") {
39668 attachment = docAttachments[stringToPDFString(name)];
39669 }
39670 }
39671 if (attachment) {
39672 resultObj.attachment = attachment;
39673 const attachmentDest = fetchRemoteDest(action);
39674 if (attachmentDest) {
39675 resultObj.attachmentDest = attachmentDest;
39676 }
39677 } else {
39678 warn(`parseDestDictionary - unimplemented "GoToE" action.`);
39679 }
39680 break;
39681 case "Named":
39682 const namedAction = action.get("N");
39683 if (namedAction instanceof Name) {
39684 resultObj.action = namedAction.name;
39685 }
39686 break;
39687 case "SetOCGState":
39688 const state = action.get("State");
39689 const preserveRB = action.get("PreserveRB");
39690 if (!Array.isArray(state) || state.length === 0) {
39691 break;
39692 }
39693 const stateArr = [];
39694 for (const elem of state) {
39695 if (elem instanceof Name) {
39696 switch (elem.name) {
39697 case "ON":
39698 case "OFF":
39699 case "Toggle":
39700 stateArr.push(elem.name);
39701 break;
39702 }
39703 } else if (elem instanceof Ref) {
39704 stateArr.push(elem.toString());
39705 }
39706 }
39707 if (stateArr.length !== state.length) {
39708 break;
39709 }
39710 resultObj.setOCGState = {
39711 state: stateArr,
39712 preserveRB: typeof preserveRB === "boolean" ? preserveRB : true
39713 };
39714 break;
39715 case "JavaScript":
39716 const jsAction = action.get("JS");
39717 let js;
39718 if (jsAction instanceof BaseStream) {
39719 js = jsAction.getString();
39720 } else if (typeof jsAction === "string") {
39721 js = jsAction;
39722 }
39723 const jsURL = js && recoverJsURL(stringToPDFString(js));
39724 if (jsURL) {
39725 url = jsURL.url;
39726 resultObj.newWindow = jsURL.newWindow;
39727 break;
39728 }
39729 default:
39730 if (actionName === "JavaScript" || actionName === "SubmitForm") {
39731 break;
39732 }
39733 warn(`parseDestDictionary - unsupported action: "${actionName}".`);
39734 break;
39735 }
39736 } else if (destDict.has("Dest")) {
39737 dest = destDict.get("Dest");
39738 }
39739 if (typeof url === "string") {
39740 const absoluteUrl = createValidAbsoluteUrl(url, docBaseUrl, {
39741 addDefaultProtocol: true,
39742 tryConvertEncoding: true
39743 });
39744 if (absoluteUrl) {
39745 resultObj.url = absoluteUrl.href;
39746 }
39747 resultObj.unsafeUrl = url;
39748 }
39749 if (dest) {
39750 if (dest instanceof Name) {
39751 dest = dest.name;
39752 }
39753 if (typeof dest === "string") {
39754 resultObj.dest = stringToPDFString(dest);
39755 } else if (Array.isArray(dest)) {
39756 resultObj.dest = dest;
39757 }
39758 }
39759 }
39760}
39761
39762;// CONCATENATED MODULE: ./src/core/object_loader.js
39763
39764
39765
39766
39767function mayHaveChildren(value) {
39768 return value instanceof Ref || value instanceof Dict || value instanceof BaseStream || Array.isArray(value);
39769}
39770function addChildren(node, nodesToVisit) {
39771 if (node instanceof Dict) {
39772 node = node.getRawValues();
39773 } else if (node instanceof BaseStream) {
39774 node = node.dict.getRawValues();
39775 } else if (!Array.isArray(node)) {
39776 return;
39777 }
39778 for (const rawValue of node) {
39779 if (mayHaveChildren(rawValue)) {
39780 nodesToVisit.push(rawValue);
39781 }
39782 }
39783}
39784class ObjectLoader {
39785 constructor(dict, keys, xref) {
39786 this.dict = dict;
39787 this.keys = keys;
39788 this.xref = xref;
39789 this.refSet = null;
39790 }
39791 async load() {
39792 if (this.xref.stream.isDataLoaded) {
39793 return undefined;
39794 }
39795 const {
39796 keys,
39797 dict
39798 } = this;
39799 this.refSet = new RefSet();
39800 const nodesToVisit = [];
39801 for (const key of keys) {
39802 const rawValue = dict.getRaw(key);
39803 if (rawValue !== undefined) {
39804 nodesToVisit.push(rawValue);
39805 }
39806 }
39807 return this._walk(nodesToVisit);
39808 }
39809 async _walk(nodesToVisit) {
39810 const nodesToRevisit = [];
39811 const pendingRequests = [];
39812 while (nodesToVisit.length) {
39813 let currentNode = nodesToVisit.pop();
39814 if (currentNode instanceof Ref) {
39815 if (this.refSet.has(currentNode)) {
39816 continue;
39817 }
39818 try {
39819 this.refSet.put(currentNode);
39820 currentNode = this.xref.fetch(currentNode);
39821 } catch (ex) {
39822 if (!(ex instanceof MissingDataException)) {
39823 warn(`ObjectLoader._walk - requesting all data: "${ex}".`);
39824 this.refSet = null;
39825 const {
39826 manager
39827 } = this.xref.stream;
39828 return manager.requestAllChunks();
39829 }
39830 nodesToRevisit.push(currentNode);
39831 pendingRequests.push({
39832 begin: ex.begin,
39833 end: ex.end
39834 });
39835 }
39836 }
39837 if (currentNode instanceof BaseStream) {
39838 const baseStreams = currentNode.getBaseStreams();
39839 if (baseStreams) {
39840 let foundMissingData = false;
39841 for (const stream of baseStreams) {
39842 if (stream.isDataLoaded) {
39843 continue;
39844 }
39845 foundMissingData = true;
39846 pendingRequests.push({
39847 begin: stream.start,
39848 end: stream.end
39849 });
39850 }
39851 if (foundMissingData) {
39852 nodesToRevisit.push(currentNode);
39853 }
39854 }
39855 }
39856 addChildren(currentNode, nodesToVisit);
39857 }
39858 if (pendingRequests.length) {
39859 await this.xref.stream.manager.requestRanges(pendingRequests);
39860 for (const node of nodesToRevisit) {
39861 if (node instanceof Ref) {
39862 this.refSet.remove(node);
39863 }
39864 }
39865 return this._walk(nodesToRevisit);
39866 }
39867 this.refSet = null;
39868 return undefined;
39869 }
39870}
39871
39872;// CONCATENATED MODULE: ./src/core/xfa/symbol_utils.js
39873const $acceptWhitespace = Symbol();
39874const $addHTML = Symbol();
39875const $appendChild = Symbol();
39876const $childrenToHTML = Symbol();
39877const $clean = Symbol();
39878const $cleanPage = Symbol();
39879const $cleanup = Symbol();
39880const $clone = Symbol();
39881const $consumed = Symbol();
39882const $content = Symbol("content");
39883const $data = Symbol("data");
39884const $dump = Symbol();
39885const $extra = Symbol("extra");
39886const $finalize = Symbol();
39887const $flushHTML = Symbol();
39888const $getAttributeIt = Symbol();
39889const $getAttributes = Symbol();
39890const $getAvailableSpace = Symbol();
39891const $getChildrenByClass = Symbol();
39892const $getChildrenByName = Symbol();
39893const $getChildrenByNameIt = Symbol();
39894const $getDataValue = Symbol();
39895const $getExtra = Symbol();
39896const $getRealChildrenByNameIt = Symbol();
39897const $getChildren = Symbol();
39898const $getContainedChildren = Symbol();
39899const $getNextPage = Symbol();
39900const $getSubformParent = Symbol();
39901const $getParent = Symbol();
39902const $getTemplateRoot = Symbol();
39903const $globalData = Symbol();
39904const $hasSettableValue = Symbol();
39905const $ids = Symbol();
39906const $indexOf = Symbol();
39907const $insertAt = Symbol();
39908const $isCDATAXml = Symbol();
39909const $isBindable = Symbol();
39910const $isDataValue = Symbol();
39911const $isDescendent = Symbol();
39912const $isNsAgnostic = Symbol();
39913const $isSplittable = Symbol();
39914const $isThereMoreWidth = Symbol();
39915const $isTransparent = Symbol();
39916const $isUsable = Symbol();
39917const $lastAttribute = Symbol();
39918const $namespaceId = Symbol("namespaceId");
39919const $nodeName = Symbol("nodeName");
39920const $nsAttributes = Symbol();
39921const $onChild = Symbol();
39922const $onChildCheck = Symbol();
39923const $onText = Symbol();
39924const $pushGlyphs = Symbol();
39925const $popPara = Symbol();
39926const $pushPara = Symbol();
39927const $removeChild = Symbol();
39928const $root = Symbol("root");
39929const $resolvePrototypes = Symbol();
39930const $searchNode = Symbol();
39931const $setId = Symbol();
39932const $setSetAttributes = Symbol();
39933const $setValue = Symbol();
39934const $tabIndex = Symbol();
39935const $text = Symbol();
39936const $toPages = Symbol();
39937const $toHTML = Symbol();
39938const $toString = Symbol();
39939const $toStyle = Symbol();
39940const $uid = Symbol("uid");
39941
39942;// CONCATENATED MODULE: ./src/core/xfa/namespaces.js
39943const $buildXFAObject = Symbol();
39944const NamespaceIds = {
39945 config: {
39946 id: 0,
39947 check: ns => ns.startsWith("http://www.xfa.org/schema/xci/")
39948 },
39949 connectionSet: {
39950 id: 1,
39951 check: ns => ns.startsWith("http://www.xfa.org/schema/xfa-connection-set/")
39952 },
39953 datasets: {
39954 id: 2,
39955 check: ns => ns.startsWith("http://www.xfa.org/schema/xfa-data/")
39956 },
39957 form: {
39958 id: 3,
39959 check: ns => ns.startsWith("http://www.xfa.org/schema/xfa-form/")
39960 },
39961 localeSet: {
39962 id: 4,
39963 check: ns => ns.startsWith("http://www.xfa.org/schema/xfa-locale-set/")
39964 },
39965 pdf: {
39966 id: 5,
39967 check: ns => ns === "http://ns.adobe.com/xdp/pdf/"
39968 },
39969 signature: {
39970 id: 6,
39971 check: ns => ns === "http://www.w3.org/2000/09/xmldsig#"
39972 },
39973 sourceSet: {
39974 id: 7,
39975 check: ns => ns.startsWith("http://www.xfa.org/schema/xfa-source-set/")
39976 },
39977 stylesheet: {
39978 id: 8,
39979 check: ns => ns === "http://www.w3.org/1999/XSL/Transform"
39980 },
39981 template: {
39982 id: 9,
39983 check: ns => ns.startsWith("http://www.xfa.org/schema/xfa-template/")
39984 },
39985 xdc: {
39986 id: 10,
39987 check: ns => ns.startsWith("http://www.xfa.org/schema/xdc/")
39988 },
39989 xdp: {
39990 id: 11,
39991 check: ns => ns === "http://ns.adobe.com/xdp/"
39992 },
39993 xfdf: {
39994 id: 12,
39995 check: ns => ns === "http://ns.adobe.com/xfdf/"
39996 },
39997 xhtml: {
39998 id: 13,
39999 check: ns => ns === "http://www.w3.org/1999/xhtml"
40000 },
40001 xmpmeta: {
40002 id: 14,
40003 check: ns => ns === "http://ns.adobe.com/xmpmeta/"
40004 }
40005};
40006
40007;// CONCATENATED MODULE: ./src/core/xfa/utils.js
40008
40009const dimConverters = {
40010 pt: x => x,
40011 cm: x => x / 2.54 * 72,
40012 mm: x => x / (10 * 2.54) * 72,
40013 in: x => x * 72,
40014 px: x => x
40015};
40016const measurementPattern = /([+-]?\d+\.?\d*)(.*)/;
40017function stripQuotes(str) {
40018 if (str.startsWith("'") || str.startsWith('"')) {
40019 return str.slice(1, -1);
40020 }
40021 return str;
40022}
40023function getInteger({
40024 data,
40025 defaultValue,
40026 validate
40027}) {
40028 if (!data) {
40029 return defaultValue;
40030 }
40031 data = data.trim();
40032 const n = parseInt(data, 10);
40033 if (!isNaN(n) && validate(n)) {
40034 return n;
40035 }
40036 return defaultValue;
40037}
40038function getFloat({
40039 data,
40040 defaultValue,
40041 validate
40042}) {
40043 if (!data) {
40044 return defaultValue;
40045 }
40046 data = data.trim();
40047 const n = parseFloat(data);
40048 if (!isNaN(n) && validate(n)) {
40049 return n;
40050 }
40051 return defaultValue;
40052}
40053function getKeyword({
40054 data,
40055 defaultValue,
40056 validate
40057}) {
40058 if (!data) {
40059 return defaultValue;
40060 }
40061 data = data.trim();
40062 if (validate(data)) {
40063 return data;
40064 }
40065 return defaultValue;
40066}
40067function getStringOption(data, options) {
40068 return getKeyword({
40069 data,
40070 defaultValue: options[0],
40071 validate: k => options.includes(k)
40072 });
40073}
40074function getMeasurement(str, def = "0") {
40075 def ||= "0";
40076 if (!str) {
40077 return getMeasurement(def);
40078 }
40079 const match = str.trim().match(measurementPattern);
40080 if (!match) {
40081 return getMeasurement(def);
40082 }
40083 const [, valueStr, unit] = match;
40084 const value = parseFloat(valueStr);
40085 if (isNaN(value)) {
40086 return getMeasurement(def);
40087 }
40088 if (value === 0) {
40089 return 0;
40090 }
40091 const conv = dimConverters[unit];
40092 if (conv) {
40093 return conv(value);
40094 }
40095 return value;
40096}
40097function getRatio(data) {
40098 if (!data) {
40099 return {
40100 num: 1,
40101 den: 1
40102 };
40103 }
40104 const ratio = data.trim().split(/\s*:\s*/).map(x => parseFloat(x)).filter(x => !isNaN(x));
40105 if (ratio.length === 1) {
40106 ratio.push(1);
40107 }
40108 if (ratio.length === 0) {
40109 return {
40110 num: 1,
40111 den: 1
40112 };
40113 }
40114 const [num, den] = ratio;
40115 return {
40116 num,
40117 den
40118 };
40119}
40120function getRelevant(data) {
40121 if (!data) {
40122 return [];
40123 }
40124 return data.trim().split(/\s+/).map(e => ({
40125 excluded: e[0] === "-",
40126 viewname: e.substring(1)
40127 }));
40128}
40129function getColor(data, def = [0, 0, 0]) {
40130 let [r, g, b] = def;
40131 if (!data) {
40132 return {
40133 r,
40134 g,
40135 b
40136 };
40137 }
40138 const color = data.trim().split(/\s*,\s*/).map(c => Math.min(Math.max(0, parseInt(c.trim(), 10)), 255)).map(c => isNaN(c) ? 0 : c);
40139 if (color.length < 3) {
40140 return {
40141 r,
40142 g,
40143 b
40144 };
40145 }
40146 [r, g, b] = color;
40147 return {
40148 r,
40149 g,
40150 b
40151 };
40152}
40153function getBBox(data) {
40154 const def = -1;
40155 if (!data) {
40156 return {
40157 x: def,
40158 y: def,
40159 width: def,
40160 height: def
40161 };
40162 }
40163 const bbox = data.trim().split(/\s*,\s*/).map(m => getMeasurement(m, "-1"));
40164 if (bbox.length < 4 || bbox[2] < 0 || bbox[3] < 0) {
40165 return {
40166 x: def,
40167 y: def,
40168 width: def,
40169 height: def
40170 };
40171 }
40172 const [x, y, width, height] = bbox;
40173 return {
40174 x,
40175 y,
40176 width,
40177 height
40178 };
40179}
40180class HTMLResult {
40181 static get FAILURE() {
40182 return shadow(this, "FAILURE", new HTMLResult(false, null, null, null));
40183 }
40184 static get EMPTY() {
40185 return shadow(this, "EMPTY", new HTMLResult(true, null, null, null));
40186 }
40187 constructor(success, html, bbox, breakNode) {
40188 this.success = success;
40189 this.html = html;
40190 this.bbox = bbox;
40191 this.breakNode = breakNode;
40192 }
40193 isBreak() {
40194 return !!this.breakNode;
40195 }
40196 static breakNode(node) {
40197 return new HTMLResult(false, null, null, node);
40198 }
40199 static success(html, bbox = null) {
40200 return new HTMLResult(true, html, bbox, null);
40201 }
40202}
40203
40204;// CONCATENATED MODULE: ./src/core/xfa/fonts.js
40205
40206
40207
40208class FontFinder {
40209 constructor(pdfFonts) {
40210 this.fonts = new Map();
40211 this.cache = new Map();
40212 this.warned = new Set();
40213 this.defaultFont = null;
40214 this.add(pdfFonts);
40215 }
40216 add(pdfFonts, reallyMissingFonts = null) {
40217 for (const pdfFont of pdfFonts) {
40218 this.addPdfFont(pdfFont);
40219 }
40220 for (const pdfFont of this.fonts.values()) {
40221 if (!pdfFont.regular) {
40222 pdfFont.regular = pdfFont.italic || pdfFont.bold || pdfFont.bolditalic;
40223 }
40224 }
40225 if (!reallyMissingFonts || reallyMissingFonts.size === 0) {
40226 return;
40227 }
40228 const myriad = this.fonts.get("PdfJS-Fallback-PdfJS-XFA");
40229 for (const missing of reallyMissingFonts) {
40230 this.fonts.set(missing, myriad);
40231 }
40232 }
40233 addPdfFont(pdfFont) {
40234 const cssFontInfo = pdfFont.cssFontInfo;
40235 const name = cssFontInfo.fontFamily;
40236 let font = this.fonts.get(name);
40237 if (!font) {
40238 font = Object.create(null);
40239 this.fonts.set(name, font);
40240 if (!this.defaultFont) {
40241 this.defaultFont = font;
40242 }
40243 }
40244 let property = "";
40245 const fontWeight = parseFloat(cssFontInfo.fontWeight);
40246 if (parseFloat(cssFontInfo.italicAngle) !== 0) {
40247 property = fontWeight >= 700 ? "bolditalic" : "italic";
40248 } else if (fontWeight >= 700) {
40249 property = "bold";
40250 }
40251 if (!property) {
40252 if (pdfFont.name.includes("Bold") || pdfFont.psName?.includes("Bold")) {
40253 property = "bold";
40254 }
40255 if (pdfFont.name.includes("Italic") || pdfFont.name.endsWith("It") || pdfFont.psName?.includes("Italic") || pdfFont.psName?.endsWith("It")) {
40256 property += "italic";
40257 }
40258 }
40259 if (!property) {
40260 property = "regular";
40261 }
40262 font[property] = pdfFont;
40263 }
40264 getDefault() {
40265 return this.defaultFont;
40266 }
40267 find(fontName, mustWarn = true) {
40268 let font = this.fonts.get(fontName) || this.cache.get(fontName);
40269 if (font) {
40270 return font;
40271 }
40272 const pattern = /,|-|_| |bolditalic|bold|italic|regular|it/gi;
40273 let name = fontName.replaceAll(pattern, "");
40274 font = this.fonts.get(name);
40275 if (font) {
40276 this.cache.set(fontName, font);
40277 return font;
40278 }
40279 name = name.toLowerCase();
40280 const maybe = [];
40281 for (const [family, pdfFont] of this.fonts.entries()) {
40282 if (family.replaceAll(pattern, "").toLowerCase().startsWith(name)) {
40283 maybe.push(pdfFont);
40284 }
40285 }
40286 if (maybe.length === 0) {
40287 for (const [, pdfFont] of this.fonts.entries()) {
40288 if (pdfFont.regular.name?.replaceAll(pattern, "").toLowerCase().startsWith(name)) {
40289 maybe.push(pdfFont);
40290 }
40291 }
40292 }
40293 if (maybe.length === 0) {
40294 name = name.replaceAll(/psmt|mt/gi, "");
40295 for (const [family, pdfFont] of this.fonts.entries()) {
40296 if (family.replaceAll(pattern, "").toLowerCase().startsWith(name)) {
40297 maybe.push(pdfFont);
40298 }
40299 }
40300 }
40301 if (maybe.length === 0) {
40302 for (const pdfFont of this.fonts.values()) {
40303 if (pdfFont.regular.name?.replaceAll(pattern, "").toLowerCase().startsWith(name)) {
40304 maybe.push(pdfFont);
40305 }
40306 }
40307 }
40308 if (maybe.length >= 1) {
40309 if (maybe.length !== 1 && mustWarn) {
40310 warn(`XFA - Too many choices to guess the correct font: ${fontName}`);
40311 }
40312 this.cache.set(fontName, maybe[0]);
40313 return maybe[0];
40314 }
40315 if (mustWarn && !this.warned.has(fontName)) {
40316 this.warned.add(fontName);
40317 warn(`XFA - Cannot find the font: ${fontName}`);
40318 }
40319 return null;
40320 }
40321}
40322function selectFont(xfaFont, typeface) {
40323 if (xfaFont.posture === "italic") {
40324 if (xfaFont.weight === "bold") {
40325 return typeface.bolditalic;
40326 }
40327 return typeface.italic;
40328 } else if (xfaFont.weight === "bold") {
40329 return typeface.bold;
40330 }
40331 return typeface.regular;
40332}
40333function fonts_getMetrics(xfaFont, real = false) {
40334 let pdfFont = null;
40335 if (xfaFont) {
40336 const name = stripQuotes(xfaFont.typeface);
40337 const typeface = xfaFont[$globalData].fontFinder.find(name);
40338 pdfFont = selectFont(xfaFont, typeface);
40339 }
40340 if (!pdfFont) {
40341 return {
40342 lineHeight: 12,
40343 lineGap: 2,
40344 lineNoGap: 10
40345 };
40346 }
40347 const size = xfaFont.size || 10;
40348 const lineHeight = pdfFont.lineHeight ? Math.max(real ? 0 : 1.2, pdfFont.lineHeight) : 1.2;
40349 const lineGap = pdfFont.lineGap === undefined ? 0.2 : pdfFont.lineGap;
40350 return {
40351 lineHeight: lineHeight * size,
40352 lineGap: lineGap * size,
40353 lineNoGap: Math.max(1, lineHeight - lineGap) * size
40354 };
40355}
40356
40357;// CONCATENATED MODULE: ./src/core/xfa/text.js
40358
40359const WIDTH_FACTOR = 1.02;
40360class FontInfo {
40361 constructor(xfaFont, margin, lineHeight, fontFinder) {
40362 this.lineHeight = lineHeight;
40363 this.paraMargin = margin || {
40364 top: 0,
40365 bottom: 0,
40366 left: 0,
40367 right: 0
40368 };
40369 if (!xfaFont) {
40370 [this.pdfFont, this.xfaFont] = this.defaultFont(fontFinder);
40371 return;
40372 }
40373 this.xfaFont = {
40374 typeface: xfaFont.typeface,
40375 posture: xfaFont.posture,
40376 weight: xfaFont.weight,
40377 size: xfaFont.size,
40378 letterSpacing: xfaFont.letterSpacing
40379 };
40380 const typeface = fontFinder.find(xfaFont.typeface);
40381 if (!typeface) {
40382 [this.pdfFont, this.xfaFont] = this.defaultFont(fontFinder);
40383 return;
40384 }
40385 this.pdfFont = selectFont(xfaFont, typeface);
40386 if (!this.pdfFont) {
40387 [this.pdfFont, this.xfaFont] = this.defaultFont(fontFinder);
40388 }
40389 }
40390 defaultFont(fontFinder) {
40391 const font = fontFinder.find("Helvetica", false) || fontFinder.find("Myriad Pro", false) || fontFinder.find("Arial", false) || fontFinder.getDefault();
40392 if (font?.regular) {
40393 const pdfFont = font.regular;
40394 const info = pdfFont.cssFontInfo;
40395 const xfaFont = {
40396 typeface: info.fontFamily,
40397 posture: "normal",
40398 weight: "normal",
40399 size: 10,
40400 letterSpacing: 0
40401 };
40402 return [pdfFont, xfaFont];
40403 }
40404 const xfaFont = {
40405 typeface: "Courier",
40406 posture: "normal",
40407 weight: "normal",
40408 size: 10,
40409 letterSpacing: 0
40410 };
40411 return [null, xfaFont];
40412 }
40413}
40414class FontSelector {
40415 constructor(defaultXfaFont, defaultParaMargin, defaultLineHeight, fontFinder) {
40416 this.fontFinder = fontFinder;
40417 this.stack = [new FontInfo(defaultXfaFont, defaultParaMargin, defaultLineHeight, fontFinder)];
40418 }
40419 pushData(xfaFont, margin, lineHeight) {
40420 const lastFont = this.stack.at(-1);
40421 for (const name of ["typeface", "posture", "weight", "size", "letterSpacing"]) {
40422 if (!xfaFont[name]) {
40423 xfaFont[name] = lastFont.xfaFont[name];
40424 }
40425 }
40426 for (const name of ["top", "bottom", "left", "right"]) {
40427 if (isNaN(margin[name])) {
40428 margin[name] = lastFont.paraMargin[name];
40429 }
40430 }
40431 const fontInfo = new FontInfo(xfaFont, margin, lineHeight || lastFont.lineHeight, this.fontFinder);
40432 if (!fontInfo.pdfFont) {
40433 fontInfo.pdfFont = lastFont.pdfFont;
40434 }
40435 this.stack.push(fontInfo);
40436 }
40437 popFont() {
40438 this.stack.pop();
40439 }
40440 topFont() {
40441 return this.stack.at(-1);
40442 }
40443}
40444class TextMeasure {
40445 constructor(defaultXfaFont, defaultParaMargin, defaultLineHeight, fonts) {
40446 this.glyphs = [];
40447 this.fontSelector = new FontSelector(defaultXfaFont, defaultParaMargin, defaultLineHeight, fonts);
40448 this.extraHeight = 0;
40449 }
40450 pushData(xfaFont, margin, lineHeight) {
40451 this.fontSelector.pushData(xfaFont, margin, lineHeight);
40452 }
40453 popFont(xfaFont) {
40454 return this.fontSelector.popFont();
40455 }
40456 addPara() {
40457 const lastFont = this.fontSelector.topFont();
40458 this.extraHeight += lastFont.paraMargin.top + lastFont.paraMargin.bottom;
40459 }
40460 addString(str) {
40461 if (!str) {
40462 return;
40463 }
40464 const lastFont = this.fontSelector.topFont();
40465 const fontSize = lastFont.xfaFont.size;
40466 if (lastFont.pdfFont) {
40467 const letterSpacing = lastFont.xfaFont.letterSpacing;
40468 const pdfFont = lastFont.pdfFont;
40469 const fontLineHeight = pdfFont.lineHeight || 1.2;
40470 const lineHeight = lastFont.lineHeight || Math.max(1.2, fontLineHeight) * fontSize;
40471 const lineGap = pdfFont.lineGap === undefined ? 0.2 : pdfFont.lineGap;
40472 const noGap = fontLineHeight - lineGap;
40473 const firstLineHeight = Math.max(1, noGap) * fontSize;
40474 const scale = fontSize / 1000;
40475 const fallbackWidth = pdfFont.defaultWidth || pdfFont.charsToGlyphs(" ")[0].width;
40476 for (const line of str.split(/[\u2029\n]/)) {
40477 const encodedLine = pdfFont.encodeString(line).join("");
40478 const glyphs = pdfFont.charsToGlyphs(encodedLine);
40479 for (const glyph of glyphs) {
40480 const width = glyph.width || fallbackWidth;
40481 this.glyphs.push([width * scale + letterSpacing, lineHeight, firstLineHeight, glyph.unicode, false]);
40482 }
40483 this.glyphs.push([0, 0, 0, "\n", true]);
40484 }
40485 this.glyphs.pop();
40486 return;
40487 }
40488 for (const line of str.split(/[\u2029\n]/)) {
40489 for (const char of line.split("")) {
40490 this.glyphs.push([fontSize, 1.2 * fontSize, fontSize, char, false]);
40491 }
40492 this.glyphs.push([0, 0, 0, "\n", true]);
40493 }
40494 this.glyphs.pop();
40495 }
40496 compute(maxWidth) {
40497 let lastSpacePos = -1,
40498 lastSpaceWidth = 0,
40499 width = 0,
40500 height = 0,
40501 currentLineWidth = 0,
40502 currentLineHeight = 0;
40503 let isBroken = false;
40504 let isFirstLine = true;
40505 for (let i = 0, ii = this.glyphs.length; i < ii; i++) {
40506 const [glyphWidth, lineHeight, firstLineHeight, char, isEOL] = this.glyphs[i];
40507 const isSpace = char === " ";
40508 const glyphHeight = isFirstLine ? firstLineHeight : lineHeight;
40509 if (isEOL) {
40510 width = Math.max(width, currentLineWidth);
40511 currentLineWidth = 0;
40512 height += currentLineHeight;
40513 currentLineHeight = glyphHeight;
40514 lastSpacePos = -1;
40515 lastSpaceWidth = 0;
40516 isFirstLine = false;
40517 continue;
40518 }
40519 if (isSpace) {
40520 if (currentLineWidth + glyphWidth > maxWidth) {
40521 width = Math.max(width, currentLineWidth);
40522 currentLineWidth = 0;
40523 height += currentLineHeight;
40524 currentLineHeight = glyphHeight;
40525 lastSpacePos = -1;
40526 lastSpaceWidth = 0;
40527 isBroken = true;
40528 isFirstLine = false;
40529 } else {
40530 currentLineHeight = Math.max(glyphHeight, currentLineHeight);
40531 lastSpaceWidth = currentLineWidth;
40532 currentLineWidth += glyphWidth;
40533 lastSpacePos = i;
40534 }
40535 continue;
40536 }
40537 if (currentLineWidth + glyphWidth > maxWidth) {
40538 height += currentLineHeight;
40539 currentLineHeight = glyphHeight;
40540 if (lastSpacePos !== -1) {
40541 i = lastSpacePos;
40542 width = Math.max(width, lastSpaceWidth);
40543 currentLineWidth = 0;
40544 lastSpacePos = -1;
40545 lastSpaceWidth = 0;
40546 } else {
40547 width = Math.max(width, currentLineWidth);
40548 currentLineWidth = glyphWidth;
40549 }
40550 isBroken = true;
40551 isFirstLine = false;
40552 continue;
40553 }
40554 currentLineWidth += glyphWidth;
40555 currentLineHeight = Math.max(glyphHeight, currentLineHeight);
40556 }
40557 width = Math.max(width, currentLineWidth);
40558 height += currentLineHeight + this.extraHeight;
40559 return {
40560 width: WIDTH_FACTOR * width,
40561 height,
40562 isBroken
40563 };
40564 }
40565}
40566
40567;// CONCATENATED MODULE: ./src/core/xfa/som.js
40568
40569
40570const namePattern = /^[^.[]+/;
40571const indexPattern = /^[^\]]+/;
40572const operators = {
40573 dot: 0,
40574 dotDot: 1,
40575 dotHash: 2,
40576 dotBracket: 3,
40577 dotParen: 4
40578};
40579const 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]]);
40580const somCache = new WeakMap();
40581function parseIndex(index) {
40582 index = index.trim();
40583 if (index === "*") {
40584 return Infinity;
40585 }
40586 return parseInt(index, 10) || 0;
40587}
40588function parseExpression(expr, dotDotAllowed, noExpr = true) {
40589 let match = expr.match(namePattern);
40590 if (!match) {
40591 return null;
40592 }
40593 let [name] = match;
40594 const parsed = [{
40595 name,
40596 cacheName: "." + name,
40597 index: 0,
40598 js: null,
40599 formCalc: null,
40600 operator: operators.dot
40601 }];
40602 let pos = name.length;
40603 while (pos < expr.length) {
40604 const spos = pos;
40605 const char = expr.charAt(pos++);
40606 if (char === "[") {
40607 match = expr.slice(pos).match(indexPattern);
40608 if (!match) {
40609 warn("XFA - Invalid index in SOM expression");
40610 return null;
40611 }
40612 parsed.at(-1).index = parseIndex(match[0]);
40613 pos += match[0].length + 1;
40614 continue;
40615 }
40616 let operator;
40617 switch (expr.charAt(pos)) {
40618 case ".":
40619 if (!dotDotAllowed) {
40620 return null;
40621 }
40622 pos++;
40623 operator = operators.dotDot;
40624 break;
40625 case "#":
40626 pos++;
40627 operator = operators.dotHash;
40628 break;
40629 case "[":
40630 if (noExpr) {
40631 warn("XFA - SOM expression contains a FormCalc subexpression which is not supported for now.");
40632 return null;
40633 }
40634 operator = operators.dotBracket;
40635 break;
40636 case "(":
40637 if (noExpr) {
40638 warn("XFA - SOM expression contains a JavaScript subexpression which is not supported for now.");
40639 return null;
40640 }
40641 operator = operators.dotParen;
40642 break;
40643 default:
40644 operator = operators.dot;
40645 break;
40646 }
40647 match = expr.slice(pos).match(namePattern);
40648 if (!match) {
40649 break;
40650 }
40651 [name] = match;
40652 pos += name.length;
40653 parsed.push({
40654 name,
40655 cacheName: expr.slice(spos, pos),
40656 operator,
40657 index: 0,
40658 js: null,
40659 formCalc: null
40660 });
40661 }
40662 return parsed;
40663}
40664function searchNode(root, container, expr, dotDotAllowed = true, useCache = true) {
40665 const parsed = parseExpression(expr, dotDotAllowed);
40666 if (!parsed) {
40667 return null;
40668 }
40669 const fn = shortcuts.get(parsed[0].name);
40670 let i = 0;
40671 let isQualified;
40672 if (fn) {
40673 isQualified = true;
40674 root = [fn(root, container)];
40675 i = 1;
40676 } else {
40677 isQualified = container === null;
40678 root = [container || root];
40679 }
40680 for (let ii = parsed.length; i < ii; i++) {
40681 const {
40682 name,
40683 cacheName,
40684 operator,
40685 index
40686 } = parsed[i];
40687 const nodes = [];
40688 for (const node of root) {
40689 if (!node.isXFAObject) {
40690 continue;
40691 }
40692 let children, cached;
40693 if (useCache) {
40694 cached = somCache.get(node);
40695 if (!cached) {
40696 cached = new Map();
40697 somCache.set(node, cached);
40698 }
40699 children = cached.get(cacheName);
40700 }
40701 if (!children) {
40702 switch (operator) {
40703 case operators.dot:
40704 children = node[$getChildrenByName](name, false);
40705 break;
40706 case operators.dotDot:
40707 children = node[$getChildrenByName](name, true);
40708 break;
40709 case operators.dotHash:
40710 children = node[$getChildrenByClass](name);
40711 children = children.isXFAObjectArray ? children.children : [children];
40712 break;
40713 default:
40714 break;
40715 }
40716 if (useCache) {
40717 cached.set(cacheName, children);
40718 }
40719 }
40720 if (children.length > 0) {
40721 nodes.push(children);
40722 }
40723 }
40724 if (nodes.length === 0 && !isQualified && i === 0) {
40725 const parent = container[$getParent]();
40726 container = parent;
40727 if (!container) {
40728 return null;
40729 }
40730 i = -1;
40731 root = [container];
40732 continue;
40733 }
40734 root = isFinite(index) ? nodes.filter(node => index < node.length).map(node => node[index]) : nodes.flat();
40735 }
40736 if (root.length === 0) {
40737 return null;
40738 }
40739 return root;
40740}
40741function createDataNode(root, container, expr) {
40742 const parsed = parseExpression(expr);
40743 if (!parsed) {
40744 return null;
40745 }
40746 if (parsed.some(x => x.operator === operators.dotDot)) {
40747 return null;
40748 }
40749 const fn = shortcuts.get(parsed[0].name);
40750 let i = 0;
40751 if (fn) {
40752 root = fn(root, container);
40753 i = 1;
40754 } else {
40755 root = container || root;
40756 }
40757 for (let ii = parsed.length; i < ii; i++) {
40758 const {
40759 name,
40760 operator,
40761 index
40762 } = parsed[i];
40763 if (!isFinite(index)) {
40764 parsed[i].index = 0;
40765 return root.createNodes(parsed.slice(i));
40766 }
40767 let children;
40768 switch (operator) {
40769 case operators.dot:
40770 children = root[$getChildrenByName](name, false);
40771 break;
40772 case operators.dotDot:
40773 children = root[$getChildrenByName](name, true);
40774 break;
40775 case operators.dotHash:
40776 children = root[$getChildrenByClass](name);
40777 children = children.isXFAObjectArray ? children.children : [children];
40778 break;
40779 default:
40780 break;
40781 }
40782 if (children.length === 0) {
40783 return root.createNodes(parsed.slice(i));
40784 }
40785 if (index < children.length) {
40786 const child = children[index];
40787 if (!child.isXFAObject) {
40788 warn(`XFA - Cannot create a node.`);
40789 return null;
40790 }
40791 root = child;
40792 } else {
40793 parsed[i].index = index - children.length;
40794 return root.createNodes(parsed.slice(i));
40795 }
40796 }
40797 return null;
40798}
40799
40800;// CONCATENATED MODULE: ./src/core/xfa/xfa_object.js
40801
40802
40803
40804
40805
40806
40807const _applyPrototype = Symbol();
40808const _attributes = Symbol();
40809const _attributeNames = Symbol();
40810const _children = Symbol("_children");
40811const _cloneAttribute = Symbol();
40812const _dataValue = Symbol();
40813const _defaultValue = Symbol();
40814const _filteredChildrenGenerator = Symbol();
40815const _getPrototype = Symbol();
40816const _getUnsetAttributes = Symbol();
40817const _hasChildren = Symbol();
40818const _max = Symbol();
40819const _options = Symbol();
40820const _parent = Symbol("parent");
40821const _resolvePrototypesHelper = Symbol();
40822const _setAttributes = Symbol();
40823const _validator = Symbol();
40824let uid = 0;
40825const NS_DATASETS = NamespaceIds.datasets.id;
40826class XFAObject {
40827 constructor(nsId, name, hasChildren = false) {
40828 this[$namespaceId] = nsId;
40829 this[$nodeName] = name;
40830 this[_hasChildren] = hasChildren;
40831 this[_parent] = null;
40832 this[_children] = [];
40833 this[$uid] = `${name}${uid++}`;
40834 this[$globalData] = null;
40835 }
40836 get isXFAObject() {
40837 return true;
40838 }
40839 get isXFAObjectArray() {
40840 return false;
40841 }
40842 createNodes(path) {
40843 let root = this,
40844 node = null;
40845 for (const {
40846 name,
40847 index
40848 } of path) {
40849 for (let i = 0, ii = isFinite(index) ? index : 0; i <= ii; i++) {
40850 const nsId = root[$namespaceId] === NS_DATASETS ? -1 : root[$namespaceId];
40851 node = new XmlObject(nsId, name);
40852 root[$appendChild](node);
40853 }
40854 root = node;
40855 }
40856 return node;
40857 }
40858 [$onChild](child) {
40859 if (!this[_hasChildren] || !this[$onChildCheck](child)) {
40860 return false;
40861 }
40862 const name = child[$nodeName];
40863 const node = this[name];
40864 if (node instanceof XFAObjectArray) {
40865 if (node.push(child)) {
40866 this[$appendChild](child);
40867 return true;
40868 }
40869 } else {
40870 if (node !== null) {
40871 this[$removeChild](node);
40872 }
40873 this[name] = child;
40874 this[$appendChild](child);
40875 return true;
40876 }
40877 let id = "";
40878 if (this.id) {
40879 id = ` (id: ${this.id})`;
40880 } else if (this.name) {
40881 id = ` (name: ${this.name} ${this.h.value})`;
40882 }
40883 warn(`XFA - node "${this[$nodeName]}"${id} has already enough "${name}"!`);
40884 return false;
40885 }
40886 [$onChildCheck](child) {
40887 return this.hasOwnProperty(child[$nodeName]) && child[$namespaceId] === this[$namespaceId];
40888 }
40889 [$isNsAgnostic]() {
40890 return false;
40891 }
40892 [$acceptWhitespace]() {
40893 return false;
40894 }
40895 [$isCDATAXml]() {
40896 return false;
40897 }
40898 [$isBindable]() {
40899 return false;
40900 }
40901 [$popPara]() {
40902 if (this.para) {
40903 this[$getTemplateRoot]()[$extra].paraStack.pop();
40904 }
40905 }
40906 [$pushPara]() {
40907 this[$getTemplateRoot]()[$extra].paraStack.push(this.para);
40908 }
40909 [$setId](ids) {
40910 if (this.id && this[$namespaceId] === NamespaceIds.template.id) {
40911 ids.set(this.id, this);
40912 }
40913 }
40914 [$getTemplateRoot]() {
40915 return this[$globalData].template;
40916 }
40917 [$isSplittable]() {
40918 return false;
40919 }
40920 [$isThereMoreWidth]() {
40921 return false;
40922 }
40923 [$appendChild](child) {
40924 child[_parent] = this;
40925 this[_children].push(child);
40926 if (!child[$globalData] && this[$globalData]) {
40927 child[$globalData] = this[$globalData];
40928 }
40929 }
40930 [$removeChild](child) {
40931 const i = this[_children].indexOf(child);
40932 this[_children].splice(i, 1);
40933 }
40934 [$hasSettableValue]() {
40935 return this.hasOwnProperty("value");
40936 }
40937 [$setValue](_) {}
40938 [$onText](_) {}
40939 [$finalize]() {}
40940 [$clean](builder) {
40941 delete this[_hasChildren];
40942 if (this[$cleanup]) {
40943 builder.clean(this[$cleanup]);
40944 delete this[$cleanup];
40945 }
40946 }
40947 [$indexOf](child) {
40948 return this[_children].indexOf(child);
40949 }
40950 [$insertAt](i, child) {
40951 child[_parent] = this;
40952 this[_children].splice(i, 0, child);
40953 if (!child[$globalData] && this[$globalData]) {
40954 child[$globalData] = this[$globalData];
40955 }
40956 }
40957 [$isTransparent]() {
40958 return !this.name;
40959 }
40960 [$lastAttribute]() {
40961 return "";
40962 }
40963 [$text]() {
40964 if (this[_children].length === 0) {
40965 return this[$content];
40966 }
40967 return this[_children].map(c => c[$text]()).join("");
40968 }
40969 get [_attributeNames]() {
40970 const proto = Object.getPrototypeOf(this);
40971 if (!proto._attributes) {
40972 const attributes = proto._attributes = new Set();
40973 for (const name of Object.getOwnPropertyNames(this)) {
40974 if (this[name] === null || this[name] instanceof XFAObject || this[name] instanceof XFAObjectArray) {
40975 break;
40976 }
40977 attributes.add(name);
40978 }
40979 }
40980 return shadow(this, _attributeNames, proto._attributes);
40981 }
40982 [$isDescendent](parent) {
40983 let node = this;
40984 while (node) {
40985 if (node === parent) {
40986 return true;
40987 }
40988 node = node[$getParent]();
40989 }
40990 return false;
40991 }
40992 [$getParent]() {
40993 return this[_parent];
40994 }
40995 [$getSubformParent]() {
40996 return this[$getParent]();
40997 }
40998 [$getChildren](name = null) {
40999 if (!name) {
41000 return this[_children];
41001 }
41002 return this[name];
41003 }
41004 [$dump]() {
41005 const dumped = Object.create(null);
41006 if (this[$content]) {
41007 dumped.$content = this[$content];
41008 }
41009 for (const name of Object.getOwnPropertyNames(this)) {
41010 const value = this[name];
41011 if (value === null) {
41012 continue;
41013 }
41014 if (value instanceof XFAObject) {
41015 dumped[name] = value[$dump]();
41016 } else if (value instanceof XFAObjectArray) {
41017 if (!value.isEmpty()) {
41018 dumped[name] = value.dump();
41019 }
41020 } else {
41021 dumped[name] = value;
41022 }
41023 }
41024 return dumped;
41025 }
41026 [$toStyle]() {
41027 return null;
41028 }
41029 [$toHTML]() {
41030 return HTMLResult.EMPTY;
41031 }
41032 *[$getContainedChildren]() {
41033 for (const node of this[$getChildren]()) {
41034 yield node;
41035 }
41036 }
41037 *[_filteredChildrenGenerator](filter, include) {
41038 for (const node of this[$getContainedChildren]()) {
41039 if (!filter || include === filter.has(node[$nodeName])) {
41040 const availableSpace = this[$getAvailableSpace]();
41041 const res = node[$toHTML](availableSpace);
41042 if (!res.success) {
41043 this[$extra].failingNode = node;
41044 }
41045 yield res;
41046 }
41047 }
41048 }
41049 [$flushHTML]() {
41050 return null;
41051 }
41052 [$addHTML](html, bbox) {
41053 this[$extra].children.push(html);
41054 }
41055 [$getAvailableSpace]() {}
41056 [$childrenToHTML]({
41057 filter = null,
41058 include = true
41059 }) {
41060 if (!this[$extra].generator) {
41061 this[$extra].generator = this[_filteredChildrenGenerator](filter, include);
41062 } else {
41063 const availableSpace = this[$getAvailableSpace]();
41064 const res = this[$extra].failingNode[$toHTML](availableSpace);
41065 if (!res.success) {
41066 return res;
41067 }
41068 if (res.html) {
41069 this[$addHTML](res.html, res.bbox);
41070 }
41071 delete this[$extra].failingNode;
41072 }
41073 while (true) {
41074 const gen = this[$extra].generator.next();
41075 if (gen.done) {
41076 break;
41077 }
41078 const res = gen.value;
41079 if (!res.success) {
41080 return res;
41081 }
41082 if (res.html) {
41083 this[$addHTML](res.html, res.bbox);
41084 }
41085 }
41086 this[$extra].generator = null;
41087 return HTMLResult.EMPTY;
41088 }
41089 [$setSetAttributes](attributes) {
41090 this[_setAttributes] = new Set(Object.keys(attributes));
41091 }
41092 [_getUnsetAttributes](protoAttributes) {
41093 const allAttr = this[_attributeNames];
41094 const setAttr = this[_setAttributes];
41095 return [...protoAttributes].filter(x => allAttr.has(x) && !setAttr.has(x));
41096 }
41097 [$resolvePrototypes](ids, ancestors = new Set()) {
41098 for (const child of this[_children]) {
41099 child[_resolvePrototypesHelper](ids, ancestors);
41100 }
41101 }
41102 [_resolvePrototypesHelper](ids, ancestors) {
41103 const proto = this[_getPrototype](ids, ancestors);
41104 if (proto) {
41105 this[_applyPrototype](proto, ids, ancestors);
41106 } else {
41107 this[$resolvePrototypes](ids, ancestors);
41108 }
41109 }
41110 [_getPrototype](ids, ancestors) {
41111 const {
41112 use,
41113 usehref
41114 } = this;
41115 if (!use && !usehref) {
41116 return null;
41117 }
41118 let proto = null;
41119 let somExpression = null;
41120 let id = null;
41121 let ref = use;
41122 if (usehref) {
41123 ref = usehref;
41124 if (usehref.startsWith("#som(") && usehref.endsWith(")")) {
41125 somExpression = usehref.slice("#som(".length, -1);
41126 } else if (usehref.startsWith(".#som(") && usehref.endsWith(")")) {
41127 somExpression = usehref.slice(".#som(".length, -1);
41128 } else if (usehref.startsWith("#")) {
41129 id = usehref.slice(1);
41130 } else if (usehref.startsWith(".#")) {
41131 id = usehref.slice(2);
41132 }
41133 } else if (use.startsWith("#")) {
41134 id = use.slice(1);
41135 } else {
41136 somExpression = use;
41137 }
41138 this.use = this.usehref = "";
41139 if (id) {
41140 proto = ids.get(id);
41141 } else {
41142 proto = searchNode(ids.get($root), this, somExpression, true, false);
41143 if (proto) {
41144 proto = proto[0];
41145 }
41146 }
41147 if (!proto) {
41148 warn(`XFA - Invalid prototype reference: ${ref}.`);
41149 return null;
41150 }
41151 if (proto[$nodeName] !== this[$nodeName]) {
41152 warn(`XFA - Incompatible prototype: ${proto[$nodeName]} !== ${this[$nodeName]}.`);
41153 return null;
41154 }
41155 if (ancestors.has(proto)) {
41156 warn(`XFA - Cycle detected in prototypes use.`);
41157 return null;
41158 }
41159 ancestors.add(proto);
41160 const protoProto = proto[_getPrototype](ids, ancestors);
41161 if (protoProto) {
41162 proto[_applyPrototype](protoProto, ids, ancestors);
41163 }
41164 proto[$resolvePrototypes](ids, ancestors);
41165 ancestors.delete(proto);
41166 return proto;
41167 }
41168 [_applyPrototype](proto, ids, ancestors) {
41169 if (ancestors.has(proto)) {
41170 warn(`XFA - Cycle detected in prototypes use.`);
41171 return;
41172 }
41173 if (!this[$content] && proto[$content]) {
41174 this[$content] = proto[$content];
41175 }
41176 const newAncestors = new Set(ancestors);
41177 newAncestors.add(proto);
41178 for (const unsetAttrName of this[_getUnsetAttributes](proto[_setAttributes])) {
41179 this[unsetAttrName] = proto[unsetAttrName];
41180 if (this[_setAttributes]) {
41181 this[_setAttributes].add(unsetAttrName);
41182 }
41183 }
41184 for (const name of Object.getOwnPropertyNames(this)) {
41185 if (this[_attributeNames].has(name)) {
41186 continue;
41187 }
41188 const value = this[name];
41189 const protoValue = proto[name];
41190 if (value instanceof XFAObjectArray) {
41191 for (const child of value[_children]) {
41192 child[_resolvePrototypesHelper](ids, ancestors);
41193 }
41194 for (let i = value[_children].length, ii = protoValue[_children].length; i < ii; i++) {
41195 const child = proto[_children][i][$clone]();
41196 if (value.push(child)) {
41197 child[_parent] = this;
41198 this[_children].push(child);
41199 child[_resolvePrototypesHelper](ids, ancestors);
41200 } else {
41201 break;
41202 }
41203 }
41204 continue;
41205 }
41206 if (value !== null) {
41207 value[$resolvePrototypes](ids, ancestors);
41208 if (protoValue) {
41209 value[_applyPrototype](protoValue, ids, ancestors);
41210 }
41211 continue;
41212 }
41213 if (protoValue !== null) {
41214 const child = protoValue[$clone]();
41215 child[_parent] = this;
41216 this[name] = child;
41217 this[_children].push(child);
41218 child[_resolvePrototypesHelper](ids, ancestors);
41219 }
41220 }
41221 }
41222 static [_cloneAttribute](obj) {
41223 if (Array.isArray(obj)) {
41224 return obj.map(x => XFAObject[_cloneAttribute](x));
41225 }
41226 if (typeof obj === "object" && obj !== null) {
41227 return Object.assign({}, obj);
41228 }
41229 return obj;
41230 }
41231 [$clone]() {
41232 const clone = Object.create(Object.getPrototypeOf(this));
41233 for (const $symbol of Object.getOwnPropertySymbols(this)) {
41234 try {
41235 clone[$symbol] = this[$symbol];
41236 } catch {
41237 shadow(clone, $symbol, this[$symbol]);
41238 }
41239 }
41240 clone[$uid] = `${clone[$nodeName]}${uid++}`;
41241 clone[_children] = [];
41242 for (const name of Object.getOwnPropertyNames(this)) {
41243 if (this[_attributeNames].has(name)) {
41244 clone[name] = XFAObject[_cloneAttribute](this[name]);
41245 continue;
41246 }
41247 const value = this[name];
41248 clone[name] = value instanceof XFAObjectArray ? new XFAObjectArray(value[_max]) : null;
41249 }
41250 for (const child of this[_children]) {
41251 const name = child[$nodeName];
41252 const clonedChild = child[$clone]();
41253 clone[_children].push(clonedChild);
41254 clonedChild[_parent] = clone;
41255 if (clone[name] === null) {
41256 clone[name] = clonedChild;
41257 } else {
41258 clone[name][_children].push(clonedChild);
41259 }
41260 }
41261 return clone;
41262 }
41263 [$getChildren](name = null) {
41264 if (!name) {
41265 return this[_children];
41266 }
41267 return this[_children].filter(c => c[$nodeName] === name);
41268 }
41269 [$getChildrenByClass](name) {
41270 return this[name];
41271 }
41272 [$getChildrenByName](name, allTransparent, first = true) {
41273 return Array.from(this[$getChildrenByNameIt](name, allTransparent, first));
41274 }
41275 *[$getChildrenByNameIt](name, allTransparent, first = true) {
41276 if (name === "parent") {
41277 yield this[_parent];
41278 return;
41279 }
41280 for (const child of this[_children]) {
41281 if (child[$nodeName] === name) {
41282 yield child;
41283 }
41284 if (child.name === name) {
41285 yield child;
41286 }
41287 if (allTransparent || child[$isTransparent]()) {
41288 yield* child[$getChildrenByNameIt](name, allTransparent, false);
41289 }
41290 }
41291 if (first && this[_attributeNames].has(name)) {
41292 yield new XFAAttribute(this, name, this[name]);
41293 }
41294 }
41295}
41296class XFAObjectArray {
41297 constructor(max = Infinity) {
41298 this[_max] = max;
41299 this[_children] = [];
41300 }
41301 get isXFAObject() {
41302 return false;
41303 }
41304 get isXFAObjectArray() {
41305 return true;
41306 }
41307 push(child) {
41308 const len = this[_children].length;
41309 if (len <= this[_max]) {
41310 this[_children].push(child);
41311 return true;
41312 }
41313 warn(`XFA - node "${child[$nodeName]}" accepts no more than ${this[_max]} children`);
41314 return false;
41315 }
41316 isEmpty() {
41317 return this[_children].length === 0;
41318 }
41319 dump() {
41320 return this[_children].length === 1 ? this[_children][0][$dump]() : this[_children].map(x => x[$dump]());
41321 }
41322 [$clone]() {
41323 const clone = new XFAObjectArray(this[_max]);
41324 clone[_children] = this[_children].map(c => c[$clone]());
41325 return clone;
41326 }
41327 get children() {
41328 return this[_children];
41329 }
41330 clear() {
41331 this[_children].length = 0;
41332 }
41333}
41334class XFAAttribute {
41335 constructor(node, name, value) {
41336 this[_parent] = node;
41337 this[$nodeName] = name;
41338 this[$content] = value;
41339 this[$consumed] = false;
41340 this[$uid] = `attribute${uid++}`;
41341 }
41342 [$getParent]() {
41343 return this[_parent];
41344 }
41345 [$isDataValue]() {
41346 return true;
41347 }
41348 [$getDataValue]() {
41349 return this[$content].trim();
41350 }
41351 [$setValue](value) {
41352 value = value.value || "";
41353 this[$content] = value.toString();
41354 }
41355 [$text]() {
41356 return this[$content];
41357 }
41358 [$isDescendent](parent) {
41359 return this[_parent] === parent || this[_parent][$isDescendent](parent);
41360 }
41361}
41362class XmlObject extends XFAObject {
41363 constructor(nsId, name, attributes = {}) {
41364 super(nsId, name);
41365 this[$content] = "";
41366 this[_dataValue] = null;
41367 if (name !== "#text") {
41368 const map = new Map();
41369 this[_attributes] = map;
41370 for (const [attrName, value] of Object.entries(attributes)) {
41371 map.set(attrName, new XFAAttribute(this, attrName, value));
41372 }
41373 if (attributes.hasOwnProperty($nsAttributes)) {
41374 const dataNode = attributes[$nsAttributes].xfa.dataNode;
41375 if (dataNode !== undefined) {
41376 if (dataNode === "dataGroup") {
41377 this[_dataValue] = false;
41378 } else if (dataNode === "dataValue") {
41379 this[_dataValue] = true;
41380 }
41381 }
41382 }
41383 }
41384 this[$consumed] = false;
41385 }
41386 [$toString](buf) {
41387 const tagName = this[$nodeName];
41388 if (tagName === "#text") {
41389 buf.push(encodeToXmlString(this[$content]));
41390 return;
41391 }
41392 const utf8TagName = utf8StringToString(tagName);
41393 const prefix = this[$namespaceId] === NS_DATASETS ? "xfa:" : "";
41394 buf.push(`<${prefix}${utf8TagName}`);
41395 for (const [name, value] of this[_attributes].entries()) {
41396 const utf8Name = utf8StringToString(name);
41397 buf.push(` ${utf8Name}="${encodeToXmlString(value[$content])}"`);
41398 }
41399 if (this[_dataValue] !== null) {
41400 if (this[_dataValue]) {
41401 buf.push(` xfa:dataNode="dataValue"`);
41402 } else {
41403 buf.push(` xfa:dataNode="dataGroup"`);
41404 }
41405 }
41406 if (!this[$content] && this[_children].length === 0) {
41407 buf.push("/>");
41408 return;
41409 }
41410 buf.push(">");
41411 if (this[$content]) {
41412 if (typeof this[$content] === "string") {
41413 buf.push(encodeToXmlString(this[$content]));
41414 } else {
41415 this[$content][$toString](buf);
41416 }
41417 } else {
41418 for (const child of this[_children]) {
41419 child[$toString](buf);
41420 }
41421 }
41422 buf.push(`</${prefix}${utf8TagName}>`);
41423 }
41424 [$onChild](child) {
41425 if (this[$content]) {
41426 const node = new XmlObject(this[$namespaceId], "#text");
41427 this[$appendChild](node);
41428 node[$content] = this[$content];
41429 this[$content] = "";
41430 }
41431 this[$appendChild](child);
41432 return true;
41433 }
41434 [$onText](str) {
41435 this[$content] += str;
41436 }
41437 [$finalize]() {
41438 if (this[$content] && this[_children].length > 0) {
41439 const node = new XmlObject(this[$namespaceId], "#text");
41440 this[$appendChild](node);
41441 node[$content] = this[$content];
41442 delete this[$content];
41443 }
41444 }
41445 [$toHTML]() {
41446 if (this[$nodeName] === "#text") {
41447 return HTMLResult.success({
41448 name: "#text",
41449 value: this[$content]
41450 });
41451 }
41452 return HTMLResult.EMPTY;
41453 }
41454 [$getChildren](name = null) {
41455 if (!name) {
41456 return this[_children];
41457 }
41458 return this[_children].filter(c => c[$nodeName] === name);
41459 }
41460 [$getAttributes]() {
41461 return this[_attributes];
41462 }
41463 [$getChildrenByClass](name) {
41464 const value = this[_attributes].get(name);
41465 if (value !== undefined) {
41466 return value;
41467 }
41468 return this[$getChildren](name);
41469 }
41470 *[$getChildrenByNameIt](name, allTransparent) {
41471 const value = this[_attributes].get(name);
41472 if (value) {
41473 yield value;
41474 }
41475 for (const child of this[_children]) {
41476 if (child[$nodeName] === name) {
41477 yield child;
41478 }
41479 if (allTransparent) {
41480 yield* child[$getChildrenByNameIt](name, allTransparent);
41481 }
41482 }
41483 }
41484 *[$getAttributeIt](name, skipConsumed) {
41485 const value = this[_attributes].get(name);
41486 if (value && (!skipConsumed || !value[$consumed])) {
41487 yield value;
41488 }
41489 for (const child of this[_children]) {
41490 yield* child[$getAttributeIt](name, skipConsumed);
41491 }
41492 }
41493 *[$getRealChildrenByNameIt](name, allTransparent, skipConsumed) {
41494 for (const child of this[_children]) {
41495 if (child[$nodeName] === name && (!skipConsumed || !child[$consumed])) {
41496 yield child;
41497 }
41498 if (allTransparent) {
41499 yield* child[$getRealChildrenByNameIt](name, allTransparent, skipConsumed);
41500 }
41501 }
41502 }
41503 [$isDataValue]() {
41504 if (this[_dataValue] === null) {
41505 return this[_children].length === 0 || this[_children][0][$namespaceId] === NamespaceIds.xhtml.id;
41506 }
41507 return this[_dataValue];
41508 }
41509 [$getDataValue]() {
41510 if (this[_dataValue] === null) {
41511 if (this[_children].length === 0) {
41512 return this[$content].trim();
41513 }
41514 if (this[_children][0][$namespaceId] === NamespaceIds.xhtml.id) {
41515 return this[_children][0][$text]().trim();
41516 }
41517 return null;
41518 }
41519 return this[$content].trim();
41520 }
41521 [$setValue](value) {
41522 value = value.value || "";
41523 this[$content] = value.toString();
41524 }
41525 [$dump](hasNS = false) {
41526 const dumped = Object.create(null);
41527 if (hasNS) {
41528 dumped.$ns = this[$namespaceId];
41529 }
41530 if (this[$content]) {
41531 dumped.$content = this[$content];
41532 }
41533 dumped.$name = this[$nodeName];
41534 dumped.children = [];
41535 for (const child of this[_children]) {
41536 dumped.children.push(child[$dump](hasNS));
41537 }
41538 dumped.attributes = Object.create(null);
41539 for (const [name, value] of this[_attributes]) {
41540 dumped.attributes[name] = value[$content];
41541 }
41542 return dumped;
41543 }
41544}
41545class ContentObject extends XFAObject {
41546 constructor(nsId, name) {
41547 super(nsId, name);
41548 this[$content] = "";
41549 }
41550 [$onText](text) {
41551 this[$content] += text;
41552 }
41553 [$finalize]() {}
41554}
41555class OptionObject extends ContentObject {
41556 constructor(nsId, name, options) {
41557 super(nsId, name);
41558 this[_options] = options;
41559 }
41560 [$finalize]() {
41561 this[$content] = getKeyword({
41562 data: this[$content],
41563 defaultValue: this[_options][0],
41564 validate: k => this[_options].includes(k)
41565 });
41566 }
41567 [$clean](builder) {
41568 super[$clean](builder);
41569 delete this[_options];
41570 }
41571}
41572class StringObject extends ContentObject {
41573 [$finalize]() {
41574 this[$content] = this[$content].trim();
41575 }
41576}
41577class IntegerObject extends ContentObject {
41578 constructor(nsId, name, defaultValue, validator) {
41579 super(nsId, name);
41580 this[_defaultValue] = defaultValue;
41581 this[_validator] = validator;
41582 }
41583 [$finalize]() {
41584 this[$content] = getInteger({
41585 data: this[$content],
41586 defaultValue: this[_defaultValue],
41587 validate: this[_validator]
41588 });
41589 }
41590 [$clean](builder) {
41591 super[$clean](builder);
41592 delete this[_defaultValue];
41593 delete this[_validator];
41594 }
41595}
41596class Option01 extends IntegerObject {
41597 constructor(nsId, name) {
41598 super(nsId, name, 0, n => n === 1);
41599 }
41600}
41601class Option10 extends IntegerObject {
41602 constructor(nsId, name) {
41603 super(nsId, name, 1, n => n === 0);
41604 }
41605}
41606
41607;// CONCATENATED MODULE: ./src/core/xfa/html_utils.js
41608
41609
41610
41611
41612
41613
41614function measureToString(m) {
41615 if (typeof m === "string") {
41616 return "0px";
41617 }
41618 return Number.isInteger(m) ? `${m}px` : `${m.toFixed(2)}px`;
41619}
41620const converters = {
41621 anchorType(node, style) {
41622 const parent = node[$getSubformParent]();
41623 if (!parent || parent.layout && parent.layout !== "position") {
41624 return;
41625 }
41626 if (!("transform" in style)) {
41627 style.transform = "";
41628 }
41629 switch (node.anchorType) {
41630 case "bottomCenter":
41631 style.transform += "translate(-50%, -100%)";
41632 break;
41633 case "bottomLeft":
41634 style.transform += "translate(0,-100%)";
41635 break;
41636 case "bottomRight":
41637 style.transform += "translate(-100%,-100%)";
41638 break;
41639 case "middleCenter":
41640 style.transform += "translate(-50%,-50%)";
41641 break;
41642 case "middleLeft":
41643 style.transform += "translate(0,-50%)";
41644 break;
41645 case "middleRight":
41646 style.transform += "translate(-100%,-50%)";
41647 break;
41648 case "topCenter":
41649 style.transform += "translate(-50%,0)";
41650 break;
41651 case "topRight":
41652 style.transform += "translate(-100%,0)";
41653 break;
41654 }
41655 },
41656 dimensions(node, style) {
41657 const parent = node[$getSubformParent]();
41658 let width = node.w;
41659 const height = node.h;
41660 if (parent.layout?.includes("row")) {
41661 const extra = parent[$extra];
41662 const colSpan = node.colSpan;
41663 let w;
41664 if (colSpan === -1) {
41665 w = extra.columnWidths.slice(extra.currentColumn).reduce((a, x) => a + x, 0);
41666 extra.currentColumn = 0;
41667 } else {
41668 w = extra.columnWidths.slice(extra.currentColumn, extra.currentColumn + colSpan).reduce((a, x) => a + x, 0);
41669 extra.currentColumn = (extra.currentColumn + node.colSpan) % extra.columnWidths.length;
41670 }
41671 if (!isNaN(w)) {
41672 width = node.w = w;
41673 }
41674 }
41675 style.width = width !== "" ? measureToString(width) : "auto";
41676 style.height = height !== "" ? measureToString(height) : "auto";
41677 },
41678 position(node, style) {
41679 const parent = node[$getSubformParent]();
41680 if (parent?.layout && parent.layout !== "position") {
41681 return;
41682 }
41683 style.position = "absolute";
41684 style.left = measureToString(node.x);
41685 style.top = measureToString(node.y);
41686 },
41687 rotate(node, style) {
41688 if (node.rotate) {
41689 if (!("transform" in style)) {
41690 style.transform = "";
41691 }
41692 style.transform += `rotate(-${node.rotate}deg)`;
41693 style.transformOrigin = "top left";
41694 }
41695 },
41696 presence(node, style) {
41697 switch (node.presence) {
41698 case "invisible":
41699 style.visibility = "hidden";
41700 break;
41701 case "hidden":
41702 case "inactive":
41703 style.display = "none";
41704 break;
41705 }
41706 },
41707 hAlign(node, style) {
41708 if (node[$nodeName] === "para") {
41709 switch (node.hAlign) {
41710 case "justifyAll":
41711 style.textAlign = "justify-all";
41712 break;
41713 case "radix":
41714 style.textAlign = "left";
41715 break;
41716 default:
41717 style.textAlign = node.hAlign;
41718 }
41719 } else {
41720 switch (node.hAlign) {
41721 case "left":
41722 style.alignSelf = "start";
41723 break;
41724 case "center":
41725 style.alignSelf = "center";
41726 break;
41727 case "right":
41728 style.alignSelf = "end";
41729 break;
41730 }
41731 }
41732 },
41733 margin(node, style) {
41734 if (node.margin) {
41735 style.margin = node.margin[$toStyle]().margin;
41736 }
41737 }
41738};
41739function setMinMaxDimensions(node, style) {
41740 const parent = node[$getSubformParent]();
41741 if (parent.layout === "position") {
41742 if (node.minW > 0) {
41743 style.minWidth = measureToString(node.minW);
41744 }
41745 if (node.maxW > 0) {
41746 style.maxWidth = measureToString(node.maxW);
41747 }
41748 if (node.minH > 0) {
41749 style.minHeight = measureToString(node.minH);
41750 }
41751 if (node.maxH > 0) {
41752 style.maxHeight = measureToString(node.maxH);
41753 }
41754 }
41755}
41756function layoutText(text, xfaFont, margin, lineHeight, fontFinder, width) {
41757 const measure = new TextMeasure(xfaFont, margin, lineHeight, fontFinder);
41758 if (typeof text === "string") {
41759 measure.addString(text);
41760 } else {
41761 text[$pushGlyphs](measure);
41762 }
41763 return measure.compute(width);
41764}
41765function layoutNode(node, availableSpace) {
41766 let height = null;
41767 let width = null;
41768 let isBroken = false;
41769 if ((!node.w || !node.h) && node.value) {
41770 let marginH = 0;
41771 let marginV = 0;
41772 if (node.margin) {
41773 marginH = node.margin.leftInset + node.margin.rightInset;
41774 marginV = node.margin.topInset + node.margin.bottomInset;
41775 }
41776 let lineHeight = null;
41777 let margin = null;
41778 if (node.para) {
41779 margin = Object.create(null);
41780 lineHeight = node.para.lineHeight === "" ? null : node.para.lineHeight;
41781 margin.top = node.para.spaceAbove === "" ? 0 : node.para.spaceAbove;
41782 margin.bottom = node.para.spaceBelow === "" ? 0 : node.para.spaceBelow;
41783 margin.left = node.para.marginLeft === "" ? 0 : node.para.marginLeft;
41784 margin.right = node.para.marginRight === "" ? 0 : node.para.marginRight;
41785 }
41786 let font = node.font;
41787 if (!font) {
41788 const root = node[$getTemplateRoot]();
41789 let parent = node[$getParent]();
41790 while (parent && parent !== root) {
41791 if (parent.font) {
41792 font = parent.font;
41793 break;
41794 }
41795 parent = parent[$getParent]();
41796 }
41797 }
41798 const maxWidth = (node.w || availableSpace.width) - marginH;
41799 const fontFinder = node[$globalData].fontFinder;
41800 if (node.value.exData && node.value.exData[$content] && node.value.exData.contentType === "text/html") {
41801 const res = layoutText(node.value.exData[$content], font, margin, lineHeight, fontFinder, maxWidth);
41802 width = res.width;
41803 height = res.height;
41804 isBroken = res.isBroken;
41805 } else {
41806 const text = node.value[$text]();
41807 if (text) {
41808 const res = layoutText(text, font, margin, lineHeight, fontFinder, maxWidth);
41809 width = res.width;
41810 height = res.height;
41811 isBroken = res.isBroken;
41812 }
41813 }
41814 if (width !== null && !node.w) {
41815 width += marginH;
41816 }
41817 if (height !== null && !node.h) {
41818 height += marginV;
41819 }
41820 }
41821 return {
41822 w: width,
41823 h: height,
41824 isBroken
41825 };
41826}
41827function computeBbox(node, html, availableSpace) {
41828 let bbox;
41829 if (node.w !== "" && node.h !== "") {
41830 bbox = [node.x, node.y, node.w, node.h];
41831 } else {
41832 if (!availableSpace) {
41833 return null;
41834 }
41835 let width = node.w;
41836 if (width === "") {
41837 if (node.maxW === 0) {
41838 const parent = node[$getSubformParent]();
41839 width = parent.layout === "position" && parent.w !== "" ? 0 : node.minW;
41840 } else {
41841 width = Math.min(node.maxW, availableSpace.width);
41842 }
41843 html.attributes.style.width = measureToString(width);
41844 }
41845 let height = node.h;
41846 if (height === "") {
41847 if (node.maxH === 0) {
41848 const parent = node[$getSubformParent]();
41849 height = parent.layout === "position" && parent.h !== "" ? 0 : node.minH;
41850 } else {
41851 height = Math.min(node.maxH, availableSpace.height);
41852 }
41853 html.attributes.style.height = measureToString(height);
41854 }
41855 bbox = [node.x, node.y, width, height];
41856 }
41857 return bbox;
41858}
41859function fixDimensions(node) {
41860 const parent = node[$getSubformParent]();
41861 if (parent.layout?.includes("row")) {
41862 const extra = parent[$extra];
41863 const colSpan = node.colSpan;
41864 let width;
41865 if (colSpan === -1) {
41866 width = extra.columnWidths.slice(extra.currentColumn).reduce((a, w) => a + w, 0);
41867 } else {
41868 width = extra.columnWidths.slice(extra.currentColumn, extra.currentColumn + colSpan).reduce((a, w) => a + w, 0);
41869 }
41870 if (!isNaN(width)) {
41871 node.w = width;
41872 }
41873 }
41874 if (parent.layout && parent.layout !== "position") {
41875 node.x = node.y = 0;
41876 }
41877 if (node.layout === "table") {
41878 if (node.w === "" && Array.isArray(node.columnWidths)) {
41879 node.w = node.columnWidths.reduce((a, x) => a + x, 0);
41880 }
41881 }
41882}
41883function layoutClass(node) {
41884 switch (node.layout) {
41885 case "position":
41886 return "xfaPosition";
41887 case "lr-tb":
41888 return "xfaLrTb";
41889 case "rl-row":
41890 return "xfaRlRow";
41891 case "rl-tb":
41892 return "xfaRlTb";
41893 case "row":
41894 return "xfaRow";
41895 case "table":
41896 return "xfaTable";
41897 case "tb":
41898 return "xfaTb";
41899 default:
41900 return "xfaPosition";
41901 }
41902}
41903function toStyle(node, ...names) {
41904 const style = Object.create(null);
41905 for (const name of names) {
41906 const value = node[name];
41907 if (value === null) {
41908 continue;
41909 }
41910 if (converters.hasOwnProperty(name)) {
41911 converters[name](node, style);
41912 continue;
41913 }
41914 if (value instanceof XFAObject) {
41915 const newStyle = value[$toStyle]();
41916 if (newStyle) {
41917 Object.assign(style, newStyle);
41918 } else {
41919 warn(`(DEBUG) - XFA - style for ${name} not implemented yet`);
41920 }
41921 }
41922 }
41923 return style;
41924}
41925function createWrapper(node, html) {
41926 const {
41927 attributes
41928 } = html;
41929 const {
41930 style
41931 } = attributes;
41932 const wrapper = {
41933 name: "div",
41934 attributes: {
41935 class: ["xfaWrapper"],
41936 style: Object.create(null)
41937 },
41938 children: []
41939 };
41940 attributes.class.push("xfaWrapped");
41941 if (node.border) {
41942 const {
41943 widths,
41944 insets
41945 } = node.border[$extra];
41946 let width, height;
41947 let top = insets[0];
41948 let left = insets[3];
41949 const insetsH = insets[0] + insets[2];
41950 const insetsW = insets[1] + insets[3];
41951 switch (node.border.hand) {
41952 case "even":
41953 top -= widths[0] / 2;
41954 left -= widths[3] / 2;
41955 width = `calc(100% + ${(widths[1] + widths[3]) / 2 - insetsW}px)`;
41956 height = `calc(100% + ${(widths[0] + widths[2]) / 2 - insetsH}px)`;
41957 break;
41958 case "left":
41959 top -= widths[0];
41960 left -= widths[3];
41961 width = `calc(100% + ${widths[1] + widths[3] - insetsW}px)`;
41962 height = `calc(100% + ${widths[0] + widths[2] - insetsH}px)`;
41963 break;
41964 case "right":
41965 width = insetsW ? `calc(100% - ${insetsW}px)` : "100%";
41966 height = insetsH ? `calc(100% - ${insetsH}px)` : "100%";
41967 break;
41968 }
41969 const classNames = ["xfaBorder"];
41970 if (isPrintOnly(node.border)) {
41971 classNames.push("xfaPrintOnly");
41972 }
41973 const border = {
41974 name: "div",
41975 attributes: {
41976 class: classNames,
41977 style: {
41978 top: `${top}px`,
41979 left: `${left}px`,
41980 width,
41981 height
41982 }
41983 },
41984 children: []
41985 };
41986 for (const key of ["border", "borderWidth", "borderColor", "borderRadius", "borderStyle"]) {
41987 if (style[key] !== undefined) {
41988 border.attributes.style[key] = style[key];
41989 delete style[key];
41990 }
41991 }
41992 wrapper.children.push(border, html);
41993 } else {
41994 wrapper.children.push(html);
41995 }
41996 for (const key of ["background", "backgroundClip", "top", "left", "width", "height", "minWidth", "minHeight", "maxWidth", "maxHeight", "transform", "transformOrigin", "visibility"]) {
41997 if (style[key] !== undefined) {
41998 wrapper.attributes.style[key] = style[key];
41999 delete style[key];
42000 }
42001 }
42002 wrapper.attributes.style.position = style.position === "absolute" ? "absolute" : "relative";
42003 delete style.position;
42004 if (style.alignSelf) {
42005 wrapper.attributes.style.alignSelf = style.alignSelf;
42006 delete style.alignSelf;
42007 }
42008 return wrapper;
42009}
42010function fixTextIndent(styles) {
42011 const indent = getMeasurement(styles.textIndent, "0px");
42012 if (indent >= 0) {
42013 return;
42014 }
42015 const align = styles.textAlign === "right" ? "right" : "left";
42016 const name = "padding" + (align === "left" ? "Left" : "Right");
42017 const padding = getMeasurement(styles[name], "0px");
42018 styles[name] = `${padding - indent}px`;
42019}
42020function setAccess(node, classNames) {
42021 switch (node.access) {
42022 case "nonInteractive":
42023 classNames.push("xfaNonInteractive");
42024 break;
42025 case "readOnly":
42026 classNames.push("xfaReadOnly");
42027 break;
42028 case "protected":
42029 classNames.push("xfaDisabled");
42030 break;
42031 }
42032}
42033function isPrintOnly(node) {
42034 return node.relevant.length > 0 && !node.relevant[0].excluded && node.relevant[0].viewname === "print";
42035}
42036function getCurrentPara(node) {
42037 const stack = node[$getTemplateRoot]()[$extra].paraStack;
42038 return stack.length ? stack.at(-1) : null;
42039}
42040function setPara(node, nodeStyle, value) {
42041 if (value.attributes.class?.includes("xfaRich")) {
42042 if (nodeStyle) {
42043 if (node.h === "") {
42044 nodeStyle.height = "auto";
42045 }
42046 if (node.w === "") {
42047 nodeStyle.width = "auto";
42048 }
42049 }
42050 const para = getCurrentPara(node);
42051 if (para) {
42052 const valueStyle = value.attributes.style;
42053 valueStyle.display = "flex";
42054 valueStyle.flexDirection = "column";
42055 switch (para.vAlign) {
42056 case "top":
42057 valueStyle.justifyContent = "start";
42058 break;
42059 case "bottom":
42060 valueStyle.justifyContent = "end";
42061 break;
42062 case "middle":
42063 valueStyle.justifyContent = "center";
42064 break;
42065 }
42066 const paraStyle = para[$toStyle]();
42067 for (const [key, val] of Object.entries(paraStyle)) {
42068 if (!(key in valueStyle)) {
42069 valueStyle[key] = val;
42070 }
42071 }
42072 }
42073 }
42074}
42075function setFontFamily(xfaFont, node, fontFinder, style) {
42076 if (!fontFinder) {
42077 delete style.fontFamily;
42078 return;
42079 }
42080 const name = stripQuotes(xfaFont.typeface);
42081 style.fontFamily = `"${name}"`;
42082 const typeface = fontFinder.find(name);
42083 if (typeface) {
42084 const {
42085 fontFamily
42086 } = typeface.regular.cssFontInfo;
42087 if (fontFamily !== name) {
42088 style.fontFamily = `"${fontFamily}"`;
42089 }
42090 const para = getCurrentPara(node);
42091 if (para && para.lineHeight !== "") {
42092 return;
42093 }
42094 if (style.lineHeight) {
42095 return;
42096 }
42097 const pdfFont = selectFont(xfaFont, typeface);
42098 if (pdfFont) {
42099 style.lineHeight = Math.max(1.2, pdfFont.lineHeight);
42100 }
42101 }
42102}
42103function fixURL(str) {
42104 const absoluteUrl = createValidAbsoluteUrl(str, null, {
42105 addDefaultProtocol: true,
42106 tryConvertEncoding: true
42107 });
42108 return absoluteUrl ? absoluteUrl.href : null;
42109}
42110
42111;// CONCATENATED MODULE: ./src/core/xfa/layout.js
42112
42113
42114function createLine(node, children) {
42115 return {
42116 name: "div",
42117 attributes: {
42118 class: [node.layout === "lr-tb" ? "xfaLr" : "xfaRl"]
42119 },
42120 children
42121 };
42122}
42123function flushHTML(node) {
42124 if (!node[$extra]) {
42125 return null;
42126 }
42127 const attributes = node[$extra].attributes;
42128 const html = {
42129 name: "div",
42130 attributes,
42131 children: node[$extra].children
42132 };
42133 if (node[$extra].failingNode) {
42134 const htmlFromFailing = node[$extra].failingNode[$flushHTML]();
42135 if (htmlFromFailing) {
42136 if (node.layout.endsWith("-tb")) {
42137 html.children.push(createLine(node, [htmlFromFailing]));
42138 } else {
42139 html.children.push(htmlFromFailing);
42140 }
42141 }
42142 }
42143 if (html.children.length === 0) {
42144 return null;
42145 }
42146 return html;
42147}
42148function addHTML(node, html, bbox) {
42149 const extra = node[$extra];
42150 const availableSpace = extra.availableSpace;
42151 const [x, y, w, h] = bbox;
42152 switch (node.layout) {
42153 case "position":
42154 {
42155 extra.width = Math.max(extra.width, x + w);
42156 extra.height = Math.max(extra.height, y + h);
42157 extra.children.push(html);
42158 break;
42159 }
42160 case "lr-tb":
42161 case "rl-tb":
42162 if (!extra.line || extra.attempt === 1) {
42163 extra.line = createLine(node, []);
42164 extra.children.push(extra.line);
42165 extra.numberInLine = 0;
42166 }
42167 extra.numberInLine += 1;
42168 extra.line.children.push(html);
42169 if (extra.attempt === 0) {
42170 extra.currentWidth += w;
42171 extra.height = Math.max(extra.height, extra.prevHeight + h);
42172 } else {
42173 extra.currentWidth = w;
42174 extra.prevHeight = extra.height;
42175 extra.height += h;
42176 extra.attempt = 0;
42177 }
42178 extra.width = Math.max(extra.width, extra.currentWidth);
42179 break;
42180 case "rl-row":
42181 case "row":
42182 {
42183 extra.children.push(html);
42184 extra.width += w;
42185 extra.height = Math.max(extra.height, h);
42186 const height = measureToString(extra.height);
42187 for (const child of extra.children) {
42188 child.attributes.style.height = height;
42189 }
42190 break;
42191 }
42192 case "table":
42193 {
42194 extra.width = Math.min(availableSpace.width, Math.max(extra.width, w));
42195 extra.height += h;
42196 extra.children.push(html);
42197 break;
42198 }
42199 case "tb":
42200 {
42201 extra.width = Math.min(availableSpace.width, Math.max(extra.width, w));
42202 extra.height += h;
42203 extra.children.push(html);
42204 break;
42205 }
42206 }
42207}
42208function getAvailableSpace(node) {
42209 const availableSpace = node[$extra].availableSpace;
42210 const marginV = node.margin ? node.margin.topInset + node.margin.bottomInset : 0;
42211 const marginH = node.margin ? node.margin.leftInset + node.margin.rightInset : 0;
42212 switch (node.layout) {
42213 case "lr-tb":
42214 case "rl-tb":
42215 if (node[$extra].attempt === 0) {
42216 return {
42217 width: availableSpace.width - marginH - node[$extra].currentWidth,
42218 height: availableSpace.height - marginV - node[$extra].prevHeight
42219 };
42220 }
42221 return {
42222 width: availableSpace.width - marginH,
42223 height: availableSpace.height - marginV - node[$extra].height
42224 };
42225 case "rl-row":
42226 case "row":
42227 const width = node[$extra].columnWidths.slice(node[$extra].currentColumn).reduce((a, x) => a + x);
42228 return {
42229 width,
42230 height: availableSpace.height - marginH
42231 };
42232 case "table":
42233 case "tb":
42234 return {
42235 width: availableSpace.width - marginH,
42236 height: availableSpace.height - marginV - node[$extra].height
42237 };
42238 case "position":
42239 default:
42240 return availableSpace;
42241 }
42242}
42243function getTransformedBBox(node) {
42244 let w = node.w === "" ? NaN : node.w;
42245 let h = node.h === "" ? NaN : node.h;
42246 let [centerX, centerY] = [0, 0];
42247 switch (node.anchorType || "") {
42248 case "bottomCenter":
42249 [centerX, centerY] = [w / 2, h];
42250 break;
42251 case "bottomLeft":
42252 [centerX, centerY] = [0, h];
42253 break;
42254 case "bottomRight":
42255 [centerX, centerY] = [w, h];
42256 break;
42257 case "middleCenter":
42258 [centerX, centerY] = [w / 2, h / 2];
42259 break;
42260 case "middleLeft":
42261 [centerX, centerY] = [0, h / 2];
42262 break;
42263 case "middleRight":
42264 [centerX, centerY] = [w, h / 2];
42265 break;
42266 case "topCenter":
42267 [centerX, centerY] = [w / 2, 0];
42268 break;
42269 case "topRight":
42270 [centerX, centerY] = [w, 0];
42271 break;
42272 }
42273 let x, y;
42274 switch (node.rotate || 0) {
42275 case 0:
42276 [x, y] = [-centerX, -centerY];
42277 break;
42278 case 90:
42279 [x, y] = [-centerY, centerX];
42280 [w, h] = [h, -w];
42281 break;
42282 case 180:
42283 [x, y] = [centerX, centerY];
42284 [w, h] = [-w, -h];
42285 break;
42286 case 270:
42287 [x, y] = [centerY, -centerX];
42288 [w, h] = [-h, w];
42289 break;
42290 }
42291 return [node.x + x + Math.min(0, w), node.y + y + Math.min(0, h), Math.abs(w), Math.abs(h)];
42292}
42293function checkDimensions(node, space) {
42294 if (node[$getTemplateRoot]()[$extra].firstUnsplittable === null) {
42295 return true;
42296 }
42297 if (node.w === 0 || node.h === 0) {
42298 return true;
42299 }
42300 const ERROR = 2;
42301 const parent = node[$getSubformParent]();
42302 const attempt = parent[$extra]?.attempt || 0;
42303 const [, y, w, h] = getTransformedBBox(node);
42304 switch (parent.layout) {
42305 case "lr-tb":
42306 case "rl-tb":
42307 if (attempt === 0) {
42308 if (!node[$getTemplateRoot]()[$extra].noLayoutFailure) {
42309 if (node.h !== "" && Math.round(h - space.height) > ERROR) {
42310 return false;
42311 }
42312 if (node.w !== "") {
42313 if (Math.round(w - space.width) <= ERROR) {
42314 return true;
42315 }
42316 if (parent[$extra].numberInLine === 0) {
42317 return space.height > ERROR;
42318 }
42319 return false;
42320 }
42321 return space.width > ERROR;
42322 }
42323 if (node.w !== "") {
42324 return Math.round(w - space.width) <= ERROR;
42325 }
42326 return space.width > ERROR;
42327 }
42328 if (node[$getTemplateRoot]()[$extra].noLayoutFailure) {
42329 return true;
42330 }
42331 if (node.h !== "" && Math.round(h - space.height) > ERROR) {
42332 return false;
42333 }
42334 if (node.w === "" || Math.round(w - space.width) <= ERROR) {
42335 return space.height > ERROR;
42336 }
42337 if (parent[$isThereMoreWidth]()) {
42338 return false;
42339 }
42340 return space.height > ERROR;
42341 case "table":
42342 case "tb":
42343 if (node[$getTemplateRoot]()[$extra].noLayoutFailure) {
42344 return true;
42345 }
42346 if (node.h !== "" && !node[$isSplittable]()) {
42347 return Math.round(h - space.height) <= ERROR;
42348 }
42349 if (node.w === "" || Math.round(w - space.width) <= ERROR) {
42350 return space.height > ERROR;
42351 }
42352 if (parent[$isThereMoreWidth]()) {
42353 return false;
42354 }
42355 return space.height > ERROR;
42356 case "position":
42357 if (node[$getTemplateRoot]()[$extra].noLayoutFailure) {
42358 return true;
42359 }
42360 if (node.h === "" || Math.round(h + y - space.height) <= ERROR) {
42361 return true;
42362 }
42363 const area = node[$getTemplateRoot]()[$extra].currentContentArea;
42364 return h + y > area.h;
42365 case "rl-row":
42366 case "row":
42367 if (node[$getTemplateRoot]()[$extra].noLayoutFailure) {
42368 return true;
42369 }
42370 if (node.h !== "") {
42371 return Math.round(h - space.height) <= ERROR;
42372 }
42373 return true;
42374 default:
42375 return true;
42376 }
42377}
42378
42379;// CONCATENATED MODULE: ./src/core/xfa/template.js
42380
42381
42382
42383
42384
42385
42386
42387
42388
42389
42390const TEMPLATE_NS_ID = NamespaceIds.template.id;
42391const SVG_NS = "http://www.w3.org/2000/svg";
42392const MAX_ATTEMPTS_FOR_LRTB_LAYOUT = 2;
42393const MAX_EMPTY_PAGES = 3;
42394const DEFAULT_TAB_INDEX = 5000;
42395const HEADING_PATTERN = /^H(\d+)$/;
42396const 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"]);
42397const 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"]];
42398function getBorderDims(node) {
42399 if (!node || !node.border) {
42400 return {
42401 w: 0,
42402 h: 0
42403 };
42404 }
42405 const borderExtra = node.border[$getExtra]();
42406 if (!borderExtra) {
42407 return {
42408 w: 0,
42409 h: 0
42410 };
42411 }
42412 return {
42413 w: borderExtra.widths[0] + borderExtra.widths[2] + borderExtra.insets[0] + borderExtra.insets[2],
42414 h: borderExtra.widths[1] + borderExtra.widths[3] + borderExtra.insets[1] + borderExtra.insets[3]
42415 };
42416}
42417function hasMargin(node) {
42418 return node.margin && (node.margin.topInset || node.margin.rightInset || node.margin.bottomInset || node.margin.leftInset);
42419}
42420function _setValue(templateNode, value) {
42421 if (!templateNode.value) {
42422 const nodeValue = new Value({});
42423 templateNode[$appendChild](nodeValue);
42424 templateNode.value = nodeValue;
42425 }
42426 templateNode.value[$setValue](value);
42427}
42428function* getContainedChildren(node) {
42429 for (const child of node[$getChildren]()) {
42430 if (child instanceof SubformSet) {
42431 yield* child[$getContainedChildren]();
42432 continue;
42433 }
42434 yield child;
42435 }
42436}
42437function isRequired(node) {
42438 return node.validate?.nullTest === "error";
42439}
42440function setTabIndex(node) {
42441 while (node) {
42442 if (!node.traversal) {
42443 node[$tabIndex] = node[$getParent]()[$tabIndex];
42444 return;
42445 }
42446 if (node[$tabIndex]) {
42447 return;
42448 }
42449 let next = null;
42450 for (const child of node.traversal[$getChildren]()) {
42451 if (child.operation === "next") {
42452 next = child;
42453 break;
42454 }
42455 }
42456 if (!next || !next.ref) {
42457 node[$tabIndex] = node[$getParent]()[$tabIndex];
42458 return;
42459 }
42460 const root = node[$getTemplateRoot]();
42461 node[$tabIndex] = ++root[$tabIndex];
42462 const ref = root[$searchNode](next.ref, node);
42463 if (!ref) {
42464 return;
42465 }
42466 node = ref[0];
42467 }
42468}
42469function applyAssist(obj, attributes) {
42470 const assist = obj.assist;
42471 if (assist) {
42472 const assistTitle = assist[$toHTML]();
42473 if (assistTitle) {
42474 attributes.title = assistTitle;
42475 }
42476 const role = assist.role;
42477 const match = role.match(HEADING_PATTERN);
42478 if (match) {
42479 const ariaRole = "heading";
42480 const ariaLevel = match[1];
42481 attributes.role = ariaRole;
42482 attributes["aria-level"] = ariaLevel;
42483 }
42484 }
42485 if (obj.layout === "table") {
42486 attributes.role = "table";
42487 } else if (obj.layout === "row") {
42488 attributes.role = "row";
42489 } else {
42490 const parent = obj[$getParent]();
42491 if (parent.layout === "row") {
42492 attributes.role = parent.assist?.role === "TH" ? "columnheader" : "cell";
42493 }
42494 }
42495}
42496function ariaLabel(obj) {
42497 if (!obj.assist) {
42498 return null;
42499 }
42500 const assist = obj.assist;
42501 if (assist.speak && assist.speak[$content] !== "") {
42502 return assist.speak[$content];
42503 }
42504 if (assist.toolTip) {
42505 return assist.toolTip[$content];
42506 }
42507 return null;
42508}
42509function valueToHtml(value) {
42510 return HTMLResult.success({
42511 name: "div",
42512 attributes: {
42513 class: ["xfaRich"],
42514 style: Object.create(null)
42515 },
42516 children: [{
42517 name: "span",
42518 attributes: {
42519 style: Object.create(null)
42520 },
42521 value
42522 }]
42523 });
42524}
42525function setFirstUnsplittable(node) {
42526 const root = node[$getTemplateRoot]();
42527 if (root[$extra].firstUnsplittable === null) {
42528 root[$extra].firstUnsplittable = node;
42529 root[$extra].noLayoutFailure = true;
42530 }
42531}
42532function unsetFirstUnsplittable(node) {
42533 const root = node[$getTemplateRoot]();
42534 if (root[$extra].firstUnsplittable === node) {
42535 root[$extra].noLayoutFailure = false;
42536 }
42537}
42538function handleBreak(node) {
42539 if (node[$extra]) {
42540 return false;
42541 }
42542 node[$extra] = Object.create(null);
42543 if (node.targetType === "auto") {
42544 return false;
42545 }
42546 const root = node[$getTemplateRoot]();
42547 let target = null;
42548 if (node.target) {
42549 target = root[$searchNode](node.target, node[$getParent]());
42550 if (!target) {
42551 return false;
42552 }
42553 target = target[0];
42554 }
42555 const {
42556 currentPageArea,
42557 currentContentArea
42558 } = root[$extra];
42559 if (node.targetType === "pageArea") {
42560 if (!(target instanceof PageArea)) {
42561 target = null;
42562 }
42563 if (node.startNew) {
42564 node[$extra].target = target || currentPageArea;
42565 return true;
42566 } else if (target && target !== currentPageArea) {
42567 node[$extra].target = target;
42568 return true;
42569 }
42570 return false;
42571 }
42572 if (!(target instanceof ContentArea)) {
42573 target = null;
42574 }
42575 const pageArea = target && target[$getParent]();
42576 let index;
42577 let nextPageArea = pageArea;
42578 if (node.startNew) {
42579 if (target) {
42580 const contentAreas = pageArea.contentArea.children;
42581 const indexForCurrent = contentAreas.indexOf(currentContentArea);
42582 const indexForTarget = contentAreas.indexOf(target);
42583 if (indexForCurrent !== -1 && indexForCurrent < indexForTarget) {
42584 nextPageArea = null;
42585 }
42586 index = indexForTarget - 1;
42587 } else {
42588 index = currentPageArea.contentArea.children.indexOf(currentContentArea);
42589 }
42590 } else if (target && target !== currentContentArea) {
42591 const contentAreas = pageArea.contentArea.children;
42592 index = contentAreas.indexOf(target) - 1;
42593 nextPageArea = pageArea === currentPageArea ? null : pageArea;
42594 } else {
42595 return false;
42596 }
42597 node[$extra].target = nextPageArea;
42598 node[$extra].index = index;
42599 return true;
42600}
42601function handleOverflow(node, extraNode, space) {
42602 const root = node[$getTemplateRoot]();
42603 const saved = root[$extra].noLayoutFailure;
42604 const savedMethod = extraNode[$getSubformParent];
42605 extraNode[$getSubformParent] = () => node;
42606 root[$extra].noLayoutFailure = true;
42607 const res = extraNode[$toHTML](space);
42608 node[$addHTML](res.html, res.bbox);
42609 root[$extra].noLayoutFailure = saved;
42610 extraNode[$getSubformParent] = savedMethod;
42611}
42612class AppearanceFilter extends StringObject {
42613 constructor(attributes) {
42614 super(TEMPLATE_NS_ID, "appearanceFilter");
42615 this.id = attributes.id || "";
42616 this.type = getStringOption(attributes.type, ["optional", "required"]);
42617 this.use = attributes.use || "";
42618 this.usehref = attributes.usehref || "";
42619 }
42620}
42621class Arc extends XFAObject {
42622 constructor(attributes) {
42623 super(TEMPLATE_NS_ID, "arc", true);
42624 this.circular = getInteger({
42625 data: attributes.circular,
42626 defaultValue: 0,
42627 validate: x => x === 1
42628 });
42629 this.hand = getStringOption(attributes.hand, ["even", "left", "right"]);
42630 this.id = attributes.id || "";
42631 this.startAngle = getFloat({
42632 data: attributes.startAngle,
42633 defaultValue: 0,
42634 validate: x => true
42635 });
42636 this.sweepAngle = getFloat({
42637 data: attributes.sweepAngle,
42638 defaultValue: 360,
42639 validate: x => true
42640 });
42641 this.use = attributes.use || "";
42642 this.usehref = attributes.usehref || "";
42643 this.edge = null;
42644 this.fill = null;
42645 }
42646 [$toHTML]() {
42647 const edge = this.edge || new Edge({});
42648 const edgeStyle = edge[$toStyle]();
42649 const style = Object.create(null);
42650 if (this.fill?.presence === "visible") {
42651 Object.assign(style, this.fill[$toStyle]());
42652 } else {
42653 style.fill = "transparent";
42654 }
42655 style.strokeWidth = measureToString(edge.presence === "visible" ? edge.thickness : 0);
42656 style.stroke = edgeStyle.color;
42657 let arc;
42658 const attributes = {
42659 xmlns: SVG_NS,
42660 style: {
42661 width: "100%",
42662 height: "100%",
42663 overflow: "visible"
42664 }
42665 };
42666 if (this.sweepAngle === 360) {
42667 arc = {
42668 name: "ellipse",
42669 attributes: {
42670 xmlns: SVG_NS,
42671 cx: "50%",
42672 cy: "50%",
42673 rx: "50%",
42674 ry: "50%",
42675 style
42676 }
42677 };
42678 } else {
42679 const startAngle = this.startAngle * Math.PI / 180;
42680 const sweepAngle = this.sweepAngle * Math.PI / 180;
42681 const largeArc = this.sweepAngle > 180 ? 1 : 0;
42682 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))];
42683 arc = {
42684 name: "path",
42685 attributes: {
42686 xmlns: SVG_NS,
42687 d: `M ${x1} ${y1} A 50 50 0 ${largeArc} 0 ${x2} ${y2}`,
42688 vectorEffect: "non-scaling-stroke",
42689 style
42690 }
42691 };
42692 Object.assign(attributes, {
42693 viewBox: "0 0 100 100",
42694 preserveAspectRatio: "none"
42695 });
42696 }
42697 const svg = {
42698 name: "svg",
42699 children: [arc],
42700 attributes
42701 };
42702 const parent = this[$getParent]()[$getParent]();
42703 if (hasMargin(parent)) {
42704 return HTMLResult.success({
42705 name: "div",
42706 attributes: {
42707 style: {
42708 display: "inline",
42709 width: "100%",
42710 height: "100%"
42711 }
42712 },
42713 children: [svg]
42714 });
42715 }
42716 svg.attributes.style.position = "absolute";
42717 return HTMLResult.success(svg);
42718 }
42719}
42720class Area extends XFAObject {
42721 constructor(attributes) {
42722 super(TEMPLATE_NS_ID, "area", true);
42723 this.colSpan = getInteger({
42724 data: attributes.colSpan,
42725 defaultValue: 1,
42726 validate: n => n >= 1 || n === -1
42727 });
42728 this.id = attributes.id || "";
42729 this.name = attributes.name || "";
42730 this.relevant = getRelevant(attributes.relevant);
42731 this.use = attributes.use || "";
42732 this.usehref = attributes.usehref || "";
42733 this.x = getMeasurement(attributes.x, "0pt");
42734 this.y = getMeasurement(attributes.y, "0pt");
42735 this.desc = null;
42736 this.extras = null;
42737 this.area = new XFAObjectArray();
42738 this.draw = new XFAObjectArray();
42739 this.exObject = new XFAObjectArray();
42740 this.exclGroup = new XFAObjectArray();
42741 this.field = new XFAObjectArray();
42742 this.subform = new XFAObjectArray();
42743 this.subformSet = new XFAObjectArray();
42744 }
42745 *[$getContainedChildren]() {
42746 yield* getContainedChildren(this);
42747 }
42748 [$isTransparent]() {
42749 return true;
42750 }
42751 [$isBindable]() {
42752 return true;
42753 }
42754 [$addHTML](html, bbox) {
42755 const [x, y, w, h] = bbox;
42756 this[$extra].width = Math.max(this[$extra].width, x + w);
42757 this[$extra].height = Math.max(this[$extra].height, y + h);
42758 this[$extra].children.push(html);
42759 }
42760 [$getAvailableSpace]() {
42761 return this[$extra].availableSpace;
42762 }
42763 [$toHTML](availableSpace) {
42764 const style = toStyle(this, "position");
42765 const attributes = {
42766 style,
42767 id: this[$uid],
42768 class: ["xfaArea"]
42769 };
42770 if (isPrintOnly(this)) {
42771 attributes.class.push("xfaPrintOnly");
42772 }
42773 if (this.name) {
42774 attributes.xfaName = this.name;
42775 }
42776 const children = [];
42777 this[$extra] = {
42778 children,
42779 width: 0,
42780 height: 0,
42781 availableSpace
42782 };
42783 const result = this[$childrenToHTML]({
42784 filter: new Set(["area", "draw", "field", "exclGroup", "subform", "subformSet"]),
42785 include: true
42786 });
42787 if (!result.success) {
42788 if (result.isBreak()) {
42789 return result;
42790 }
42791 delete this[$extra];
42792 return HTMLResult.FAILURE;
42793 }
42794 style.width = measureToString(this[$extra].width);
42795 style.height = measureToString(this[$extra].height);
42796 const html = {
42797 name: "div",
42798 attributes,
42799 children
42800 };
42801 const bbox = [this.x, this.y, this[$extra].width, this[$extra].height];
42802 delete this[$extra];
42803 return HTMLResult.success(html, bbox);
42804 }
42805}
42806class Assist extends XFAObject {
42807 constructor(attributes) {
42808 super(TEMPLATE_NS_ID, "assist", true);
42809 this.id = attributes.id || "";
42810 this.role = attributes.role || "";
42811 this.use = attributes.use || "";
42812 this.usehref = attributes.usehref || "";
42813 this.speak = null;
42814 this.toolTip = null;
42815 }
42816 [$toHTML]() {
42817 return this.toolTip?.[$content] || null;
42818 }
42819}
42820class Barcode extends XFAObject {
42821 constructor(attributes) {
42822 super(TEMPLATE_NS_ID, "barcode", true);
42823 this.charEncoding = getKeyword({
42824 data: attributes.charEncoding ? attributes.charEncoding.toLowerCase() : "",
42825 defaultValue: "",
42826 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}/)
42827 });
42828 this.checksum = getStringOption(attributes.checksum, ["none", "1mod10", "1mod10_1mod11", "2mod10", "auto"]);
42829 this.dataColumnCount = getInteger({
42830 data: attributes.dataColumnCount,
42831 defaultValue: -1,
42832 validate: x => x >= 0
42833 });
42834 this.dataLength = getInteger({
42835 data: attributes.dataLength,
42836 defaultValue: -1,
42837 validate: x => x >= 0
42838 });
42839 this.dataPrep = getStringOption(attributes.dataPrep, ["none", "flateCompress"]);
42840 this.dataRowCount = getInteger({
42841 data: attributes.dataRowCount,
42842 defaultValue: -1,
42843 validate: x => x >= 0
42844 });
42845 this.endChar = attributes.endChar || "";
42846 this.errorCorrectionLevel = getInteger({
42847 data: attributes.errorCorrectionLevel,
42848 defaultValue: -1,
42849 validate: x => x >= 0 && x <= 8
42850 });
42851 this.id = attributes.id || "";
42852 this.moduleHeight = getMeasurement(attributes.moduleHeight, "5mm");
42853 this.moduleWidth = getMeasurement(attributes.moduleWidth, "0.25mm");
42854 this.printCheckDigit = getInteger({
42855 data: attributes.printCheckDigit,
42856 defaultValue: 0,
42857 validate: x => x === 1
42858 });
42859 this.rowColumnRatio = getRatio(attributes.rowColumnRatio);
42860 this.startChar = attributes.startChar || "";
42861 this.textLocation = getStringOption(attributes.textLocation, ["below", "above", "aboveEmbedded", "belowEmbedded", "none"]);
42862 this.truncate = getInteger({
42863 data: attributes.truncate,
42864 defaultValue: 0,
42865 validate: x => x === 1
42866 });
42867 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"]);
42868 this.upsMode = getStringOption(attributes.upsMode, ["usCarrier", "internationalCarrier", "secureSymbol", "standardSymbol"]);
42869 this.use = attributes.use || "";
42870 this.usehref = attributes.usehref || "";
42871 this.wideNarrowRatio = getRatio(attributes.wideNarrowRatio);
42872 this.encrypt = null;
42873 this.extras = null;
42874 }
42875}
42876class Bind extends XFAObject {
42877 constructor(attributes) {
42878 super(TEMPLATE_NS_ID, "bind", true);
42879 this.match = getStringOption(attributes.match, ["once", "dataRef", "global", "none"]);
42880 this.ref = attributes.ref || "";
42881 this.picture = null;
42882 }
42883}
42884class BindItems extends XFAObject {
42885 constructor(attributes) {
42886 super(TEMPLATE_NS_ID, "bindItems");
42887 this.connection = attributes.connection || "";
42888 this.labelRef = attributes.labelRef || "";
42889 this.ref = attributes.ref || "";
42890 this.valueRef = attributes.valueRef || "";
42891 }
42892}
42893class Bookend extends XFAObject {
42894 constructor(attributes) {
42895 super(TEMPLATE_NS_ID, "bookend");
42896 this.id = attributes.id || "";
42897 this.leader = attributes.leader || "";
42898 this.trailer = attributes.trailer || "";
42899 this.use = attributes.use || "";
42900 this.usehref = attributes.usehref || "";
42901 }
42902}
42903class BooleanElement extends Option01 {
42904 constructor(attributes) {
42905 super(TEMPLATE_NS_ID, "boolean");
42906 this.id = attributes.id || "";
42907 this.name = attributes.name || "";
42908 this.use = attributes.use || "";
42909 this.usehref = attributes.usehref || "";
42910 }
42911 [$toHTML](availableSpace) {
42912 return valueToHtml(this[$content] === 1 ? "1" : "0");
42913 }
42914}
42915class Border extends XFAObject {
42916 constructor(attributes) {
42917 super(TEMPLATE_NS_ID, "border", true);
42918 this.break = getStringOption(attributes.break, ["close", "open"]);
42919 this.hand = getStringOption(attributes.hand, ["even", "left", "right"]);
42920 this.id = attributes.id || "";
42921 this.presence = getStringOption(attributes.presence, ["visible", "hidden", "inactive", "invisible"]);
42922 this.relevant = getRelevant(attributes.relevant);
42923 this.use = attributes.use || "";
42924 this.usehref = attributes.usehref || "";
42925 this.corner = new XFAObjectArray(4);
42926 this.edge = new XFAObjectArray(4);
42927 this.extras = null;
42928 this.fill = null;
42929 this.margin = null;
42930 }
42931 [$getExtra]() {
42932 if (!this[$extra]) {
42933 const edges = this.edge.children.slice();
42934 if (edges.length < 4) {
42935 const defaultEdge = edges.at(-1) || new Edge({});
42936 for (let i = edges.length; i < 4; i++) {
42937 edges.push(defaultEdge);
42938 }
42939 }
42940 const widths = edges.map(edge => edge.thickness);
42941 const insets = [0, 0, 0, 0];
42942 if (this.margin) {
42943 insets[0] = this.margin.topInset;
42944 insets[1] = this.margin.rightInset;
42945 insets[2] = this.margin.bottomInset;
42946 insets[3] = this.margin.leftInset;
42947 }
42948 this[$extra] = {
42949 widths,
42950 insets,
42951 edges
42952 };
42953 }
42954 return this[$extra];
42955 }
42956 [$toStyle]() {
42957 const {
42958 edges
42959 } = this[$getExtra]();
42960 const edgeStyles = edges.map(node => {
42961 const style = node[$toStyle]();
42962 style.color ||= "#000000";
42963 return style;
42964 });
42965 const style = Object.create(null);
42966 if (this.margin) {
42967 Object.assign(style, this.margin[$toStyle]());
42968 }
42969 if (this.fill?.presence === "visible") {
42970 Object.assign(style, this.fill[$toStyle]());
42971 }
42972 if (this.corner.children.some(node => node.radius !== 0)) {
42973 const cornerStyles = this.corner.children.map(node => node[$toStyle]());
42974 if (cornerStyles.length === 2 || cornerStyles.length === 3) {
42975 const last = cornerStyles.at(-1);
42976 for (let i = cornerStyles.length; i < 4; i++) {
42977 cornerStyles.push(last);
42978 }
42979 }
42980 style.borderRadius = cornerStyles.map(s => s.radius).join(" ");
42981 }
42982 switch (this.presence) {
42983 case "invisible":
42984 case "hidden":
42985 style.borderStyle = "";
42986 break;
42987 case "inactive":
42988 style.borderStyle = "none";
42989 break;
42990 default:
42991 style.borderStyle = edgeStyles.map(s => s.style).join(" ");
42992 break;
42993 }
42994 style.borderWidth = edgeStyles.map(s => s.width).join(" ");
42995 style.borderColor = edgeStyles.map(s => s.color).join(" ");
42996 return style;
42997 }
42998}
42999class Break extends XFAObject {
43000 constructor(attributes) {
43001 super(TEMPLATE_NS_ID, "break", true);
43002 this.after = getStringOption(attributes.after, ["auto", "contentArea", "pageArea", "pageEven", "pageOdd"]);
43003 this.afterTarget = attributes.afterTarget || "";
43004 this.before = getStringOption(attributes.before, ["auto", "contentArea", "pageArea", "pageEven", "pageOdd"]);
43005 this.beforeTarget = attributes.beforeTarget || "";
43006 this.bookendLeader = attributes.bookendLeader || "";
43007 this.bookendTrailer = attributes.bookendTrailer || "";
43008 this.id = attributes.id || "";
43009 this.overflowLeader = attributes.overflowLeader || "";
43010 this.overflowTarget = attributes.overflowTarget || "";
43011 this.overflowTrailer = attributes.overflowTrailer || "";
43012 this.startNew = getInteger({
43013 data: attributes.startNew,
43014 defaultValue: 0,
43015 validate: x => x === 1
43016 });
43017 this.use = attributes.use || "";
43018 this.usehref = attributes.usehref || "";
43019 this.extras = null;
43020 }
43021}
43022class BreakAfter extends XFAObject {
43023 constructor(attributes) {
43024 super(TEMPLATE_NS_ID, "breakAfter", true);
43025 this.id = attributes.id || "";
43026 this.leader = attributes.leader || "";
43027 this.startNew = getInteger({
43028 data: attributes.startNew,
43029 defaultValue: 0,
43030 validate: x => x === 1
43031 });
43032 this.target = attributes.target || "";
43033 this.targetType = getStringOption(attributes.targetType, ["auto", "contentArea", "pageArea"]);
43034 this.trailer = attributes.trailer || "";
43035 this.use = attributes.use || "";
43036 this.usehref = attributes.usehref || "";
43037 this.script = null;
43038 }
43039}
43040class BreakBefore extends XFAObject {
43041 constructor(attributes) {
43042 super(TEMPLATE_NS_ID, "breakBefore", true);
43043 this.id = attributes.id || "";
43044 this.leader = attributes.leader || "";
43045 this.startNew = getInteger({
43046 data: attributes.startNew,
43047 defaultValue: 0,
43048 validate: x => x === 1
43049 });
43050 this.target = attributes.target || "";
43051 this.targetType = getStringOption(attributes.targetType, ["auto", "contentArea", "pageArea"]);
43052 this.trailer = attributes.trailer || "";
43053 this.use = attributes.use || "";
43054 this.usehref = attributes.usehref || "";
43055 this.script = null;
43056 }
43057 [$toHTML](availableSpace) {
43058 this[$extra] = {};
43059 return HTMLResult.FAILURE;
43060 }
43061}
43062class Button extends XFAObject {
43063 constructor(attributes) {
43064 super(TEMPLATE_NS_ID, "button", true);
43065 this.highlight = getStringOption(attributes.highlight, ["inverted", "none", "outline", "push"]);
43066 this.id = attributes.id || "";
43067 this.use = attributes.use || "";
43068 this.usehref = attributes.usehref || "";
43069 this.extras = null;
43070 }
43071 [$toHTML](availableSpace) {
43072 const parent = this[$getParent]();
43073 const grandpa = parent[$getParent]();
43074 const htmlButton = {
43075 name: "button",
43076 attributes: {
43077 id: this[$uid],
43078 class: ["xfaButton"],
43079 style: {}
43080 },
43081 children: []
43082 };
43083 for (const event of grandpa.event.children) {
43084 if (event.activity !== "click" || !event.script) {
43085 continue;
43086 }
43087 const jsURL = recoverJsURL(event.script[$content]);
43088 if (!jsURL) {
43089 continue;
43090 }
43091 const href = fixURL(jsURL.url);
43092 if (!href) {
43093 continue;
43094 }
43095 htmlButton.children.push({
43096 name: "a",
43097 attributes: {
43098 id: "link" + this[$uid],
43099 href,
43100 newWindow: jsURL.newWindow,
43101 class: ["xfaLink"],
43102 style: {}
43103 },
43104 children: []
43105 });
43106 }
43107 return HTMLResult.success(htmlButton);
43108 }
43109}
43110class Calculate extends XFAObject {
43111 constructor(attributes) {
43112 super(TEMPLATE_NS_ID, "calculate", true);
43113 this.id = attributes.id || "";
43114 this.override = getStringOption(attributes.override, ["disabled", "error", "ignore", "warning"]);
43115 this.use = attributes.use || "";
43116 this.usehref = attributes.usehref || "";
43117 this.extras = null;
43118 this.message = null;
43119 this.script = null;
43120 }
43121}
43122class Caption extends XFAObject {
43123 constructor(attributes) {
43124 super(TEMPLATE_NS_ID, "caption", true);
43125 this.id = attributes.id || "";
43126 this.placement = getStringOption(attributes.placement, ["left", "bottom", "inline", "right", "top"]);
43127 this.presence = getStringOption(attributes.presence, ["visible", "hidden", "inactive", "invisible"]);
43128 this.reserve = Math.ceil(getMeasurement(attributes.reserve));
43129 this.use = attributes.use || "";
43130 this.usehref = attributes.usehref || "";
43131 this.extras = null;
43132 this.font = null;
43133 this.margin = null;
43134 this.para = null;
43135 this.value = null;
43136 }
43137 [$setValue](value) {
43138 _setValue(this, value);
43139 }
43140 [$getExtra](availableSpace) {
43141 if (!this[$extra]) {
43142 let {
43143 width,
43144 height
43145 } = availableSpace;
43146 switch (this.placement) {
43147 case "left":
43148 case "right":
43149 case "inline":
43150 width = this.reserve <= 0 ? width : this.reserve;
43151 break;
43152 case "top":
43153 case "bottom":
43154 height = this.reserve <= 0 ? height : this.reserve;
43155 break;
43156 }
43157 this[$extra] = layoutNode(this, {
43158 width,
43159 height
43160 });
43161 }
43162 return this[$extra];
43163 }
43164 [$toHTML](availableSpace) {
43165 if (!this.value) {
43166 return HTMLResult.EMPTY;
43167 }
43168 this[$pushPara]();
43169 const value = this.value[$toHTML](availableSpace).html;
43170 if (!value) {
43171 this[$popPara]();
43172 return HTMLResult.EMPTY;
43173 }
43174 const savedReserve = this.reserve;
43175 if (this.reserve <= 0) {
43176 const {
43177 w,
43178 h
43179 } = this[$getExtra](availableSpace);
43180 switch (this.placement) {
43181 case "left":
43182 case "right":
43183 case "inline":
43184 this.reserve = w;
43185 break;
43186 case "top":
43187 case "bottom":
43188 this.reserve = h;
43189 break;
43190 }
43191 }
43192 const children = [];
43193 if (typeof value === "string") {
43194 children.push({
43195 name: "#text",
43196 value
43197 });
43198 } else {
43199 children.push(value);
43200 }
43201 const style = toStyle(this, "font", "margin", "visibility");
43202 switch (this.placement) {
43203 case "left":
43204 case "right":
43205 if (this.reserve > 0) {
43206 style.width = measureToString(this.reserve);
43207 }
43208 break;
43209 case "top":
43210 case "bottom":
43211 if (this.reserve > 0) {
43212 style.height = measureToString(this.reserve);
43213 }
43214 break;
43215 }
43216 setPara(this, null, value);
43217 this[$popPara]();
43218 this.reserve = savedReserve;
43219 return HTMLResult.success({
43220 name: "div",
43221 attributes: {
43222 style,
43223 class: ["xfaCaption"]
43224 },
43225 children
43226 });
43227 }
43228}
43229class Certificate extends StringObject {
43230 constructor(attributes) {
43231 super(TEMPLATE_NS_ID, "certificate");
43232 this.id = attributes.id || "";
43233 this.name = attributes.name || "";
43234 this.use = attributes.use || "";
43235 this.usehref = attributes.usehref || "";
43236 }
43237}
43238class Certificates extends XFAObject {
43239 constructor(attributes) {
43240 super(TEMPLATE_NS_ID, "certificates", true);
43241 this.credentialServerPolicy = getStringOption(attributes.credentialServerPolicy, ["optional", "required"]);
43242 this.id = attributes.id || "";
43243 this.url = attributes.url || "";
43244 this.urlPolicy = attributes.urlPolicy || "";
43245 this.use = attributes.use || "";
43246 this.usehref = attributes.usehref || "";
43247 this.encryption = null;
43248 this.issuers = null;
43249 this.keyUsage = null;
43250 this.oids = null;
43251 this.signing = null;
43252 this.subjectDNs = null;
43253 }
43254}
43255class CheckButton extends XFAObject {
43256 constructor(attributes) {
43257 super(TEMPLATE_NS_ID, "checkButton", true);
43258 this.id = attributes.id || "";
43259 this.mark = getStringOption(attributes.mark, ["default", "check", "circle", "cross", "diamond", "square", "star"]);
43260 this.shape = getStringOption(attributes.shape, ["square", "round"]);
43261 this.size = getMeasurement(attributes.size, "10pt");
43262 this.use = attributes.use || "";
43263 this.usehref = attributes.usehref || "";
43264 this.border = null;
43265 this.extras = null;
43266 this.margin = null;
43267 }
43268 [$toHTML](availableSpace) {
43269 const style = toStyle("margin");
43270 const size = measureToString(this.size);
43271 style.width = style.height = size;
43272 let type;
43273 let className;
43274 let groupId;
43275 const field = this[$getParent]()[$getParent]();
43276 const items = field.items.children.length && field.items.children[0][$toHTML]().html || [];
43277 const exportedValue = {
43278 on: (items[0] !== undefined ? items[0] : "on").toString(),
43279 off: (items[1] !== undefined ? items[1] : "off").toString()
43280 };
43281 const value = field.value?.[$text]() || "off";
43282 const checked = value === exportedValue.on || undefined;
43283 const container = field[$getSubformParent]();
43284 const fieldId = field[$uid];
43285 let dataId;
43286 if (container instanceof ExclGroup) {
43287 groupId = container[$uid];
43288 type = "radio";
43289 className = "xfaRadio";
43290 dataId = container[$data]?.[$uid] || container[$uid];
43291 } else {
43292 type = "checkbox";
43293 className = "xfaCheckbox";
43294 dataId = field[$data]?.[$uid] || field[$uid];
43295 }
43296 const input = {
43297 name: "input",
43298 attributes: {
43299 class: [className],
43300 style,
43301 fieldId,
43302 dataId,
43303 type,
43304 checked,
43305 xfaOn: exportedValue.on,
43306 xfaOff: exportedValue.off,
43307 "aria-label": ariaLabel(field),
43308 "aria-required": false
43309 }
43310 };
43311 if (groupId) {
43312 input.attributes.name = groupId;
43313 }
43314 if (isRequired(field)) {
43315 input.attributes["aria-required"] = true;
43316 input.attributes.required = true;
43317 }
43318 return HTMLResult.success({
43319 name: "label",
43320 attributes: {
43321 class: ["xfaLabel"]
43322 },
43323 children: [input]
43324 });
43325 }
43326}
43327class ChoiceList extends XFAObject {
43328 constructor(attributes) {
43329 super(TEMPLATE_NS_ID, "choiceList", true);
43330 this.commitOn = getStringOption(attributes.commitOn, ["select", "exit"]);
43331 this.id = attributes.id || "";
43332 this.open = getStringOption(attributes.open, ["userControl", "always", "multiSelect", "onEntry"]);
43333 this.textEntry = getInteger({
43334 data: attributes.textEntry,
43335 defaultValue: 0,
43336 validate: x => x === 1
43337 });
43338 this.use = attributes.use || "";
43339 this.usehref = attributes.usehref || "";
43340 this.border = null;
43341 this.extras = null;
43342 this.margin = null;
43343 }
43344 [$toHTML](availableSpace) {
43345 const style = toStyle(this, "border", "margin");
43346 const ui = this[$getParent]();
43347 const field = ui[$getParent]();
43348 const fontSize = field.font?.size || 10;
43349 const optionStyle = {
43350 fontSize: `calc(${fontSize}px * var(--scale-factor))`
43351 };
43352 const children = [];
43353 if (field.items.children.length > 0) {
43354 const items = field.items;
43355 let displayedIndex = 0;
43356 let saveIndex = 0;
43357 if (items.children.length === 2) {
43358 displayedIndex = items.children[0].save;
43359 saveIndex = 1 - displayedIndex;
43360 }
43361 const displayed = items.children[displayedIndex][$toHTML]().html;
43362 const values = items.children[saveIndex][$toHTML]().html;
43363 let selected = false;
43364 const value = field.value?.[$text]() || "";
43365 for (let i = 0, ii = displayed.length; i < ii; i++) {
43366 const option = {
43367 name: "option",
43368 attributes: {
43369 value: values[i] || displayed[i],
43370 style: optionStyle
43371 },
43372 value: displayed[i]
43373 };
43374 if (values[i] === value) {
43375 option.attributes.selected = selected = true;
43376 }
43377 children.push(option);
43378 }
43379 if (!selected) {
43380 children.splice(0, 0, {
43381 name: "option",
43382 attributes: {
43383 hidden: true,
43384 selected: true
43385 },
43386 value: " "
43387 });
43388 }
43389 }
43390 const selectAttributes = {
43391 class: ["xfaSelect"],
43392 fieldId: field[$uid],
43393 dataId: field[$data]?.[$uid] || field[$uid],
43394 style,
43395 "aria-label": ariaLabel(field),
43396 "aria-required": false
43397 };
43398 if (isRequired(field)) {
43399 selectAttributes["aria-required"] = true;
43400 selectAttributes.required = true;
43401 }
43402 if (this.open === "multiSelect") {
43403 selectAttributes.multiple = true;
43404 }
43405 return HTMLResult.success({
43406 name: "label",
43407 attributes: {
43408 class: ["xfaLabel"]
43409 },
43410 children: [{
43411 name: "select",
43412 children,
43413 attributes: selectAttributes
43414 }]
43415 });
43416 }
43417}
43418class Color extends XFAObject {
43419 constructor(attributes) {
43420 super(TEMPLATE_NS_ID, "color", true);
43421 this.cSpace = getStringOption(attributes.cSpace, ["SRGB"]);
43422 this.id = attributes.id || "";
43423 this.use = attributes.use || "";
43424 this.usehref = attributes.usehref || "";
43425 this.value = attributes.value ? getColor(attributes.value) : "";
43426 this.extras = null;
43427 }
43428 [$hasSettableValue]() {
43429 return false;
43430 }
43431 [$toStyle]() {
43432 return this.value ? Util.makeHexColor(this.value.r, this.value.g, this.value.b) : null;
43433 }
43434}
43435class Comb extends XFAObject {
43436 constructor(attributes) {
43437 super(TEMPLATE_NS_ID, "comb");
43438 this.id = attributes.id || "";
43439 this.numberOfCells = getInteger({
43440 data: attributes.numberOfCells,
43441 defaultValue: 0,
43442 validate: x => x >= 0
43443 });
43444 this.use = attributes.use || "";
43445 this.usehref = attributes.usehref || "";
43446 }
43447}
43448class Connect extends XFAObject {
43449 constructor(attributes) {
43450 super(TEMPLATE_NS_ID, "connect", true);
43451 this.connection = attributes.connection || "";
43452 this.id = attributes.id || "";
43453 this.ref = attributes.ref || "";
43454 this.usage = getStringOption(attributes.usage, ["exportAndImport", "exportOnly", "importOnly"]);
43455 this.use = attributes.use || "";
43456 this.usehref = attributes.usehref || "";
43457 this.picture = null;
43458 }
43459}
43460class ContentArea extends XFAObject {
43461 constructor(attributes) {
43462 super(TEMPLATE_NS_ID, "contentArea", true);
43463 this.h = getMeasurement(attributes.h);
43464 this.id = attributes.id || "";
43465 this.name = attributes.name || "";
43466 this.relevant = getRelevant(attributes.relevant);
43467 this.use = attributes.use || "";
43468 this.usehref = attributes.usehref || "";
43469 this.w = getMeasurement(attributes.w);
43470 this.x = getMeasurement(attributes.x, "0pt");
43471 this.y = getMeasurement(attributes.y, "0pt");
43472 this.desc = null;
43473 this.extras = null;
43474 }
43475 [$toHTML](availableSpace) {
43476 const left = measureToString(this.x);
43477 const top = measureToString(this.y);
43478 const style = {
43479 left,
43480 top,
43481 width: measureToString(this.w),
43482 height: measureToString(this.h)
43483 };
43484 const classNames = ["xfaContentarea"];
43485 if (isPrintOnly(this)) {
43486 classNames.push("xfaPrintOnly");
43487 }
43488 return HTMLResult.success({
43489 name: "div",
43490 children: [],
43491 attributes: {
43492 style,
43493 class: classNames,
43494 id: this[$uid]
43495 }
43496 });
43497 }
43498}
43499class Corner extends XFAObject {
43500 constructor(attributes) {
43501 super(TEMPLATE_NS_ID, "corner", true);
43502 this.id = attributes.id || "";
43503 this.inverted = getInteger({
43504 data: attributes.inverted,
43505 defaultValue: 0,
43506 validate: x => x === 1
43507 });
43508 this.join = getStringOption(attributes.join, ["square", "round"]);
43509 this.presence = getStringOption(attributes.presence, ["visible", "hidden", "inactive", "invisible"]);
43510 this.radius = getMeasurement(attributes.radius);
43511 this.stroke = getStringOption(attributes.stroke, ["solid", "dashDot", "dashDotDot", "dashed", "dotted", "embossed", "etched", "lowered", "raised"]);
43512 this.thickness = getMeasurement(attributes.thickness, "0.5pt");
43513 this.use = attributes.use || "";
43514 this.usehref = attributes.usehref || "";
43515 this.color = null;
43516 this.extras = null;
43517 }
43518 [$toStyle]() {
43519 const style = toStyle(this, "visibility");
43520 style.radius = measureToString(this.join === "square" ? 0 : this.radius);
43521 return style;
43522 }
43523}
43524class DateElement extends ContentObject {
43525 constructor(attributes) {
43526 super(TEMPLATE_NS_ID, "date");
43527 this.id = attributes.id || "";
43528 this.name = attributes.name || "";
43529 this.use = attributes.use || "";
43530 this.usehref = attributes.usehref || "";
43531 }
43532 [$finalize]() {
43533 const date = this[$content].trim();
43534 this[$content] = date ? new Date(date) : null;
43535 }
43536 [$toHTML](availableSpace) {
43537 return valueToHtml(this[$content] ? this[$content].toString() : "");
43538 }
43539}
43540class DateTime extends ContentObject {
43541 constructor(attributes) {
43542 super(TEMPLATE_NS_ID, "dateTime");
43543 this.id = attributes.id || "";
43544 this.name = attributes.name || "";
43545 this.use = attributes.use || "";
43546 this.usehref = attributes.usehref || "";
43547 }
43548 [$finalize]() {
43549 const date = this[$content].trim();
43550 this[$content] = date ? new Date(date) : null;
43551 }
43552 [$toHTML](availableSpace) {
43553 return valueToHtml(this[$content] ? this[$content].toString() : "");
43554 }
43555}
43556class DateTimeEdit extends XFAObject {
43557 constructor(attributes) {
43558 super(TEMPLATE_NS_ID, "dateTimeEdit", true);
43559 this.hScrollPolicy = getStringOption(attributes.hScrollPolicy, ["auto", "off", "on"]);
43560 this.id = attributes.id || "";
43561 this.picker = getStringOption(attributes.picker, ["host", "none"]);
43562 this.use = attributes.use || "";
43563 this.usehref = attributes.usehref || "";
43564 this.border = null;
43565 this.comb = null;
43566 this.extras = null;
43567 this.margin = null;
43568 }
43569 [$toHTML](availableSpace) {
43570 const style = toStyle(this, "border", "font", "margin");
43571 const field = this[$getParent]()[$getParent]();
43572 const html = {
43573 name: "input",
43574 attributes: {
43575 type: "text",
43576 fieldId: field[$uid],
43577 dataId: field[$data]?.[$uid] || field[$uid],
43578 class: ["xfaTextfield"],
43579 style,
43580 "aria-label": ariaLabel(field),
43581 "aria-required": false
43582 }
43583 };
43584 if (isRequired(field)) {
43585 html.attributes["aria-required"] = true;
43586 html.attributes.required = true;
43587 }
43588 return HTMLResult.success({
43589 name: "label",
43590 attributes: {
43591 class: ["xfaLabel"]
43592 },
43593 children: [html]
43594 });
43595 }
43596}
43597class Decimal extends ContentObject {
43598 constructor(attributes) {
43599 super(TEMPLATE_NS_ID, "decimal");
43600 this.fracDigits = getInteger({
43601 data: attributes.fracDigits,
43602 defaultValue: 2,
43603 validate: x => true
43604 });
43605 this.id = attributes.id || "";
43606 this.leadDigits = getInteger({
43607 data: attributes.leadDigits,
43608 defaultValue: -1,
43609 validate: x => true
43610 });
43611 this.name = attributes.name || "";
43612 this.use = attributes.use || "";
43613 this.usehref = attributes.usehref || "";
43614 }
43615 [$finalize]() {
43616 const number = parseFloat(this[$content].trim());
43617 this[$content] = isNaN(number) ? null : number;
43618 }
43619 [$toHTML](availableSpace) {
43620 return valueToHtml(this[$content] !== null ? this[$content].toString() : "");
43621 }
43622}
43623class DefaultUi extends XFAObject {
43624 constructor(attributes) {
43625 super(TEMPLATE_NS_ID, "defaultUi", true);
43626 this.id = attributes.id || "";
43627 this.use = attributes.use || "";
43628 this.usehref = attributes.usehref || "";
43629 this.extras = null;
43630 }
43631}
43632class Desc extends XFAObject {
43633 constructor(attributes) {
43634 super(TEMPLATE_NS_ID, "desc", true);
43635 this.id = attributes.id || "";
43636 this.use = attributes.use || "";
43637 this.usehref = attributes.usehref || "";
43638 this.boolean = new XFAObjectArray();
43639 this.date = new XFAObjectArray();
43640 this.dateTime = new XFAObjectArray();
43641 this.decimal = new XFAObjectArray();
43642 this.exData = new XFAObjectArray();
43643 this.float = new XFAObjectArray();
43644 this.image = new XFAObjectArray();
43645 this.integer = new XFAObjectArray();
43646 this.text = new XFAObjectArray();
43647 this.time = new XFAObjectArray();
43648 }
43649}
43650class DigestMethod extends OptionObject {
43651 constructor(attributes) {
43652 super(TEMPLATE_NS_ID, "digestMethod", ["", "SHA1", "SHA256", "SHA512", "RIPEMD160"]);
43653 this.id = attributes.id || "";
43654 this.use = attributes.use || "";
43655 this.usehref = attributes.usehref || "";
43656 }
43657}
43658class DigestMethods extends XFAObject {
43659 constructor(attributes) {
43660 super(TEMPLATE_NS_ID, "digestMethods", true);
43661 this.id = attributes.id || "";
43662 this.type = getStringOption(attributes.type, ["optional", "required"]);
43663 this.use = attributes.use || "";
43664 this.usehref = attributes.usehref || "";
43665 this.digestMethod = new XFAObjectArray();
43666 }
43667}
43668class Draw extends XFAObject {
43669 constructor(attributes) {
43670 super(TEMPLATE_NS_ID, "draw", true);
43671 this.anchorType = getStringOption(attributes.anchorType, ["topLeft", "bottomCenter", "bottomLeft", "bottomRight", "middleCenter", "middleLeft", "middleRight", "topCenter", "topRight"]);
43672 this.colSpan = getInteger({
43673 data: attributes.colSpan,
43674 defaultValue: 1,
43675 validate: n => n >= 1 || n === -1
43676 });
43677 this.h = attributes.h ? getMeasurement(attributes.h) : "";
43678 this.hAlign = getStringOption(attributes.hAlign, ["left", "center", "justify", "justifyAll", "radix", "right"]);
43679 this.id = attributes.id || "";
43680 this.locale = attributes.locale || "";
43681 this.maxH = getMeasurement(attributes.maxH, "0pt");
43682 this.maxW = getMeasurement(attributes.maxW, "0pt");
43683 this.minH = getMeasurement(attributes.minH, "0pt");
43684 this.minW = getMeasurement(attributes.minW, "0pt");
43685 this.name = attributes.name || "";
43686 this.presence = getStringOption(attributes.presence, ["visible", "hidden", "inactive", "invisible"]);
43687 this.relevant = getRelevant(attributes.relevant);
43688 this.rotate = getInteger({
43689 data: attributes.rotate,
43690 defaultValue: 0,
43691 validate: x => x % 90 === 0
43692 });
43693 this.use = attributes.use || "";
43694 this.usehref = attributes.usehref || "";
43695 this.w = attributes.w ? getMeasurement(attributes.w) : "";
43696 this.x = getMeasurement(attributes.x, "0pt");
43697 this.y = getMeasurement(attributes.y, "0pt");
43698 this.assist = null;
43699 this.border = null;
43700 this.caption = null;
43701 this.desc = null;
43702 this.extras = null;
43703 this.font = null;
43704 this.keep = null;
43705 this.margin = null;
43706 this.para = null;
43707 this.traversal = null;
43708 this.ui = null;
43709 this.value = null;
43710 this.setProperty = new XFAObjectArray();
43711 }
43712 [$setValue](value) {
43713 _setValue(this, value);
43714 }
43715 [$toHTML](availableSpace) {
43716 setTabIndex(this);
43717 if (this.presence === "hidden" || this.presence === "inactive") {
43718 return HTMLResult.EMPTY;
43719 }
43720 fixDimensions(this);
43721 this[$pushPara]();
43722 const savedW = this.w;
43723 const savedH = this.h;
43724 const {
43725 w,
43726 h,
43727 isBroken
43728 } = layoutNode(this, availableSpace);
43729 if (w && this.w === "") {
43730 if (isBroken && this[$getSubformParent]()[$isThereMoreWidth]()) {
43731 this[$popPara]();
43732 return HTMLResult.FAILURE;
43733 }
43734 this.w = w;
43735 }
43736 if (h && this.h === "") {
43737 this.h = h;
43738 }
43739 setFirstUnsplittable(this);
43740 if (!checkDimensions(this, availableSpace)) {
43741 this.w = savedW;
43742 this.h = savedH;
43743 this[$popPara]();
43744 return HTMLResult.FAILURE;
43745 }
43746 unsetFirstUnsplittable(this);
43747 const style = toStyle(this, "font", "hAlign", "dimensions", "position", "presence", "rotate", "anchorType", "border", "margin");
43748 setMinMaxDimensions(this, style);
43749 if (style.margin) {
43750 style.padding = style.margin;
43751 delete style.margin;
43752 }
43753 const classNames = ["xfaDraw"];
43754 if (this.font) {
43755 classNames.push("xfaFont");
43756 }
43757 if (isPrintOnly(this)) {
43758 classNames.push("xfaPrintOnly");
43759 }
43760 const attributes = {
43761 style,
43762 id: this[$uid],
43763 class: classNames
43764 };
43765 if (this.name) {
43766 attributes.xfaName = this.name;
43767 }
43768 const html = {
43769 name: "div",
43770 attributes,
43771 children: []
43772 };
43773 applyAssist(this, attributes);
43774 const bbox = computeBbox(this, html, availableSpace);
43775 const value = this.value ? this.value[$toHTML](availableSpace).html : null;
43776 if (value === null) {
43777 this.w = savedW;
43778 this.h = savedH;
43779 this[$popPara]();
43780 return HTMLResult.success(createWrapper(this, html), bbox);
43781 }
43782 html.children.push(value);
43783 setPara(this, style, value);
43784 this.w = savedW;
43785 this.h = savedH;
43786 this[$popPara]();
43787 return HTMLResult.success(createWrapper(this, html), bbox);
43788 }
43789}
43790class Edge extends XFAObject {
43791 constructor(attributes) {
43792 super(TEMPLATE_NS_ID, "edge", true);
43793 this.cap = getStringOption(attributes.cap, ["square", "butt", "round"]);
43794 this.id = attributes.id || "";
43795 this.presence = getStringOption(attributes.presence, ["visible", "hidden", "inactive", "invisible"]);
43796 this.stroke = getStringOption(attributes.stroke, ["solid", "dashDot", "dashDotDot", "dashed", "dotted", "embossed", "etched", "lowered", "raised"]);
43797 this.thickness = getMeasurement(attributes.thickness, "0.5pt");
43798 this.use = attributes.use || "";
43799 this.usehref = attributes.usehref || "";
43800 this.color = null;
43801 this.extras = null;
43802 }
43803 [$toStyle]() {
43804 const style = toStyle(this, "visibility");
43805 Object.assign(style, {
43806 linecap: this.cap,
43807 width: measureToString(this.thickness),
43808 color: this.color ? this.color[$toStyle]() : "#000000",
43809 style: ""
43810 });
43811 if (this.presence !== "visible") {
43812 style.style = "none";
43813 } else {
43814 switch (this.stroke) {
43815 case "solid":
43816 style.style = "solid";
43817 break;
43818 case "dashDot":
43819 style.style = "dashed";
43820 break;
43821 case "dashDotDot":
43822 style.style = "dashed";
43823 break;
43824 case "dashed":
43825 style.style = "dashed";
43826 break;
43827 case "dotted":
43828 style.style = "dotted";
43829 break;
43830 case "embossed":
43831 style.style = "ridge";
43832 break;
43833 case "etched":
43834 style.style = "groove";
43835 break;
43836 case "lowered":
43837 style.style = "inset";
43838 break;
43839 case "raised":
43840 style.style = "outset";
43841 break;
43842 }
43843 }
43844 return style;
43845 }
43846}
43847class Encoding extends OptionObject {
43848 constructor(attributes) {
43849 super(TEMPLATE_NS_ID, "encoding", ["adbe.x509.rsa_sha1", "adbe.pkcs7.detached", "adbe.pkcs7.sha1"]);
43850 this.id = attributes.id || "";
43851 this.use = attributes.use || "";
43852 this.usehref = attributes.usehref || "";
43853 }
43854}
43855class Encodings extends XFAObject {
43856 constructor(attributes) {
43857 super(TEMPLATE_NS_ID, "encodings", true);
43858 this.id = attributes.id || "";
43859 this.type = getStringOption(attributes.type, ["optional", "required"]);
43860 this.use = attributes.use || "";
43861 this.usehref = attributes.usehref || "";
43862 this.encoding = new XFAObjectArray();
43863 }
43864}
43865class Encrypt extends XFAObject {
43866 constructor(attributes) {
43867 super(TEMPLATE_NS_ID, "encrypt", true);
43868 this.id = attributes.id || "";
43869 this.use = attributes.use || "";
43870 this.usehref = attributes.usehref || "";
43871 this.certificate = null;
43872 }
43873}
43874class EncryptData extends XFAObject {
43875 constructor(attributes) {
43876 super(TEMPLATE_NS_ID, "encryptData", true);
43877 this.id = attributes.id || "";
43878 this.operation = getStringOption(attributes.operation, ["encrypt", "decrypt"]);
43879 this.target = attributes.target || "";
43880 this.use = attributes.use || "";
43881 this.usehref = attributes.usehref || "";
43882 this.filter = null;
43883 this.manifest = null;
43884 }
43885}
43886class Encryption extends XFAObject {
43887 constructor(attributes) {
43888 super(TEMPLATE_NS_ID, "encryption", true);
43889 this.id = attributes.id || "";
43890 this.type = getStringOption(attributes.type, ["optional", "required"]);
43891 this.use = attributes.use || "";
43892 this.usehref = attributes.usehref || "";
43893 this.certificate = new XFAObjectArray();
43894 }
43895}
43896class EncryptionMethod extends OptionObject {
43897 constructor(attributes) {
43898 super(TEMPLATE_NS_ID, "encryptionMethod", ["", "AES256-CBC", "TRIPLEDES-CBC", "AES128-CBC", "AES192-CBC"]);
43899 this.id = attributes.id || "";
43900 this.use = attributes.use || "";
43901 this.usehref = attributes.usehref || "";
43902 }
43903}
43904class EncryptionMethods extends XFAObject {
43905 constructor(attributes) {
43906 super(TEMPLATE_NS_ID, "encryptionMethods", true);
43907 this.id = attributes.id || "";
43908 this.type = getStringOption(attributes.type, ["optional", "required"]);
43909 this.use = attributes.use || "";
43910 this.usehref = attributes.usehref || "";
43911 this.encryptionMethod = new XFAObjectArray();
43912 }
43913}
43914class Event extends XFAObject {
43915 constructor(attributes) {
43916 super(TEMPLATE_NS_ID, "event", true);
43917 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"]);
43918 this.id = attributes.id || "";
43919 this.listen = getStringOption(attributes.listen, ["refOnly", "refAndDescendents"]);
43920 this.name = attributes.name || "";
43921 this.ref = attributes.ref || "";
43922 this.use = attributes.use || "";
43923 this.usehref = attributes.usehref || "";
43924 this.extras = null;
43925 this.encryptData = null;
43926 this.execute = null;
43927 this.script = null;
43928 this.signData = null;
43929 this.submit = null;
43930 }
43931}
43932class ExData extends ContentObject {
43933 constructor(attributes) {
43934 super(TEMPLATE_NS_ID, "exData");
43935 this.contentType = attributes.contentType || "";
43936 this.href = attributes.href || "";
43937 this.id = attributes.id || "";
43938 this.maxLength = getInteger({
43939 data: attributes.maxLength,
43940 defaultValue: -1,
43941 validate: x => x >= -1
43942 });
43943 this.name = attributes.name || "";
43944 this.rid = attributes.rid || "";
43945 this.transferEncoding = getStringOption(attributes.transferEncoding, ["none", "base64", "package"]);
43946 this.use = attributes.use || "";
43947 this.usehref = attributes.usehref || "";
43948 }
43949 [$isCDATAXml]() {
43950 return this.contentType === "text/html";
43951 }
43952 [$onChild](child) {
43953 if (this.contentType === "text/html" && child[$namespaceId] === NamespaceIds.xhtml.id) {
43954 this[$content] = child;
43955 return true;
43956 }
43957 if (this.contentType === "text/xml") {
43958 this[$content] = child;
43959 return true;
43960 }
43961 return false;
43962 }
43963 [$toHTML](availableSpace) {
43964 if (this.contentType !== "text/html" || !this[$content]) {
43965 return HTMLResult.EMPTY;
43966 }
43967 return this[$content][$toHTML](availableSpace);
43968 }
43969}
43970class ExObject extends XFAObject {
43971 constructor(attributes) {
43972 super(TEMPLATE_NS_ID, "exObject", true);
43973 this.archive = attributes.archive || "";
43974 this.classId = attributes.classId || "";
43975 this.codeBase = attributes.codeBase || "";
43976 this.codeType = attributes.codeType || "";
43977 this.id = attributes.id || "";
43978 this.name = attributes.name || "";
43979 this.use = attributes.use || "";
43980 this.usehref = attributes.usehref || "";
43981 this.extras = null;
43982 this.boolean = new XFAObjectArray();
43983 this.date = new XFAObjectArray();
43984 this.dateTime = new XFAObjectArray();
43985 this.decimal = new XFAObjectArray();
43986 this.exData = new XFAObjectArray();
43987 this.exObject = new XFAObjectArray();
43988 this.float = new XFAObjectArray();
43989 this.image = new XFAObjectArray();
43990 this.integer = new XFAObjectArray();
43991 this.text = new XFAObjectArray();
43992 this.time = new XFAObjectArray();
43993 }
43994}
43995class ExclGroup extends XFAObject {
43996 constructor(attributes) {
43997 super(TEMPLATE_NS_ID, "exclGroup", true);
43998 this.access = getStringOption(attributes.access, ["open", "nonInteractive", "protected", "readOnly"]);
43999 this.accessKey = attributes.accessKey || "";
44000 this.anchorType = getStringOption(attributes.anchorType, ["topLeft", "bottomCenter", "bottomLeft", "bottomRight", "middleCenter", "middleLeft", "middleRight", "topCenter", "topRight"]);
44001 this.colSpan = getInteger({
44002 data: attributes.colSpan,
44003 defaultValue: 1,
44004 validate: n => n >= 1 || n === -1
44005 });
44006 this.h = attributes.h ? getMeasurement(attributes.h) : "";
44007 this.hAlign = getStringOption(attributes.hAlign, ["left", "center", "justify", "justifyAll", "radix", "right"]);
44008 this.id = attributes.id || "";
44009 this.layout = getStringOption(attributes.layout, ["position", "lr-tb", "rl-row", "rl-tb", "row", "table", "tb"]);
44010 this.maxH = getMeasurement(attributes.maxH, "0pt");
44011 this.maxW = getMeasurement(attributes.maxW, "0pt");
44012 this.minH = getMeasurement(attributes.minH, "0pt");
44013 this.minW = getMeasurement(attributes.minW, "0pt");
44014 this.name = attributes.name || "";
44015 this.presence = getStringOption(attributes.presence, ["visible", "hidden", "inactive", "invisible"]);
44016 this.relevant = getRelevant(attributes.relevant);
44017 this.use = attributes.use || "";
44018 this.usehref = attributes.usehref || "";
44019 this.w = attributes.w ? getMeasurement(attributes.w) : "";
44020 this.x = getMeasurement(attributes.x, "0pt");
44021 this.y = getMeasurement(attributes.y, "0pt");
44022 this.assist = null;
44023 this.bind = null;
44024 this.border = null;
44025 this.calculate = null;
44026 this.caption = null;
44027 this.desc = null;
44028 this.extras = null;
44029 this.margin = null;
44030 this.para = null;
44031 this.traversal = null;
44032 this.validate = null;
44033 this.connect = new XFAObjectArray();
44034 this.event = new XFAObjectArray();
44035 this.field = new XFAObjectArray();
44036 this.setProperty = new XFAObjectArray();
44037 }
44038 [$isBindable]() {
44039 return true;
44040 }
44041 [$hasSettableValue]() {
44042 return true;
44043 }
44044 [$setValue](value) {
44045 for (const field of this.field.children) {
44046 if (!field.value) {
44047 const nodeValue = new Value({});
44048 field[$appendChild](nodeValue);
44049 field.value = nodeValue;
44050 }
44051 field.value[$setValue](value);
44052 }
44053 }
44054 [$isThereMoreWidth]() {
44055 return this.layout.endsWith("-tb") && this[$extra].attempt === 0 && this[$extra].numberInLine > 0 || this[$getParent]()[$isThereMoreWidth]();
44056 }
44057 [$isSplittable]() {
44058 const parent = this[$getSubformParent]();
44059 if (!parent[$isSplittable]()) {
44060 return false;
44061 }
44062 if (this[$extra]._isSplittable !== undefined) {
44063 return this[$extra]._isSplittable;
44064 }
44065 if (this.layout === "position" || this.layout.includes("row")) {
44066 this[$extra]._isSplittable = false;
44067 return false;
44068 }
44069 if (parent.layout?.endsWith("-tb") && parent[$extra].numberInLine !== 0) {
44070 return false;
44071 }
44072 this[$extra]._isSplittable = true;
44073 return true;
44074 }
44075 [$flushHTML]() {
44076 return flushHTML(this);
44077 }
44078 [$addHTML](html, bbox) {
44079 addHTML(this, html, bbox);
44080 }
44081 [$getAvailableSpace]() {
44082 return getAvailableSpace(this);
44083 }
44084 [$toHTML](availableSpace) {
44085 setTabIndex(this);
44086 if (this.presence === "hidden" || this.presence === "inactive" || this.h === 0 || this.w === 0) {
44087 return HTMLResult.EMPTY;
44088 }
44089 fixDimensions(this);
44090 const children = [];
44091 const attributes = {
44092 id: this[$uid],
44093 class: []
44094 };
44095 setAccess(this, attributes.class);
44096 if (!this[$extra]) {
44097 this[$extra] = Object.create(null);
44098 }
44099 Object.assign(this[$extra], {
44100 children,
44101 attributes,
44102 attempt: 0,
44103 line: null,
44104 numberInLine: 0,
44105 availableSpace: {
44106 width: Math.min(this.w || Infinity, availableSpace.width),
44107 height: Math.min(this.h || Infinity, availableSpace.height)
44108 },
44109 width: 0,
44110 height: 0,
44111 prevHeight: 0,
44112 currentWidth: 0
44113 });
44114 const isSplittable = this[$isSplittable]();
44115 if (!isSplittable) {
44116 setFirstUnsplittable(this);
44117 }
44118 if (!checkDimensions(this, availableSpace)) {
44119 return HTMLResult.FAILURE;
44120 }
44121 const filter = new Set(["field"]);
44122 if (this.layout.includes("row")) {
44123 const columnWidths = this[$getSubformParent]().columnWidths;
44124 if (Array.isArray(columnWidths) && columnWidths.length > 0) {
44125 this[$extra].columnWidths = columnWidths;
44126 this[$extra].currentColumn = 0;
44127 }
44128 }
44129 const style = toStyle(this, "anchorType", "dimensions", "position", "presence", "border", "margin", "hAlign");
44130 const classNames = ["xfaExclgroup"];
44131 const cl = layoutClass(this);
44132 if (cl) {
44133 classNames.push(cl);
44134 }
44135 if (isPrintOnly(this)) {
44136 classNames.push("xfaPrintOnly");
44137 }
44138 attributes.style = style;
44139 attributes.class = classNames;
44140 if (this.name) {
44141 attributes.xfaName = this.name;
44142 }
44143 this[$pushPara]();
44144 const isLrTb = this.layout === "lr-tb" || this.layout === "rl-tb";
44145 const maxRun = isLrTb ? MAX_ATTEMPTS_FOR_LRTB_LAYOUT : 1;
44146 for (; this[$extra].attempt < maxRun; this[$extra].attempt++) {
44147 if (isLrTb && this[$extra].attempt === MAX_ATTEMPTS_FOR_LRTB_LAYOUT - 1) {
44148 this[$extra].numberInLine = 0;
44149 }
44150 const result = this[$childrenToHTML]({
44151 filter,
44152 include: true
44153 });
44154 if (result.success) {
44155 break;
44156 }
44157 if (result.isBreak()) {
44158 this[$popPara]();
44159 return result;
44160 }
44161 if (isLrTb && this[$extra].attempt === 0 && this[$extra].numberInLine === 0 && !this[$getTemplateRoot]()[$extra].noLayoutFailure) {
44162 this[$extra].attempt = maxRun;
44163 break;
44164 }
44165 }
44166 this[$popPara]();
44167 if (!isSplittable) {
44168 unsetFirstUnsplittable(this);
44169 }
44170 if (this[$extra].attempt === maxRun) {
44171 if (!isSplittable) {
44172 delete this[$extra];
44173 }
44174 return HTMLResult.FAILURE;
44175 }
44176 let marginH = 0;
44177 let marginV = 0;
44178 if (this.margin) {
44179 marginH = this.margin.leftInset + this.margin.rightInset;
44180 marginV = this.margin.topInset + this.margin.bottomInset;
44181 }
44182 const width = Math.max(this[$extra].width + marginH, this.w || 0);
44183 const height = Math.max(this[$extra].height + marginV, this.h || 0);
44184 const bbox = [this.x, this.y, width, height];
44185 if (this.w === "") {
44186 style.width = measureToString(width);
44187 }
44188 if (this.h === "") {
44189 style.height = measureToString(height);
44190 }
44191 const html = {
44192 name: "div",
44193 attributes,
44194 children
44195 };
44196 applyAssist(this, attributes);
44197 delete this[$extra];
44198 return HTMLResult.success(createWrapper(this, html), bbox);
44199 }
44200}
44201class Execute extends XFAObject {
44202 constructor(attributes) {
44203 super(TEMPLATE_NS_ID, "execute");
44204 this.connection = attributes.connection || "";
44205 this.executeType = getStringOption(attributes.executeType, ["import", "remerge"]);
44206 this.id = attributes.id || "";
44207 this.runAt = getStringOption(attributes.runAt, ["client", "both", "server"]);
44208 this.use = attributes.use || "";
44209 this.usehref = attributes.usehref || "";
44210 }
44211}
44212class Extras extends XFAObject {
44213 constructor(attributes) {
44214 super(TEMPLATE_NS_ID, "extras", true);
44215 this.id = attributes.id || "";
44216 this.name = attributes.name || "";
44217 this.use = attributes.use || "";
44218 this.usehref = attributes.usehref || "";
44219 this.boolean = new XFAObjectArray();
44220 this.date = new XFAObjectArray();
44221 this.dateTime = new XFAObjectArray();
44222 this.decimal = new XFAObjectArray();
44223 this.exData = new XFAObjectArray();
44224 this.extras = new XFAObjectArray();
44225 this.float = new XFAObjectArray();
44226 this.image = new XFAObjectArray();
44227 this.integer = new XFAObjectArray();
44228 this.text = new XFAObjectArray();
44229 this.time = new XFAObjectArray();
44230 }
44231}
44232class Field extends XFAObject {
44233 constructor(attributes) {
44234 super(TEMPLATE_NS_ID, "field", true);
44235 this.access = getStringOption(attributes.access, ["open", "nonInteractive", "protected", "readOnly"]);
44236 this.accessKey = attributes.accessKey || "";
44237 this.anchorType = getStringOption(attributes.anchorType, ["topLeft", "bottomCenter", "bottomLeft", "bottomRight", "middleCenter", "middleLeft", "middleRight", "topCenter", "topRight"]);
44238 this.colSpan = getInteger({
44239 data: attributes.colSpan,
44240 defaultValue: 1,
44241 validate: n => n >= 1 || n === -1
44242 });
44243 this.h = attributes.h ? getMeasurement(attributes.h) : "";
44244 this.hAlign = getStringOption(attributes.hAlign, ["left", "center", "justify", "justifyAll", "radix", "right"]);
44245 this.id = attributes.id || "";
44246 this.locale = attributes.locale || "";
44247 this.maxH = getMeasurement(attributes.maxH, "0pt");
44248 this.maxW = getMeasurement(attributes.maxW, "0pt");
44249 this.minH = getMeasurement(attributes.minH, "0pt");
44250 this.minW = getMeasurement(attributes.minW, "0pt");
44251 this.name = attributes.name || "";
44252 this.presence = getStringOption(attributes.presence, ["visible", "hidden", "inactive", "invisible"]);
44253 this.relevant = getRelevant(attributes.relevant);
44254 this.rotate = getInteger({
44255 data: attributes.rotate,
44256 defaultValue: 0,
44257 validate: x => x % 90 === 0
44258 });
44259 this.use = attributes.use || "";
44260 this.usehref = attributes.usehref || "";
44261 this.w = attributes.w ? getMeasurement(attributes.w) : "";
44262 this.x = getMeasurement(attributes.x, "0pt");
44263 this.y = getMeasurement(attributes.y, "0pt");
44264 this.assist = null;
44265 this.bind = null;
44266 this.border = null;
44267 this.calculate = null;
44268 this.caption = null;
44269 this.desc = null;
44270 this.extras = null;
44271 this.font = null;
44272 this.format = null;
44273 this.items = new XFAObjectArray(2);
44274 this.keep = null;
44275 this.margin = null;
44276 this.para = null;
44277 this.traversal = null;
44278 this.ui = null;
44279 this.validate = null;
44280 this.value = null;
44281 this.bindItems = new XFAObjectArray();
44282 this.connect = new XFAObjectArray();
44283 this.event = new XFAObjectArray();
44284 this.setProperty = new XFAObjectArray();
44285 }
44286 [$isBindable]() {
44287 return true;
44288 }
44289 [$setValue](value) {
44290 _setValue(this, value);
44291 }
44292 [$toHTML](availableSpace) {
44293 setTabIndex(this);
44294 if (!this.ui) {
44295 this.ui = new Ui({});
44296 this.ui[$globalData] = this[$globalData];
44297 this[$appendChild](this.ui);
44298 let node;
44299 switch (this.items.children.length) {
44300 case 0:
44301 node = new TextEdit({});
44302 this.ui.textEdit = node;
44303 break;
44304 case 1:
44305 node = new CheckButton({});
44306 this.ui.checkButton = node;
44307 break;
44308 case 2:
44309 node = new ChoiceList({});
44310 this.ui.choiceList = node;
44311 break;
44312 }
44313 this.ui[$appendChild](node);
44314 }
44315 if (!this.ui || this.presence === "hidden" || this.presence === "inactive" || this.h === 0 || this.w === 0) {
44316 return HTMLResult.EMPTY;
44317 }
44318 if (this.caption) {
44319 delete this.caption[$extra];
44320 }
44321 this[$pushPara]();
44322 const caption = this.caption ? this.caption[$toHTML](availableSpace).html : null;
44323 const savedW = this.w;
44324 const savedH = this.h;
44325 let marginH = 0;
44326 let marginV = 0;
44327 if (this.margin) {
44328 marginH = this.margin.leftInset + this.margin.rightInset;
44329 marginV = this.margin.topInset + this.margin.bottomInset;
44330 }
44331 let borderDims = null;
44332 if (this.w === "" || this.h === "") {
44333 let width = null;
44334 let height = null;
44335 let uiW = 0;
44336 let uiH = 0;
44337 if (this.ui.checkButton) {
44338 uiW = uiH = this.ui.checkButton.size;
44339 } else {
44340 const {
44341 w,
44342 h
44343 } = layoutNode(this, availableSpace);
44344 if (w !== null) {
44345 uiW = w;
44346 uiH = h;
44347 } else {
44348 uiH = fonts_getMetrics(this.font, true).lineNoGap;
44349 }
44350 }
44351 borderDims = getBorderDims(this.ui[$getExtra]());
44352 uiW += borderDims.w;
44353 uiH += borderDims.h;
44354 if (this.caption) {
44355 const {
44356 w,
44357 h,
44358 isBroken
44359 } = this.caption[$getExtra](availableSpace);
44360 if (isBroken && this[$getSubformParent]()[$isThereMoreWidth]()) {
44361 this[$popPara]();
44362 return HTMLResult.FAILURE;
44363 }
44364 width = w;
44365 height = h;
44366 switch (this.caption.placement) {
44367 case "left":
44368 case "right":
44369 case "inline":
44370 width += uiW;
44371 break;
44372 case "top":
44373 case "bottom":
44374 height += uiH;
44375 break;
44376 }
44377 } else {
44378 width = uiW;
44379 height = uiH;
44380 }
44381 if (width && this.w === "") {
44382 width += marginH;
44383 this.w = Math.min(this.maxW <= 0 ? Infinity : this.maxW, this.minW + 1 < width ? width : this.minW);
44384 }
44385 if (height && this.h === "") {
44386 height += marginV;
44387 this.h = Math.min(this.maxH <= 0 ? Infinity : this.maxH, this.minH + 1 < height ? height : this.minH);
44388 }
44389 }
44390 this[$popPara]();
44391 fixDimensions(this);
44392 setFirstUnsplittable(this);
44393 if (!checkDimensions(this, availableSpace)) {
44394 this.w = savedW;
44395 this.h = savedH;
44396 this[$popPara]();
44397 return HTMLResult.FAILURE;
44398 }
44399 unsetFirstUnsplittable(this);
44400 const style = toStyle(this, "font", "dimensions", "position", "rotate", "anchorType", "presence", "margin", "hAlign");
44401 setMinMaxDimensions(this, style);
44402 const classNames = ["xfaField"];
44403 if (this.font) {
44404 classNames.push("xfaFont");
44405 }
44406 if (isPrintOnly(this)) {
44407 classNames.push("xfaPrintOnly");
44408 }
44409 const attributes = {
44410 style,
44411 id: this[$uid],
44412 class: classNames
44413 };
44414 if (style.margin) {
44415 style.padding = style.margin;
44416 delete style.margin;
44417 }
44418 setAccess(this, classNames);
44419 if (this.name) {
44420 attributes.xfaName = this.name;
44421 }
44422 const children = [];
44423 const html = {
44424 name: "div",
44425 attributes,
44426 children
44427 };
44428 applyAssist(this, attributes);
44429 const borderStyle = this.border ? this.border[$toStyle]() : null;
44430 const bbox = computeBbox(this, html, availableSpace);
44431 const ui = this.ui[$toHTML]().html;
44432 if (!ui) {
44433 Object.assign(style, borderStyle);
44434 return HTMLResult.success(createWrapper(this, html), bbox);
44435 }
44436 if (this[$tabIndex]) {
44437 if (ui.children?.[0]) {
44438 ui.children[0].attributes.tabindex = this[$tabIndex];
44439 } else {
44440 ui.attributes.tabindex = this[$tabIndex];
44441 }
44442 }
44443 if (!ui.attributes.style) {
44444 ui.attributes.style = Object.create(null);
44445 }
44446 let aElement = null;
44447 if (this.ui.button) {
44448 if (ui.children.length === 1) {
44449 [aElement] = ui.children.splice(0, 1);
44450 }
44451 Object.assign(ui.attributes.style, borderStyle);
44452 } else {
44453 Object.assign(style, borderStyle);
44454 }
44455 children.push(ui);
44456 if (this.value) {
44457 if (this.ui.imageEdit) {
44458 ui.children.push(this.value[$toHTML]().html);
44459 } else if (!this.ui.button) {
44460 let value = "";
44461 if (this.value.exData) {
44462 value = this.value.exData[$text]();
44463 } else if (this.value.text) {
44464 value = this.value.text[$getExtra]();
44465 } else {
44466 const htmlValue = this.value[$toHTML]().html;
44467 if (htmlValue !== null) {
44468 value = htmlValue.children[0].value;
44469 }
44470 }
44471 if (this.ui.textEdit && this.value.text?.maxChars) {
44472 ui.children[0].attributes.maxLength = this.value.text.maxChars;
44473 }
44474 if (value) {
44475 if (this.ui.numericEdit) {
44476 value = parseFloat(value);
44477 value = isNaN(value) ? "" : value.toString();
44478 }
44479 if (ui.children[0].name === "textarea") {
44480 ui.children[0].attributes.textContent = value;
44481 } else {
44482 ui.children[0].attributes.value = value;
44483 }
44484 }
44485 }
44486 }
44487 if (!this.ui.imageEdit && ui.children?.[0] && this.h) {
44488 borderDims = borderDims || getBorderDims(this.ui[$getExtra]());
44489 let captionHeight = 0;
44490 if (this.caption && ["top", "bottom"].includes(this.caption.placement)) {
44491 captionHeight = this.caption.reserve;
44492 if (captionHeight <= 0) {
44493 captionHeight = this.caption[$getExtra](availableSpace).h;
44494 }
44495 const inputHeight = this.h - captionHeight - marginV - borderDims.h;
44496 ui.children[0].attributes.style.height = measureToString(inputHeight);
44497 } else {
44498 ui.children[0].attributes.style.height = "100%";
44499 }
44500 }
44501 if (aElement) {
44502 ui.children.push(aElement);
44503 }
44504 if (!caption) {
44505 if (ui.attributes.class) {
44506 ui.attributes.class.push("xfaLeft");
44507 }
44508 this.w = savedW;
44509 this.h = savedH;
44510 return HTMLResult.success(createWrapper(this, html), bbox);
44511 }
44512 if (this.ui.button) {
44513 if (style.padding) {
44514 delete style.padding;
44515 }
44516 if (caption.name === "div") {
44517 caption.name = "span";
44518 }
44519 ui.children.push(caption);
44520 return HTMLResult.success(html, bbox);
44521 } else if (this.ui.checkButton) {
44522 caption.attributes.class[0] = "xfaCaptionForCheckButton";
44523 }
44524 if (!ui.attributes.class) {
44525 ui.attributes.class = [];
44526 }
44527 ui.children.splice(0, 0, caption);
44528 switch (this.caption.placement) {
44529 case "left":
44530 ui.attributes.class.push("xfaLeft");
44531 break;
44532 case "right":
44533 ui.attributes.class.push("xfaRight");
44534 break;
44535 case "top":
44536 ui.attributes.class.push("xfaTop");
44537 break;
44538 case "bottom":
44539 ui.attributes.class.push("xfaBottom");
44540 break;
44541 case "inline":
44542 ui.attributes.class.push("xfaLeft");
44543 break;
44544 }
44545 this.w = savedW;
44546 this.h = savedH;
44547 return HTMLResult.success(createWrapper(this, html), bbox);
44548 }
44549}
44550class Fill extends XFAObject {
44551 constructor(attributes) {
44552 super(TEMPLATE_NS_ID, "fill", true);
44553 this.id = attributes.id || "";
44554 this.presence = getStringOption(attributes.presence, ["visible", "hidden", "inactive", "invisible"]);
44555 this.use = attributes.use || "";
44556 this.usehref = attributes.usehref || "";
44557 this.color = null;
44558 this.extras = null;
44559 this.linear = null;
44560 this.pattern = null;
44561 this.radial = null;
44562 this.solid = null;
44563 this.stipple = null;
44564 }
44565 [$toStyle]() {
44566 const parent = this[$getParent]();
44567 const grandpa = parent[$getParent]();
44568 const ggrandpa = grandpa[$getParent]();
44569 const style = Object.create(null);
44570 let propName = "color";
44571 let altPropName = propName;
44572 if (parent instanceof Border) {
44573 propName = "background-color";
44574 altPropName = "background";
44575 if (ggrandpa instanceof Ui) {
44576 style.backgroundColor = "white";
44577 }
44578 }
44579 if (parent instanceof Rectangle || parent instanceof Arc) {
44580 propName = altPropName = "fill";
44581 style.fill = "white";
44582 }
44583 for (const name of Object.getOwnPropertyNames(this)) {
44584 if (name === "extras" || name === "color") {
44585 continue;
44586 }
44587 const obj = this[name];
44588 if (!(obj instanceof XFAObject)) {
44589 continue;
44590 }
44591 const color = obj[$toStyle](this.color);
44592 if (color) {
44593 style[color.startsWith("#") ? propName : altPropName] = color;
44594 }
44595 return style;
44596 }
44597 if (this.color?.value) {
44598 const color = this.color[$toStyle]();
44599 style[color.startsWith("#") ? propName : altPropName] = color;
44600 }
44601 return style;
44602 }
44603}
44604class Filter extends XFAObject {
44605 constructor(attributes) {
44606 super(TEMPLATE_NS_ID, "filter", true);
44607 this.addRevocationInfo = getStringOption(attributes.addRevocationInfo, ["", "required", "optional", "none"]);
44608 this.id = attributes.id || "";
44609 this.name = attributes.name || "";
44610 this.use = attributes.use || "";
44611 this.usehref = attributes.usehref || "";
44612 this.version = getInteger({
44613 data: this.version,
44614 defaultValue: 5,
44615 validate: x => x >= 1 && x <= 5
44616 });
44617 this.appearanceFilter = null;
44618 this.certificates = null;
44619 this.digestMethods = null;
44620 this.encodings = null;
44621 this.encryptionMethods = null;
44622 this.handler = null;
44623 this.lockDocument = null;
44624 this.mdp = null;
44625 this.reasons = null;
44626 this.timeStamp = null;
44627 }
44628}
44629class Float extends ContentObject {
44630 constructor(attributes) {
44631 super(TEMPLATE_NS_ID, "float");
44632 this.id = attributes.id || "";
44633 this.name = attributes.name || "";
44634 this.use = attributes.use || "";
44635 this.usehref = attributes.usehref || "";
44636 }
44637 [$finalize]() {
44638 const number = parseFloat(this[$content].trim());
44639 this[$content] = isNaN(number) ? null : number;
44640 }
44641 [$toHTML](availableSpace) {
44642 return valueToHtml(this[$content] !== null ? this[$content].toString() : "");
44643 }
44644}
44645class template_Font extends XFAObject {
44646 constructor(attributes) {
44647 super(TEMPLATE_NS_ID, "font", true);
44648 this.baselineShift = getMeasurement(attributes.baselineShift);
44649 this.fontHorizontalScale = getFloat({
44650 data: attributes.fontHorizontalScale,
44651 defaultValue: 100,
44652 validate: x => x >= 0
44653 });
44654 this.fontVerticalScale = getFloat({
44655 data: attributes.fontVerticalScale,
44656 defaultValue: 100,
44657 validate: x => x >= 0
44658 });
44659 this.id = attributes.id || "";
44660 this.kerningMode = getStringOption(attributes.kerningMode, ["none", "pair"]);
44661 this.letterSpacing = getMeasurement(attributes.letterSpacing, "0");
44662 this.lineThrough = getInteger({
44663 data: attributes.lineThrough,
44664 defaultValue: 0,
44665 validate: x => x === 1 || x === 2
44666 });
44667 this.lineThroughPeriod = getStringOption(attributes.lineThroughPeriod, ["all", "word"]);
44668 this.overline = getInteger({
44669 data: attributes.overline,
44670 defaultValue: 0,
44671 validate: x => x === 1 || x === 2
44672 });
44673 this.overlinePeriod = getStringOption(attributes.overlinePeriod, ["all", "word"]);
44674 this.posture = getStringOption(attributes.posture, ["normal", "italic"]);
44675 this.size = getMeasurement(attributes.size, "10pt");
44676 this.typeface = attributes.typeface || "Courier";
44677 this.underline = getInteger({
44678 data: attributes.underline,
44679 defaultValue: 0,
44680 validate: x => x === 1 || x === 2
44681 });
44682 this.underlinePeriod = getStringOption(attributes.underlinePeriod, ["all", "word"]);
44683 this.use = attributes.use || "";
44684 this.usehref = attributes.usehref || "";
44685 this.weight = getStringOption(attributes.weight, ["normal", "bold"]);
44686 this.extras = null;
44687 this.fill = null;
44688 }
44689 [$clean](builder) {
44690 super[$clean](builder);
44691 this[$globalData].usedTypefaces.add(this.typeface);
44692 }
44693 [$toStyle]() {
44694 const style = toStyle(this, "fill");
44695 const color = style.color;
44696 if (color) {
44697 if (color === "#000000") {
44698 delete style.color;
44699 } else if (!color.startsWith("#")) {
44700 style.background = color;
44701 style.backgroundClip = "text";
44702 style.color = "transparent";
44703 }
44704 }
44705 if (this.baselineShift) {
44706 style.verticalAlign = measureToString(this.baselineShift);
44707 }
44708 style.fontKerning = this.kerningMode === "none" ? "none" : "normal";
44709 style.letterSpacing = measureToString(this.letterSpacing);
44710 if (this.lineThrough !== 0) {
44711 style.textDecoration = "line-through";
44712 if (this.lineThrough === 2) {
44713 style.textDecorationStyle = "double";
44714 }
44715 }
44716 if (this.overline !== 0) {
44717 style.textDecoration = "overline";
44718 if (this.overline === 2) {
44719 style.textDecorationStyle = "double";
44720 }
44721 }
44722 style.fontStyle = this.posture;
44723 style.fontSize = measureToString(0.99 * this.size);
44724 setFontFamily(this, this, this[$globalData].fontFinder, style);
44725 if (this.underline !== 0) {
44726 style.textDecoration = "underline";
44727 if (this.underline === 2) {
44728 style.textDecorationStyle = "double";
44729 }
44730 }
44731 style.fontWeight = this.weight;
44732 return style;
44733 }
44734}
44735class Format extends XFAObject {
44736 constructor(attributes) {
44737 super(TEMPLATE_NS_ID, "format", true);
44738 this.id = attributes.id || "";
44739 this.use = attributes.use || "";
44740 this.usehref = attributes.usehref || "";
44741 this.extras = null;
44742 this.picture = null;
44743 }
44744}
44745class Handler extends StringObject {
44746 constructor(attributes) {
44747 super(TEMPLATE_NS_ID, "handler");
44748 this.id = attributes.id || "";
44749 this.type = getStringOption(attributes.type, ["optional", "required"]);
44750 this.use = attributes.use || "";
44751 this.usehref = attributes.usehref || "";
44752 }
44753}
44754class Hyphenation extends XFAObject {
44755 constructor(attributes) {
44756 super(TEMPLATE_NS_ID, "hyphenation");
44757 this.excludeAllCaps = getInteger({
44758 data: attributes.excludeAllCaps,
44759 defaultValue: 0,
44760 validate: x => x === 1
44761 });
44762 this.excludeInitialCap = getInteger({
44763 data: attributes.excludeInitialCap,
44764 defaultValue: 0,
44765 validate: x => x === 1
44766 });
44767 this.hyphenate = getInteger({
44768 data: attributes.hyphenate,
44769 defaultValue: 0,
44770 validate: x => x === 1
44771 });
44772 this.id = attributes.id || "";
44773 this.pushCharacterCount = getInteger({
44774 data: attributes.pushCharacterCount,
44775 defaultValue: 3,
44776 validate: x => x >= 0
44777 });
44778 this.remainCharacterCount = getInteger({
44779 data: attributes.remainCharacterCount,
44780 defaultValue: 3,
44781 validate: x => x >= 0
44782 });
44783 this.use = attributes.use || "";
44784 this.usehref = attributes.usehref || "";
44785 this.wordCharacterCount = getInteger({
44786 data: attributes.wordCharacterCount,
44787 defaultValue: 7,
44788 validate: x => x >= 0
44789 });
44790 }
44791}
44792class Image extends StringObject {
44793 constructor(attributes) {
44794 super(TEMPLATE_NS_ID, "image");
44795 this.aspect = getStringOption(attributes.aspect, ["fit", "actual", "height", "none", "width"]);
44796 this.contentType = attributes.contentType || "";
44797 this.href = attributes.href || "";
44798 this.id = attributes.id || "";
44799 this.name = attributes.name || "";
44800 this.transferEncoding = getStringOption(attributes.transferEncoding, ["base64", "none", "package"]);
44801 this.use = attributes.use || "";
44802 this.usehref = attributes.usehref || "";
44803 }
44804 [$toHTML]() {
44805 if (this.contentType && !MIMES.has(this.contentType.toLowerCase())) {
44806 return HTMLResult.EMPTY;
44807 }
44808 let buffer = this[$globalData].images && this[$globalData].images.get(this.href);
44809 if (!buffer && (this.href || !this[$content])) {
44810 return HTMLResult.EMPTY;
44811 }
44812 if (!buffer && this.transferEncoding === "base64") {
44813 buffer = stringToBytes(atob(this[$content]));
44814 }
44815 if (!buffer) {
44816 return HTMLResult.EMPTY;
44817 }
44818 if (!this.contentType) {
44819 for (const [header, type] of IMAGES_HEADERS) {
44820 if (buffer.length > header.length && header.every((x, i) => x === buffer[i])) {
44821 this.contentType = type;
44822 break;
44823 }
44824 }
44825 if (!this.contentType) {
44826 return HTMLResult.EMPTY;
44827 }
44828 }
44829 const blob = new Blob([buffer], {
44830 type: this.contentType
44831 });
44832 let style;
44833 switch (this.aspect) {
44834 case "fit":
44835 case "actual":
44836 break;
44837 case "height":
44838 style = {
44839 height: "100%",
44840 objectFit: "fill"
44841 };
44842 break;
44843 case "none":
44844 style = {
44845 width: "100%",
44846 height: "100%",
44847 objectFit: "fill"
44848 };
44849 break;
44850 case "width":
44851 style = {
44852 width: "100%",
44853 objectFit: "fill"
44854 };
44855 break;
44856 }
44857 const parent = this[$getParent]();
44858 return HTMLResult.success({
44859 name: "img",
44860 attributes: {
44861 class: ["xfaImage"],
44862 style,
44863 src: URL.createObjectURL(blob),
44864 alt: parent ? ariaLabel(parent[$getParent]()) : null
44865 }
44866 });
44867 }
44868}
44869class ImageEdit extends XFAObject {
44870 constructor(attributes) {
44871 super(TEMPLATE_NS_ID, "imageEdit", true);
44872 this.data = getStringOption(attributes.data, ["link", "embed"]);
44873 this.id = attributes.id || "";
44874 this.use = attributes.use || "";
44875 this.usehref = attributes.usehref || "";
44876 this.border = null;
44877 this.extras = null;
44878 this.margin = null;
44879 }
44880 [$toHTML](availableSpace) {
44881 if (this.data === "embed") {
44882 return HTMLResult.success({
44883 name: "div",
44884 children: [],
44885 attributes: {}
44886 });
44887 }
44888 return HTMLResult.EMPTY;
44889 }
44890}
44891class Integer extends ContentObject {
44892 constructor(attributes) {
44893 super(TEMPLATE_NS_ID, "integer");
44894 this.id = attributes.id || "";
44895 this.name = attributes.name || "";
44896 this.use = attributes.use || "";
44897 this.usehref = attributes.usehref || "";
44898 }
44899 [$finalize]() {
44900 const number = parseInt(this[$content].trim(), 10);
44901 this[$content] = isNaN(number) ? null : number;
44902 }
44903 [$toHTML](availableSpace) {
44904 return valueToHtml(this[$content] !== null ? this[$content].toString() : "");
44905 }
44906}
44907class Issuers extends XFAObject {
44908 constructor(attributes) {
44909 super(TEMPLATE_NS_ID, "issuers", true);
44910 this.id = attributes.id || "";
44911 this.type = getStringOption(attributes.type, ["optional", "required"]);
44912 this.use = attributes.use || "";
44913 this.usehref = attributes.usehref || "";
44914 this.certificate = new XFAObjectArray();
44915 }
44916}
44917class Items extends XFAObject {
44918 constructor(attributes) {
44919 super(TEMPLATE_NS_ID, "items", true);
44920 this.id = attributes.id || "";
44921 this.name = attributes.name || "";
44922 this.presence = getStringOption(attributes.presence, ["visible", "hidden", "inactive", "invisible"]);
44923 this.ref = attributes.ref || "";
44924 this.save = getInteger({
44925 data: attributes.save,
44926 defaultValue: 0,
44927 validate: x => x === 1
44928 });
44929 this.use = attributes.use || "";
44930 this.usehref = attributes.usehref || "";
44931 this.boolean = new XFAObjectArray();
44932 this.date = new XFAObjectArray();
44933 this.dateTime = new XFAObjectArray();
44934 this.decimal = new XFAObjectArray();
44935 this.exData = new XFAObjectArray();
44936 this.float = new XFAObjectArray();
44937 this.image = new XFAObjectArray();
44938 this.integer = new XFAObjectArray();
44939 this.text = new XFAObjectArray();
44940 this.time = new XFAObjectArray();
44941 }
44942 [$toHTML]() {
44943 const output = [];
44944 for (const child of this[$getChildren]()) {
44945 output.push(child[$text]());
44946 }
44947 return HTMLResult.success(output);
44948 }
44949}
44950class Keep extends XFAObject {
44951 constructor(attributes) {
44952 super(TEMPLATE_NS_ID, "keep", true);
44953 this.id = attributes.id || "";
44954 const options = ["none", "contentArea", "pageArea"];
44955 this.intact = getStringOption(attributes.intact, options);
44956 this.next = getStringOption(attributes.next, options);
44957 this.previous = getStringOption(attributes.previous, options);
44958 this.use = attributes.use || "";
44959 this.usehref = attributes.usehref || "";
44960 this.extras = null;
44961 }
44962}
44963class KeyUsage extends XFAObject {
44964 constructor(attributes) {
44965 super(TEMPLATE_NS_ID, "keyUsage");
44966 const options = ["", "yes", "no"];
44967 this.crlSign = getStringOption(attributes.crlSign, options);
44968 this.dataEncipherment = getStringOption(attributes.dataEncipherment, options);
44969 this.decipherOnly = getStringOption(attributes.decipherOnly, options);
44970 this.digitalSignature = getStringOption(attributes.digitalSignature, options);
44971 this.encipherOnly = getStringOption(attributes.encipherOnly, options);
44972 this.id = attributes.id || "";
44973 this.keyAgreement = getStringOption(attributes.keyAgreement, options);
44974 this.keyCertSign = getStringOption(attributes.keyCertSign, options);
44975 this.keyEncipherment = getStringOption(attributes.keyEncipherment, options);
44976 this.nonRepudiation = getStringOption(attributes.nonRepudiation, options);
44977 this.type = getStringOption(attributes.type, ["optional", "required"]);
44978 this.use = attributes.use || "";
44979 this.usehref = attributes.usehref || "";
44980 }
44981}
44982class Line extends XFAObject {
44983 constructor(attributes) {
44984 super(TEMPLATE_NS_ID, "line", true);
44985 this.hand = getStringOption(attributes.hand, ["even", "left", "right"]);
44986 this.id = attributes.id || "";
44987 this.slope = getStringOption(attributes.slope, ["\\", "/"]);
44988 this.use = attributes.use || "";
44989 this.usehref = attributes.usehref || "";
44990 this.edge = null;
44991 }
44992 [$toHTML]() {
44993 const parent = this[$getParent]()[$getParent]();
44994 const edge = this.edge || new Edge({});
44995 const edgeStyle = edge[$toStyle]();
44996 const style = Object.create(null);
44997 const thickness = edge.presence === "visible" ? edge.thickness : 0;
44998 style.strokeWidth = measureToString(thickness);
44999 style.stroke = edgeStyle.color;
45000 let x1, y1, x2, y2;
45001 let width = "100%";
45002 let height = "100%";
45003 if (parent.w <= thickness) {
45004 [x1, y1, x2, y2] = ["50%", 0, "50%", "100%"];
45005 width = style.strokeWidth;
45006 } else if (parent.h <= thickness) {
45007 [x1, y1, x2, y2] = [0, "50%", "100%", "50%"];
45008 height = style.strokeWidth;
45009 } else if (this.slope === "\\") {
45010 [x1, y1, x2, y2] = [0, 0, "100%", "100%"];
45011 } else {
45012 [x1, y1, x2, y2] = [0, "100%", "100%", 0];
45013 }
45014 const line = {
45015 name: "line",
45016 attributes: {
45017 xmlns: SVG_NS,
45018 x1,
45019 y1,
45020 x2,
45021 y2,
45022 style
45023 }
45024 };
45025 const svg = {
45026 name: "svg",
45027 children: [line],
45028 attributes: {
45029 xmlns: SVG_NS,
45030 width,
45031 height,
45032 style: {
45033 overflow: "visible"
45034 }
45035 }
45036 };
45037 if (hasMargin(parent)) {
45038 return HTMLResult.success({
45039 name: "div",
45040 attributes: {
45041 style: {
45042 display: "inline",
45043 width: "100%",
45044 height: "100%"
45045 }
45046 },
45047 children: [svg]
45048 });
45049 }
45050 svg.attributes.style.position = "absolute";
45051 return HTMLResult.success(svg);
45052 }
45053}
45054class Linear extends XFAObject {
45055 constructor(attributes) {
45056 super(TEMPLATE_NS_ID, "linear", true);
45057 this.id = attributes.id || "";
45058 this.type = getStringOption(attributes.type, ["toRight", "toBottom", "toLeft", "toTop"]);
45059 this.use = attributes.use || "";
45060 this.usehref = attributes.usehref || "";
45061 this.color = null;
45062 this.extras = null;
45063 }
45064 [$toStyle](startColor) {
45065 startColor = startColor ? startColor[$toStyle]() : "#FFFFFF";
45066 const transf = this.type.replace(/([RBLT])/, " $1").toLowerCase();
45067 const endColor = this.color ? this.color[$toStyle]() : "#000000";
45068 return `linear-gradient(${transf}, ${startColor}, ${endColor})`;
45069 }
45070}
45071class LockDocument extends ContentObject {
45072 constructor(attributes) {
45073 super(TEMPLATE_NS_ID, "lockDocument");
45074 this.id = attributes.id || "";
45075 this.type = getStringOption(attributes.type, ["optional", "required"]);
45076 this.use = attributes.use || "";
45077 this.usehref = attributes.usehref || "";
45078 }
45079 [$finalize]() {
45080 this[$content] = getStringOption(this[$content], ["auto", "0", "1"]);
45081 }
45082}
45083class Manifest extends XFAObject {
45084 constructor(attributes) {
45085 super(TEMPLATE_NS_ID, "manifest", true);
45086 this.action = getStringOption(attributes.action, ["include", "all", "exclude"]);
45087 this.id = attributes.id || "";
45088 this.name = attributes.name || "";
45089 this.use = attributes.use || "";
45090 this.usehref = attributes.usehref || "";
45091 this.extras = null;
45092 this.ref = new XFAObjectArray();
45093 }
45094}
45095class Margin extends XFAObject {
45096 constructor(attributes) {
45097 super(TEMPLATE_NS_ID, "margin", true);
45098 this.bottomInset = getMeasurement(attributes.bottomInset, "0");
45099 this.id = attributes.id || "";
45100 this.leftInset = getMeasurement(attributes.leftInset, "0");
45101 this.rightInset = getMeasurement(attributes.rightInset, "0");
45102 this.topInset = getMeasurement(attributes.topInset, "0");
45103 this.use = attributes.use || "";
45104 this.usehref = attributes.usehref || "";
45105 this.extras = null;
45106 }
45107 [$toStyle]() {
45108 return {
45109 margin: measureToString(this.topInset) + " " + measureToString(this.rightInset) + " " + measureToString(this.bottomInset) + " " + measureToString(this.leftInset)
45110 };
45111 }
45112}
45113class Mdp extends XFAObject {
45114 constructor(attributes) {
45115 super(TEMPLATE_NS_ID, "mdp");
45116 this.id = attributes.id || "";
45117 this.permissions = getInteger({
45118 data: attributes.permissions,
45119 defaultValue: 2,
45120 validate: x => x === 1 || x === 3
45121 });
45122 this.signatureType = getStringOption(attributes.signatureType, ["filler", "author"]);
45123 this.use = attributes.use || "";
45124 this.usehref = attributes.usehref || "";
45125 }
45126}
45127class Medium extends XFAObject {
45128 constructor(attributes) {
45129 super(TEMPLATE_NS_ID, "medium");
45130 this.id = attributes.id || "";
45131 this.imagingBBox = getBBox(attributes.imagingBBox);
45132 this.long = getMeasurement(attributes.long);
45133 this.orientation = getStringOption(attributes.orientation, ["portrait", "landscape"]);
45134 this.short = getMeasurement(attributes.short);
45135 this.stock = attributes.stock || "";
45136 this.trayIn = getStringOption(attributes.trayIn, ["auto", "delegate", "pageFront"]);
45137 this.trayOut = getStringOption(attributes.trayOut, ["auto", "delegate"]);
45138 this.use = attributes.use || "";
45139 this.usehref = attributes.usehref || "";
45140 }
45141}
45142class Message extends XFAObject {
45143 constructor(attributes) {
45144 super(TEMPLATE_NS_ID, "message", true);
45145 this.id = attributes.id || "";
45146 this.use = attributes.use || "";
45147 this.usehref = attributes.usehref || "";
45148 this.text = new XFAObjectArray();
45149 }
45150}
45151class NumericEdit extends XFAObject {
45152 constructor(attributes) {
45153 super(TEMPLATE_NS_ID, "numericEdit", true);
45154 this.hScrollPolicy = getStringOption(attributes.hScrollPolicy, ["auto", "off", "on"]);
45155 this.id = attributes.id || "";
45156 this.use = attributes.use || "";
45157 this.usehref = attributes.usehref || "";
45158 this.border = null;
45159 this.comb = null;
45160 this.extras = null;
45161 this.margin = null;
45162 }
45163 [$toHTML](availableSpace) {
45164 const style = toStyle(this, "border", "font", "margin");
45165 const field = this[$getParent]()[$getParent]();
45166 const html = {
45167 name: "input",
45168 attributes: {
45169 type: "text",
45170 fieldId: field[$uid],
45171 dataId: field[$data]?.[$uid] || field[$uid],
45172 class: ["xfaTextfield"],
45173 style,
45174 "aria-label": ariaLabel(field),
45175 "aria-required": false
45176 }
45177 };
45178 if (isRequired(field)) {
45179 html.attributes["aria-required"] = true;
45180 html.attributes.required = true;
45181 }
45182 return HTMLResult.success({
45183 name: "label",
45184 attributes: {
45185 class: ["xfaLabel"]
45186 },
45187 children: [html]
45188 });
45189 }
45190}
45191class Occur extends XFAObject {
45192 constructor(attributes) {
45193 super(TEMPLATE_NS_ID, "occur", true);
45194 this.id = attributes.id || "";
45195 this.initial = attributes.initial !== "" ? getInteger({
45196 data: attributes.initial,
45197 defaultValue: "",
45198 validate: x => true
45199 }) : "";
45200 this.max = attributes.max !== "" ? getInteger({
45201 data: attributes.max,
45202 defaultValue: 1,
45203 validate: x => true
45204 }) : "";
45205 this.min = attributes.min !== "" ? getInteger({
45206 data: attributes.min,
45207 defaultValue: 1,
45208 validate: x => true
45209 }) : "";
45210 this.use = attributes.use || "";
45211 this.usehref = attributes.usehref || "";
45212 this.extras = null;
45213 }
45214 [$clean]() {
45215 const parent = this[$getParent]();
45216 const originalMin = this.min;
45217 if (this.min === "") {
45218 this.min = parent instanceof PageArea || parent instanceof PageSet ? 0 : 1;
45219 }
45220 if (this.max === "") {
45221 if (originalMin === "") {
45222 this.max = parent instanceof PageArea || parent instanceof PageSet ? -1 : 1;
45223 } else {
45224 this.max = this.min;
45225 }
45226 }
45227 if (this.max !== -1 && this.max < this.min) {
45228 this.max = this.min;
45229 }
45230 if (this.initial === "") {
45231 this.initial = parent instanceof Template ? 1 : this.min;
45232 }
45233 }
45234}
45235class Oid extends StringObject {
45236 constructor(attributes) {
45237 super(TEMPLATE_NS_ID, "oid");
45238 this.id = attributes.id || "";
45239 this.name = attributes.name || "";
45240 this.use = attributes.use || "";
45241 this.usehref = attributes.usehref || "";
45242 }
45243}
45244class Oids extends XFAObject {
45245 constructor(attributes) {
45246 super(TEMPLATE_NS_ID, "oids", true);
45247 this.id = attributes.id || "";
45248 this.type = getStringOption(attributes.type, ["optional", "required"]);
45249 this.use = attributes.use || "";
45250 this.usehref = attributes.usehref || "";
45251 this.oid = new XFAObjectArray();
45252 }
45253}
45254class Overflow extends XFAObject {
45255 constructor(attributes) {
45256 super(TEMPLATE_NS_ID, "overflow");
45257 this.id = attributes.id || "";
45258 this.leader = attributes.leader || "";
45259 this.target = attributes.target || "";
45260 this.trailer = attributes.trailer || "";
45261 this.use = attributes.use || "";
45262 this.usehref = attributes.usehref || "";
45263 }
45264 [$getExtra]() {
45265 if (!this[$extra]) {
45266 const parent = this[$getParent]();
45267 const root = this[$getTemplateRoot]();
45268 const target = root[$searchNode](this.target, parent);
45269 const leader = root[$searchNode](this.leader, parent);
45270 const trailer = root[$searchNode](this.trailer, parent);
45271 this[$extra] = {
45272 target: target?.[0] || null,
45273 leader: leader?.[0] || null,
45274 trailer: trailer?.[0] || null,
45275 addLeader: false,
45276 addTrailer: false
45277 };
45278 }
45279 return this[$extra];
45280 }
45281}
45282class PageArea extends XFAObject {
45283 constructor(attributes) {
45284 super(TEMPLATE_NS_ID, "pageArea", true);
45285 this.blankOrNotBlank = getStringOption(attributes.blankOrNotBlank, ["any", "blank", "notBlank"]);
45286 this.id = attributes.id || "";
45287 this.initialNumber = getInteger({
45288 data: attributes.initialNumber,
45289 defaultValue: 1,
45290 validate: x => true
45291 });
45292 this.name = attributes.name || "";
45293 this.numbered = getInteger({
45294 data: attributes.numbered,
45295 defaultValue: 1,
45296 validate: x => true
45297 });
45298 this.oddOrEven = getStringOption(attributes.oddOrEven, ["any", "even", "odd"]);
45299 this.pagePosition = getStringOption(attributes.pagePosition, ["any", "first", "last", "only", "rest"]);
45300 this.relevant = getRelevant(attributes.relevant);
45301 this.use = attributes.use || "";
45302 this.usehref = attributes.usehref || "";
45303 this.desc = null;
45304 this.extras = null;
45305 this.medium = null;
45306 this.occur = null;
45307 this.area = new XFAObjectArray();
45308 this.contentArea = new XFAObjectArray();
45309 this.draw = new XFAObjectArray();
45310 this.exclGroup = new XFAObjectArray();
45311 this.field = new XFAObjectArray();
45312 this.subform = new XFAObjectArray();
45313 }
45314 [$isUsable]() {
45315 if (!this[$extra]) {
45316 this[$extra] = {
45317 numberOfUse: 0
45318 };
45319 return true;
45320 }
45321 return !this.occur || this.occur.max === -1 || this[$extra].numberOfUse < this.occur.max;
45322 }
45323 [$cleanPage]() {
45324 delete this[$extra];
45325 }
45326 [$getNextPage]() {
45327 if (!this[$extra]) {
45328 this[$extra] = {
45329 numberOfUse: 0
45330 };
45331 }
45332 const parent = this[$getParent]();
45333 if (parent.relation === "orderedOccurrence") {
45334 if (this[$isUsable]()) {
45335 this[$extra].numberOfUse += 1;
45336 return this;
45337 }
45338 }
45339 return parent[$getNextPage]();
45340 }
45341 [$getAvailableSpace]() {
45342 return this[$extra].space || {
45343 width: 0,
45344 height: 0
45345 };
45346 }
45347 [$toHTML]() {
45348 if (!this[$extra]) {
45349 this[$extra] = {
45350 numberOfUse: 1
45351 };
45352 }
45353 const children = [];
45354 this[$extra].children = children;
45355 const style = Object.create(null);
45356 if (this.medium && this.medium.short && this.medium.long) {
45357 style.width = measureToString(this.medium.short);
45358 style.height = measureToString(this.medium.long);
45359 this[$extra].space = {
45360 width: this.medium.short,
45361 height: this.medium.long
45362 };
45363 if (this.medium.orientation === "landscape") {
45364 const x = style.width;
45365 style.width = style.height;
45366 style.height = x;
45367 this[$extra].space = {
45368 width: this.medium.long,
45369 height: this.medium.short
45370 };
45371 }
45372 } else {
45373 warn("XFA - No medium specified in pageArea: please file a bug.");
45374 }
45375 this[$childrenToHTML]({
45376 filter: new Set(["area", "draw", "field", "subform"]),
45377 include: true
45378 });
45379 this[$childrenToHTML]({
45380 filter: new Set(["contentArea"]),
45381 include: true
45382 });
45383 return HTMLResult.success({
45384 name: "div",
45385 children,
45386 attributes: {
45387 class: ["xfaPage"],
45388 id: this[$uid],
45389 style,
45390 xfaName: this.name
45391 }
45392 });
45393 }
45394}
45395class PageSet extends XFAObject {
45396 constructor(attributes) {
45397 super(TEMPLATE_NS_ID, "pageSet", true);
45398 this.duplexImposition = getStringOption(attributes.duplexImposition, ["longEdge", "shortEdge"]);
45399 this.id = attributes.id || "";
45400 this.name = attributes.name || "";
45401 this.relation = getStringOption(attributes.relation, ["orderedOccurrence", "duplexPaginated", "simplexPaginated"]);
45402 this.relevant = getRelevant(attributes.relevant);
45403 this.use = attributes.use || "";
45404 this.usehref = attributes.usehref || "";
45405 this.extras = null;
45406 this.occur = null;
45407 this.pageArea = new XFAObjectArray();
45408 this.pageSet = new XFAObjectArray();
45409 }
45410 [$cleanPage]() {
45411 for (const page of this.pageArea.children) {
45412 page[$cleanPage]();
45413 }
45414 for (const page of this.pageSet.children) {
45415 page[$cleanPage]();
45416 }
45417 }
45418 [$isUsable]() {
45419 return !this.occur || this.occur.max === -1 || this[$extra].numberOfUse < this.occur.max;
45420 }
45421 [$getNextPage]() {
45422 if (!this[$extra]) {
45423 this[$extra] = {
45424 numberOfUse: 1,
45425 pageIndex: -1,
45426 pageSetIndex: -1
45427 };
45428 }
45429 if (this.relation === "orderedOccurrence") {
45430 if (this[$extra].pageIndex + 1 < this.pageArea.children.length) {
45431 this[$extra].pageIndex += 1;
45432 const pageArea = this.pageArea.children[this[$extra].pageIndex];
45433 return pageArea[$getNextPage]();
45434 }
45435 if (this[$extra].pageSetIndex + 1 < this.pageSet.children.length) {
45436 this[$extra].pageSetIndex += 1;
45437 return this.pageSet.children[this[$extra].pageSetIndex][$getNextPage]();
45438 }
45439 if (this[$isUsable]()) {
45440 this[$extra].numberOfUse += 1;
45441 this[$extra].pageIndex = -1;
45442 this[$extra].pageSetIndex = -1;
45443 return this[$getNextPage]();
45444 }
45445 const parent = this[$getParent]();
45446 if (parent instanceof PageSet) {
45447 return parent[$getNextPage]();
45448 }
45449 this[$cleanPage]();
45450 return this[$getNextPage]();
45451 }
45452 const pageNumber = this[$getTemplateRoot]()[$extra].pageNumber;
45453 const parity = pageNumber % 2 === 0 ? "even" : "odd";
45454 const position = pageNumber === 0 ? "first" : "rest";
45455 let page = this.pageArea.children.find(p => p.oddOrEven === parity && p.pagePosition === position);
45456 if (page) {
45457 return page;
45458 }
45459 page = this.pageArea.children.find(p => p.oddOrEven === "any" && p.pagePosition === position);
45460 if (page) {
45461 return page;
45462 }
45463 page = this.pageArea.children.find(p => p.oddOrEven === "any" && p.pagePosition === "any");
45464 if (page) {
45465 return page;
45466 }
45467 return this.pageArea.children[0];
45468 }
45469}
45470class Para extends XFAObject {
45471 constructor(attributes) {
45472 super(TEMPLATE_NS_ID, "para", true);
45473 this.hAlign = getStringOption(attributes.hAlign, ["left", "center", "justify", "justifyAll", "radix", "right"]);
45474 this.id = attributes.id || "";
45475 this.lineHeight = attributes.lineHeight ? getMeasurement(attributes.lineHeight, "0pt") : "";
45476 this.marginLeft = attributes.marginLeft ? getMeasurement(attributes.marginLeft, "0pt") : "";
45477 this.marginRight = attributes.marginRight ? getMeasurement(attributes.marginRight, "0pt") : "";
45478 this.orphans = getInteger({
45479 data: attributes.orphans,
45480 defaultValue: 0,
45481 validate: x => x >= 0
45482 });
45483 this.preserve = attributes.preserve || "";
45484 this.radixOffset = attributes.radixOffset ? getMeasurement(attributes.radixOffset, "0pt") : "";
45485 this.spaceAbove = attributes.spaceAbove ? getMeasurement(attributes.spaceAbove, "0pt") : "";
45486 this.spaceBelow = attributes.spaceBelow ? getMeasurement(attributes.spaceBelow, "0pt") : "";
45487 this.tabDefault = attributes.tabDefault ? getMeasurement(this.tabDefault) : "";
45488 this.tabStops = (attributes.tabStops || "").trim().split(/\s+/).map((x, i) => i % 2 === 1 ? getMeasurement(x) : x);
45489 this.textIndent = attributes.textIndent ? getMeasurement(attributes.textIndent, "0pt") : "";
45490 this.use = attributes.use || "";
45491 this.usehref = attributes.usehref || "";
45492 this.vAlign = getStringOption(attributes.vAlign, ["top", "bottom", "middle"]);
45493 this.widows = getInteger({
45494 data: attributes.widows,
45495 defaultValue: 0,
45496 validate: x => x >= 0
45497 });
45498 this.hyphenation = null;
45499 }
45500 [$toStyle]() {
45501 const style = toStyle(this, "hAlign");
45502 if (this.marginLeft !== "") {
45503 style.paddingLeft = measureToString(this.marginLeft);
45504 }
45505 if (this.marginRight !== "") {
45506 style.paddingight = measureToString(this.marginRight);
45507 }
45508 if (this.spaceAbove !== "") {
45509 style.paddingTop = measureToString(this.spaceAbove);
45510 }
45511 if (this.spaceBelow !== "") {
45512 style.paddingBottom = measureToString(this.spaceBelow);
45513 }
45514 if (this.textIndent !== "") {
45515 style.textIndent = measureToString(this.textIndent);
45516 fixTextIndent(style);
45517 }
45518 if (this.lineHeight > 0) {
45519 style.lineHeight = measureToString(this.lineHeight);
45520 }
45521 if (this.tabDefault !== "") {
45522 style.tabSize = measureToString(this.tabDefault);
45523 }
45524 if (this.tabStops.length > 0) {}
45525 if (this.hyphenatation) {
45526 Object.assign(style, this.hyphenatation[$toStyle]());
45527 }
45528 return style;
45529 }
45530}
45531class PasswordEdit extends XFAObject {
45532 constructor(attributes) {
45533 super(TEMPLATE_NS_ID, "passwordEdit", true);
45534 this.hScrollPolicy = getStringOption(attributes.hScrollPolicy, ["auto", "off", "on"]);
45535 this.id = attributes.id || "";
45536 this.passwordChar = attributes.passwordChar || "*";
45537 this.use = attributes.use || "";
45538 this.usehref = attributes.usehref || "";
45539 this.border = null;
45540 this.extras = null;
45541 this.margin = null;
45542 }
45543}
45544class template_Pattern extends XFAObject {
45545 constructor(attributes) {
45546 super(TEMPLATE_NS_ID, "pattern", true);
45547 this.id = attributes.id || "";
45548 this.type = getStringOption(attributes.type, ["crossHatch", "crossDiagonal", "diagonalLeft", "diagonalRight", "horizontal", "vertical"]);
45549 this.use = attributes.use || "";
45550 this.usehref = attributes.usehref || "";
45551 this.color = null;
45552 this.extras = null;
45553 }
45554 [$toStyle](startColor) {
45555 startColor = startColor ? startColor[$toStyle]() : "#FFFFFF";
45556 const endColor = this.color ? this.color[$toStyle]() : "#000000";
45557 const width = 5;
45558 const cmd = "repeating-linear-gradient";
45559 const colors = `${startColor},${startColor} ${width}px,${endColor} ${width}px,${endColor} ${2 * width}px`;
45560 switch (this.type) {
45561 case "crossHatch":
45562 return `${cmd}(to top,${colors}) ${cmd}(to right,${colors})`;
45563 case "crossDiagonal":
45564 return `${cmd}(45deg,${colors}) ${cmd}(-45deg,${colors})`;
45565 case "diagonalLeft":
45566 return `${cmd}(45deg,${colors})`;
45567 case "diagonalRight":
45568 return `${cmd}(-45deg,${colors})`;
45569 case "horizontal":
45570 return `${cmd}(to top,${colors})`;
45571 case "vertical":
45572 return `${cmd}(to right,${colors})`;
45573 }
45574 return "";
45575 }
45576}
45577class Picture extends StringObject {
45578 constructor(attributes) {
45579 super(TEMPLATE_NS_ID, "picture");
45580 this.id = attributes.id || "";
45581 this.use = attributes.use || "";
45582 this.usehref = attributes.usehref || "";
45583 }
45584}
45585class Proto extends XFAObject {
45586 constructor(attributes) {
45587 super(TEMPLATE_NS_ID, "proto", true);
45588 this.appearanceFilter = new XFAObjectArray();
45589 this.arc = new XFAObjectArray();
45590 this.area = new XFAObjectArray();
45591 this.assist = new XFAObjectArray();
45592 this.barcode = new XFAObjectArray();
45593 this.bindItems = new XFAObjectArray();
45594 this.bookend = new XFAObjectArray();
45595 this.boolean = new XFAObjectArray();
45596 this.border = new XFAObjectArray();
45597 this.break = new XFAObjectArray();
45598 this.breakAfter = new XFAObjectArray();
45599 this.breakBefore = new XFAObjectArray();
45600 this.button = new XFAObjectArray();
45601 this.calculate = new XFAObjectArray();
45602 this.caption = new XFAObjectArray();
45603 this.certificate = new XFAObjectArray();
45604 this.certificates = new XFAObjectArray();
45605 this.checkButton = new XFAObjectArray();
45606 this.choiceList = new XFAObjectArray();
45607 this.color = new XFAObjectArray();
45608 this.comb = new XFAObjectArray();
45609 this.connect = new XFAObjectArray();
45610 this.contentArea = new XFAObjectArray();
45611 this.corner = new XFAObjectArray();
45612 this.date = new XFAObjectArray();
45613 this.dateTime = new XFAObjectArray();
45614 this.dateTimeEdit = new XFAObjectArray();
45615 this.decimal = new XFAObjectArray();
45616 this.defaultUi = new XFAObjectArray();
45617 this.desc = new XFAObjectArray();
45618 this.digestMethod = new XFAObjectArray();
45619 this.digestMethods = new XFAObjectArray();
45620 this.draw = new XFAObjectArray();
45621 this.edge = new XFAObjectArray();
45622 this.encoding = new XFAObjectArray();
45623 this.encodings = new XFAObjectArray();
45624 this.encrypt = new XFAObjectArray();
45625 this.encryptData = new XFAObjectArray();
45626 this.encryption = new XFAObjectArray();
45627 this.encryptionMethod = new XFAObjectArray();
45628 this.encryptionMethods = new XFAObjectArray();
45629 this.event = new XFAObjectArray();
45630 this.exData = new XFAObjectArray();
45631 this.exObject = new XFAObjectArray();
45632 this.exclGroup = new XFAObjectArray();
45633 this.execute = new XFAObjectArray();
45634 this.extras = new XFAObjectArray();
45635 this.field = new XFAObjectArray();
45636 this.fill = new XFAObjectArray();
45637 this.filter = new XFAObjectArray();
45638 this.float = new XFAObjectArray();
45639 this.font = new XFAObjectArray();
45640 this.format = new XFAObjectArray();
45641 this.handler = new XFAObjectArray();
45642 this.hyphenation = new XFAObjectArray();
45643 this.image = new XFAObjectArray();
45644 this.imageEdit = new XFAObjectArray();
45645 this.integer = new XFAObjectArray();
45646 this.issuers = new XFAObjectArray();
45647 this.items = new XFAObjectArray();
45648 this.keep = new XFAObjectArray();
45649 this.keyUsage = new XFAObjectArray();
45650 this.line = new XFAObjectArray();
45651 this.linear = new XFAObjectArray();
45652 this.lockDocument = new XFAObjectArray();
45653 this.manifest = new XFAObjectArray();
45654 this.margin = new XFAObjectArray();
45655 this.mdp = new XFAObjectArray();
45656 this.medium = new XFAObjectArray();
45657 this.message = new XFAObjectArray();
45658 this.numericEdit = new XFAObjectArray();
45659 this.occur = new XFAObjectArray();
45660 this.oid = new XFAObjectArray();
45661 this.oids = new XFAObjectArray();
45662 this.overflow = new XFAObjectArray();
45663 this.pageArea = new XFAObjectArray();
45664 this.pageSet = new XFAObjectArray();
45665 this.para = new XFAObjectArray();
45666 this.passwordEdit = new XFAObjectArray();
45667 this.pattern = new XFAObjectArray();
45668 this.picture = new XFAObjectArray();
45669 this.radial = new XFAObjectArray();
45670 this.reason = new XFAObjectArray();
45671 this.reasons = new XFAObjectArray();
45672 this.rectangle = new XFAObjectArray();
45673 this.ref = new XFAObjectArray();
45674 this.script = new XFAObjectArray();
45675 this.setProperty = new XFAObjectArray();
45676 this.signData = new XFAObjectArray();
45677 this.signature = new XFAObjectArray();
45678 this.signing = new XFAObjectArray();
45679 this.solid = new XFAObjectArray();
45680 this.speak = new XFAObjectArray();
45681 this.stipple = new XFAObjectArray();
45682 this.subform = new XFAObjectArray();
45683 this.subformSet = new XFAObjectArray();
45684 this.subjectDN = new XFAObjectArray();
45685 this.subjectDNs = new XFAObjectArray();
45686 this.submit = new XFAObjectArray();
45687 this.text = new XFAObjectArray();
45688 this.textEdit = new XFAObjectArray();
45689 this.time = new XFAObjectArray();
45690 this.timeStamp = new XFAObjectArray();
45691 this.toolTip = new XFAObjectArray();
45692 this.traversal = new XFAObjectArray();
45693 this.traverse = new XFAObjectArray();
45694 this.ui = new XFAObjectArray();
45695 this.validate = new XFAObjectArray();
45696 this.value = new XFAObjectArray();
45697 this.variables = new XFAObjectArray();
45698 }
45699}
45700class Radial extends XFAObject {
45701 constructor(attributes) {
45702 super(TEMPLATE_NS_ID, "radial", true);
45703 this.id = attributes.id || "";
45704 this.type = getStringOption(attributes.type, ["toEdge", "toCenter"]);
45705 this.use = attributes.use || "";
45706 this.usehref = attributes.usehref || "";
45707 this.color = null;
45708 this.extras = null;
45709 }
45710 [$toStyle](startColor) {
45711 startColor = startColor ? startColor[$toStyle]() : "#FFFFFF";
45712 const endColor = this.color ? this.color[$toStyle]() : "#000000";
45713 const colors = this.type === "toEdge" ? `${startColor},${endColor}` : `${endColor},${startColor}`;
45714 return `radial-gradient(circle at center, ${colors})`;
45715 }
45716}
45717class Reason extends StringObject {
45718 constructor(attributes) {
45719 super(TEMPLATE_NS_ID, "reason");
45720 this.id = attributes.id || "";
45721 this.name = attributes.name || "";
45722 this.use = attributes.use || "";
45723 this.usehref = attributes.usehref || "";
45724 }
45725}
45726class Reasons extends XFAObject {
45727 constructor(attributes) {
45728 super(TEMPLATE_NS_ID, "reasons", true);
45729 this.id = attributes.id || "";
45730 this.type = getStringOption(attributes.type, ["optional", "required"]);
45731 this.use = attributes.use || "";
45732 this.usehref = attributes.usehref || "";
45733 this.reason = new XFAObjectArray();
45734 }
45735}
45736class Rectangle extends XFAObject {
45737 constructor(attributes) {
45738 super(TEMPLATE_NS_ID, "rectangle", true);
45739 this.hand = getStringOption(attributes.hand, ["even", "left", "right"]);
45740 this.id = attributes.id || "";
45741 this.use = attributes.use || "";
45742 this.usehref = attributes.usehref || "";
45743 this.corner = new XFAObjectArray(4);
45744 this.edge = new XFAObjectArray(4);
45745 this.fill = null;
45746 }
45747 [$toHTML]() {
45748 const edge = this.edge.children.length ? this.edge.children[0] : new Edge({});
45749 const edgeStyle = edge[$toStyle]();
45750 const style = Object.create(null);
45751 if (this.fill?.presence === "visible") {
45752 Object.assign(style, this.fill[$toStyle]());
45753 } else {
45754 style.fill = "transparent";
45755 }
45756 style.strokeWidth = measureToString(edge.presence === "visible" ? edge.thickness : 0);
45757 style.stroke = edgeStyle.color;
45758 const corner = this.corner.children.length ? this.corner.children[0] : new Corner({});
45759 const cornerStyle = corner[$toStyle]();
45760 const rect = {
45761 name: "rect",
45762 attributes: {
45763 xmlns: SVG_NS,
45764 width: "100%",
45765 height: "100%",
45766 x: 0,
45767 y: 0,
45768 rx: cornerStyle.radius,
45769 ry: cornerStyle.radius,
45770 style
45771 }
45772 };
45773 const svg = {
45774 name: "svg",
45775 children: [rect],
45776 attributes: {
45777 xmlns: SVG_NS,
45778 style: {
45779 overflow: "visible"
45780 },
45781 width: "100%",
45782 height: "100%"
45783 }
45784 };
45785 const parent = this[$getParent]()[$getParent]();
45786 if (hasMargin(parent)) {
45787 return HTMLResult.success({
45788 name: "div",
45789 attributes: {
45790 style: {
45791 display: "inline",
45792 width: "100%",
45793 height: "100%"
45794 }
45795 },
45796 children: [svg]
45797 });
45798 }
45799 svg.attributes.style.position = "absolute";
45800 return HTMLResult.success(svg);
45801 }
45802}
45803class RefElement extends StringObject {
45804 constructor(attributes) {
45805 super(TEMPLATE_NS_ID, "ref");
45806 this.id = attributes.id || "";
45807 this.use = attributes.use || "";
45808 this.usehref = attributes.usehref || "";
45809 }
45810}
45811class Script extends StringObject {
45812 constructor(attributes) {
45813 super(TEMPLATE_NS_ID, "script");
45814 this.binding = attributes.binding || "";
45815 this.contentType = attributes.contentType || "";
45816 this.id = attributes.id || "";
45817 this.name = attributes.name || "";
45818 this.runAt = getStringOption(attributes.runAt, ["client", "both", "server"]);
45819 this.use = attributes.use || "";
45820 this.usehref = attributes.usehref || "";
45821 }
45822}
45823class SetProperty extends XFAObject {
45824 constructor(attributes) {
45825 super(TEMPLATE_NS_ID, "setProperty");
45826 this.connection = attributes.connection || "";
45827 this.ref = attributes.ref || "";
45828 this.target = attributes.target || "";
45829 }
45830}
45831class SignData extends XFAObject {
45832 constructor(attributes) {
45833 super(TEMPLATE_NS_ID, "signData", true);
45834 this.id = attributes.id || "";
45835 this.operation = getStringOption(attributes.operation, ["sign", "clear", "verify"]);
45836 this.ref = attributes.ref || "";
45837 this.target = attributes.target || "";
45838 this.use = attributes.use || "";
45839 this.usehref = attributes.usehref || "";
45840 this.filter = null;
45841 this.manifest = null;
45842 }
45843}
45844class Signature extends XFAObject {
45845 constructor(attributes) {
45846 super(TEMPLATE_NS_ID, "signature", true);
45847 this.id = attributes.id || "";
45848 this.type = getStringOption(attributes.type, ["PDF1.3", "PDF1.6"]);
45849 this.use = attributes.use || "";
45850 this.usehref = attributes.usehref || "";
45851 this.border = null;
45852 this.extras = null;
45853 this.filter = null;
45854 this.manifest = null;
45855 this.margin = null;
45856 }
45857}
45858class Signing extends XFAObject {
45859 constructor(attributes) {
45860 super(TEMPLATE_NS_ID, "signing", true);
45861 this.id = attributes.id || "";
45862 this.type = getStringOption(attributes.type, ["optional", "required"]);
45863 this.use = attributes.use || "";
45864 this.usehref = attributes.usehref || "";
45865 this.certificate = new XFAObjectArray();
45866 }
45867}
45868class Solid extends XFAObject {
45869 constructor(attributes) {
45870 super(TEMPLATE_NS_ID, "solid", true);
45871 this.id = attributes.id || "";
45872 this.use = attributes.use || "";
45873 this.usehref = attributes.usehref || "";
45874 this.extras = null;
45875 }
45876 [$toStyle](startColor) {
45877 return startColor ? startColor[$toStyle]() : "#FFFFFF";
45878 }
45879}
45880class Speak extends StringObject {
45881 constructor(attributes) {
45882 super(TEMPLATE_NS_ID, "speak");
45883 this.disable = getInteger({
45884 data: attributes.disable,
45885 defaultValue: 0,
45886 validate: x => x === 1
45887 });
45888 this.id = attributes.id || "";
45889 this.priority = getStringOption(attributes.priority, ["custom", "caption", "name", "toolTip"]);
45890 this.rid = attributes.rid || "";
45891 this.use = attributes.use || "";
45892 this.usehref = attributes.usehref || "";
45893 }
45894}
45895class Stipple extends XFAObject {
45896 constructor(attributes) {
45897 super(TEMPLATE_NS_ID, "stipple", true);
45898 this.id = attributes.id || "";
45899 this.rate = getInteger({
45900 data: attributes.rate,
45901 defaultValue: 50,
45902 validate: x => x >= 0 && x <= 100
45903 });
45904 this.use = attributes.use || "";
45905 this.usehref = attributes.usehref || "";
45906 this.color = null;
45907 this.extras = null;
45908 }
45909 [$toStyle](bgColor) {
45910 const alpha = this.rate / 100;
45911 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));
45912 }
45913}
45914class Subform extends XFAObject {
45915 constructor(attributes) {
45916 super(TEMPLATE_NS_ID, "subform", true);
45917 this.access = getStringOption(attributes.access, ["open", "nonInteractive", "protected", "readOnly"]);
45918 this.allowMacro = getInteger({
45919 data: attributes.allowMacro,
45920 defaultValue: 0,
45921 validate: x => x === 1
45922 });
45923 this.anchorType = getStringOption(attributes.anchorType, ["topLeft", "bottomCenter", "bottomLeft", "bottomRight", "middleCenter", "middleLeft", "middleRight", "topCenter", "topRight"]);
45924 this.colSpan = getInteger({
45925 data: attributes.colSpan,
45926 defaultValue: 1,
45927 validate: n => n >= 1 || n === -1
45928 });
45929 this.columnWidths = (attributes.columnWidths || "").trim().split(/\s+/).map(x => x === "-1" ? -1 : getMeasurement(x));
45930 this.h = attributes.h ? getMeasurement(attributes.h) : "";
45931 this.hAlign = getStringOption(attributes.hAlign, ["left", "center", "justify", "justifyAll", "radix", "right"]);
45932 this.id = attributes.id || "";
45933 this.layout = getStringOption(attributes.layout, ["position", "lr-tb", "rl-row", "rl-tb", "row", "table", "tb"]);
45934 this.locale = attributes.locale || "";
45935 this.maxH = getMeasurement(attributes.maxH, "0pt");
45936 this.maxW = getMeasurement(attributes.maxW, "0pt");
45937 this.mergeMode = getStringOption(attributes.mergeMode, ["consumeData", "matchTemplate"]);
45938 this.minH = getMeasurement(attributes.minH, "0pt");
45939 this.minW = getMeasurement(attributes.minW, "0pt");
45940 this.name = attributes.name || "";
45941 this.presence = getStringOption(attributes.presence, ["visible", "hidden", "inactive", "invisible"]);
45942 this.relevant = getRelevant(attributes.relevant);
45943 this.restoreState = getStringOption(attributes.restoreState, ["manual", "auto"]);
45944 this.scope = getStringOption(attributes.scope, ["name", "none"]);
45945 this.use = attributes.use || "";
45946 this.usehref = attributes.usehref || "";
45947 this.w = attributes.w ? getMeasurement(attributes.w) : "";
45948 this.x = getMeasurement(attributes.x, "0pt");
45949 this.y = getMeasurement(attributes.y, "0pt");
45950 this.assist = null;
45951 this.bind = null;
45952 this.bookend = null;
45953 this.border = null;
45954 this.break = null;
45955 this.calculate = null;
45956 this.desc = null;
45957 this.extras = null;
45958 this.keep = null;
45959 this.margin = null;
45960 this.occur = null;
45961 this.overflow = null;
45962 this.pageSet = null;
45963 this.para = null;
45964 this.traversal = null;
45965 this.validate = null;
45966 this.variables = null;
45967 this.area = new XFAObjectArray();
45968 this.breakAfter = new XFAObjectArray();
45969 this.breakBefore = new XFAObjectArray();
45970 this.connect = new XFAObjectArray();
45971 this.draw = new XFAObjectArray();
45972 this.event = new XFAObjectArray();
45973 this.exObject = new XFAObjectArray();
45974 this.exclGroup = new XFAObjectArray();
45975 this.field = new XFAObjectArray();
45976 this.proto = new XFAObjectArray();
45977 this.setProperty = new XFAObjectArray();
45978 this.subform = new XFAObjectArray();
45979 this.subformSet = new XFAObjectArray();
45980 }
45981 [$getSubformParent]() {
45982 const parent = this[$getParent]();
45983 if (parent instanceof SubformSet) {
45984 return parent[$getSubformParent]();
45985 }
45986 return parent;
45987 }
45988 [$isBindable]() {
45989 return true;
45990 }
45991 [$isThereMoreWidth]() {
45992 return this.layout.endsWith("-tb") && this[$extra].attempt === 0 && this[$extra].numberInLine > 0 || this[$getParent]()[$isThereMoreWidth]();
45993 }
45994 *[$getContainedChildren]() {
45995 yield* getContainedChildren(this);
45996 }
45997 [$flushHTML]() {
45998 return flushHTML(this);
45999 }
46000 [$addHTML](html, bbox) {
46001 addHTML(this, html, bbox);
46002 }
46003 [$getAvailableSpace]() {
46004 return getAvailableSpace(this);
46005 }
46006 [$isSplittable]() {
46007 const parent = this[$getSubformParent]();
46008 if (!parent[$isSplittable]()) {
46009 return false;
46010 }
46011 if (this[$extra]._isSplittable !== undefined) {
46012 return this[$extra]._isSplittable;
46013 }
46014 if (this.layout === "position" || this.layout.includes("row")) {
46015 this[$extra]._isSplittable = false;
46016 return false;
46017 }
46018 if (this.keep && this.keep.intact !== "none") {
46019 this[$extra]._isSplittable = false;
46020 return false;
46021 }
46022 if (parent.layout?.endsWith("-tb") && parent[$extra].numberInLine !== 0) {
46023 return false;
46024 }
46025 this[$extra]._isSplittable = true;
46026 return true;
46027 }
46028 [$toHTML](availableSpace) {
46029 setTabIndex(this);
46030 if (this.break) {
46031 if (this.break.after !== "auto" || this.break.afterTarget !== "") {
46032 const node = new BreakAfter({
46033 targetType: this.break.after,
46034 target: this.break.afterTarget,
46035 startNew: this.break.startNew.toString()
46036 });
46037 node[$globalData] = this[$globalData];
46038 this[$appendChild](node);
46039 this.breakAfter.push(node);
46040 }
46041 if (this.break.before !== "auto" || this.break.beforeTarget !== "") {
46042 const node = new BreakBefore({
46043 targetType: this.break.before,
46044 target: this.break.beforeTarget,
46045 startNew: this.break.startNew.toString()
46046 });
46047 node[$globalData] = this[$globalData];
46048 this[$appendChild](node);
46049 this.breakBefore.push(node);
46050 }
46051 if (this.break.overflowTarget !== "") {
46052 const node = new Overflow({
46053 target: this.break.overflowTarget,
46054 leader: this.break.overflowLeader,
46055 trailer: this.break.overflowTrailer
46056 });
46057 node[$globalData] = this[$globalData];
46058 this[$appendChild](node);
46059 this.overflow.push(node);
46060 }
46061 this[$removeChild](this.break);
46062 this.break = null;
46063 }
46064 if (this.presence === "hidden" || this.presence === "inactive") {
46065 return HTMLResult.EMPTY;
46066 }
46067 if (this.breakBefore.children.length > 1 || this.breakAfter.children.length > 1) {
46068 warn("XFA - Several breakBefore or breakAfter in subforms: please file a bug.");
46069 }
46070 if (this.breakBefore.children.length >= 1) {
46071 const breakBefore = this.breakBefore.children[0];
46072 if (handleBreak(breakBefore)) {
46073 return HTMLResult.breakNode(breakBefore);
46074 }
46075 }
46076 if (this[$extra]?.afterBreakAfter) {
46077 return HTMLResult.EMPTY;
46078 }
46079 fixDimensions(this);
46080 const children = [];
46081 const attributes = {
46082 id: this[$uid],
46083 class: []
46084 };
46085 setAccess(this, attributes.class);
46086 if (!this[$extra]) {
46087 this[$extra] = Object.create(null);
46088 }
46089 Object.assign(this[$extra], {
46090 children,
46091 line: null,
46092 attributes,
46093 attempt: 0,
46094 numberInLine: 0,
46095 availableSpace: {
46096 width: Math.min(this.w || Infinity, availableSpace.width),
46097 height: Math.min(this.h || Infinity, availableSpace.height)
46098 },
46099 width: 0,
46100 height: 0,
46101 prevHeight: 0,
46102 currentWidth: 0
46103 });
46104 const root = this[$getTemplateRoot]();
46105 const savedNoLayoutFailure = root[$extra].noLayoutFailure;
46106 const isSplittable = this[$isSplittable]();
46107 if (!isSplittable) {
46108 setFirstUnsplittable(this);
46109 }
46110 if (!checkDimensions(this, availableSpace)) {
46111 return HTMLResult.FAILURE;
46112 }
46113 const filter = new Set(["area", "draw", "exclGroup", "field", "subform", "subformSet"]);
46114 if (this.layout.includes("row")) {
46115 const columnWidths = this[$getSubformParent]().columnWidths;
46116 if (Array.isArray(columnWidths) && columnWidths.length > 0) {
46117 this[$extra].columnWidths = columnWidths;
46118 this[$extra].currentColumn = 0;
46119 }
46120 }
46121 const style = toStyle(this, "anchorType", "dimensions", "position", "presence", "border", "margin", "hAlign");
46122 const classNames = ["xfaSubform"];
46123 const cl = layoutClass(this);
46124 if (cl) {
46125 classNames.push(cl);
46126 }
46127 attributes.style = style;
46128 attributes.class = classNames;
46129 if (this.name) {
46130 attributes.xfaName = this.name;
46131 }
46132 if (this.overflow) {
46133 const overflowExtra = this.overflow[$getExtra]();
46134 if (overflowExtra.addLeader) {
46135 overflowExtra.addLeader = false;
46136 handleOverflow(this, overflowExtra.leader, availableSpace);
46137 }
46138 }
46139 this[$pushPara]();
46140 const isLrTb = this.layout === "lr-tb" || this.layout === "rl-tb";
46141 const maxRun = isLrTb ? MAX_ATTEMPTS_FOR_LRTB_LAYOUT : 1;
46142 for (; this[$extra].attempt < maxRun; this[$extra].attempt++) {
46143 if (isLrTb && this[$extra].attempt === MAX_ATTEMPTS_FOR_LRTB_LAYOUT - 1) {
46144 this[$extra].numberInLine = 0;
46145 }
46146 const result = this[$childrenToHTML]({
46147 filter,
46148 include: true
46149 });
46150 if (result.success) {
46151 break;
46152 }
46153 if (result.isBreak()) {
46154 this[$popPara]();
46155 return result;
46156 }
46157 if (isLrTb && this[$extra].attempt === 0 && this[$extra].numberInLine === 0 && !root[$extra].noLayoutFailure) {
46158 this[$extra].attempt = maxRun;
46159 break;
46160 }
46161 }
46162 this[$popPara]();
46163 if (!isSplittable) {
46164 unsetFirstUnsplittable(this);
46165 }
46166 root[$extra].noLayoutFailure = savedNoLayoutFailure;
46167 if (this[$extra].attempt === maxRun) {
46168 if (this.overflow) {
46169 this[$getTemplateRoot]()[$extra].overflowNode = this.overflow;
46170 }
46171 if (!isSplittable) {
46172 delete this[$extra];
46173 }
46174 return HTMLResult.FAILURE;
46175 }
46176 if (this.overflow) {
46177 const overflowExtra = this.overflow[$getExtra]();
46178 if (overflowExtra.addTrailer) {
46179 overflowExtra.addTrailer = false;
46180 handleOverflow(this, overflowExtra.trailer, availableSpace);
46181 }
46182 }
46183 let marginH = 0;
46184 let marginV = 0;
46185 if (this.margin) {
46186 marginH = this.margin.leftInset + this.margin.rightInset;
46187 marginV = this.margin.topInset + this.margin.bottomInset;
46188 }
46189 const width = Math.max(this[$extra].width + marginH, this.w || 0);
46190 const height = Math.max(this[$extra].height + marginV, this.h || 0);
46191 const bbox = [this.x, this.y, width, height];
46192 if (this.w === "") {
46193 style.width = measureToString(width);
46194 }
46195 if (this.h === "") {
46196 style.height = measureToString(height);
46197 }
46198 if ((style.width === "0px" || style.height === "0px") && children.length === 0) {
46199 return HTMLResult.EMPTY;
46200 }
46201 const html = {
46202 name: "div",
46203 attributes,
46204 children
46205 };
46206 applyAssist(this, attributes);
46207 const result = HTMLResult.success(createWrapper(this, html), bbox);
46208 if (this.breakAfter.children.length >= 1) {
46209 const breakAfter = this.breakAfter.children[0];
46210 if (handleBreak(breakAfter)) {
46211 this[$extra].afterBreakAfter = result;
46212 return HTMLResult.breakNode(breakAfter);
46213 }
46214 }
46215 delete this[$extra];
46216 return result;
46217 }
46218}
46219class SubformSet extends XFAObject {
46220 constructor(attributes) {
46221 super(TEMPLATE_NS_ID, "subformSet", true);
46222 this.id = attributes.id || "";
46223 this.name = attributes.name || "";
46224 this.relation = getStringOption(attributes.relation, ["ordered", "choice", "unordered"]);
46225 this.relevant = getRelevant(attributes.relevant);
46226 this.use = attributes.use || "";
46227 this.usehref = attributes.usehref || "";
46228 this.bookend = null;
46229 this.break = null;
46230 this.desc = null;
46231 this.extras = null;
46232 this.occur = null;
46233 this.overflow = null;
46234 this.breakAfter = new XFAObjectArray();
46235 this.breakBefore = new XFAObjectArray();
46236 this.subform = new XFAObjectArray();
46237 this.subformSet = new XFAObjectArray();
46238 }
46239 *[$getContainedChildren]() {
46240 yield* getContainedChildren(this);
46241 }
46242 [$getSubformParent]() {
46243 let parent = this[$getParent]();
46244 while (!(parent instanceof Subform)) {
46245 parent = parent[$getParent]();
46246 }
46247 return parent;
46248 }
46249 [$isBindable]() {
46250 return true;
46251 }
46252}
46253class SubjectDN extends ContentObject {
46254 constructor(attributes) {
46255 super(TEMPLATE_NS_ID, "subjectDN");
46256 this.delimiter = attributes.delimiter || ",";
46257 this.id = attributes.id || "";
46258 this.name = attributes.name || "";
46259 this.use = attributes.use || "";
46260 this.usehref = attributes.usehref || "";
46261 }
46262 [$finalize]() {
46263 this[$content] = new Map(this[$content].split(this.delimiter).map(kv => {
46264 kv = kv.split("=", 2);
46265 kv[0] = kv[0].trim();
46266 return kv;
46267 }));
46268 }
46269}
46270class SubjectDNs extends XFAObject {
46271 constructor(attributes) {
46272 super(TEMPLATE_NS_ID, "subjectDNs", true);
46273 this.id = attributes.id || "";
46274 this.type = getStringOption(attributes.type, ["optional", "required"]);
46275 this.use = attributes.use || "";
46276 this.usehref = attributes.usehref || "";
46277 this.subjectDN = new XFAObjectArray();
46278 }
46279}
46280class Submit extends XFAObject {
46281 constructor(attributes) {
46282 super(TEMPLATE_NS_ID, "submit", true);
46283 this.embedPDF = getInteger({
46284 data: attributes.embedPDF,
46285 defaultValue: 0,
46286 validate: x => x === 1
46287 });
46288 this.format = getStringOption(attributes.format, ["xdp", "formdata", "pdf", "urlencoded", "xfd", "xml"]);
46289 this.id = attributes.id || "";
46290 this.target = attributes.target || "";
46291 this.textEncoding = getKeyword({
46292 data: attributes.textEncoding ? attributes.textEncoding.toLowerCase() : "",
46293 defaultValue: "",
46294 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}/)
46295 });
46296 this.use = attributes.use || "";
46297 this.usehref = attributes.usehref || "";
46298 this.xdpContent = attributes.xdpContent || "";
46299 this.encrypt = null;
46300 this.encryptData = new XFAObjectArray();
46301 this.signData = new XFAObjectArray();
46302 }
46303}
46304class Template extends XFAObject {
46305 constructor(attributes) {
46306 super(TEMPLATE_NS_ID, "template", true);
46307 this.baseProfile = getStringOption(attributes.baseProfile, ["full", "interactiveForms"]);
46308 this.extras = null;
46309 this.subform = new XFAObjectArray();
46310 }
46311 [$finalize]() {
46312 if (this.subform.children.length === 0) {
46313 warn("XFA - No subforms in template node.");
46314 }
46315 if (this.subform.children.length >= 2) {
46316 warn("XFA - Several subforms in template node: please file a bug.");
46317 }
46318 this[$tabIndex] = DEFAULT_TAB_INDEX;
46319 }
46320 [$isSplittable]() {
46321 return true;
46322 }
46323 [$searchNode](expr, container) {
46324 if (expr.startsWith("#")) {
46325 return [this[$ids].get(expr.slice(1))];
46326 }
46327 return searchNode(this, container, expr, true, true);
46328 }
46329 *[$toPages]() {
46330 if (!this.subform.children.length) {
46331 return HTMLResult.success({
46332 name: "div",
46333 children: []
46334 });
46335 }
46336 this[$extra] = {
46337 overflowNode: null,
46338 firstUnsplittable: null,
46339 currentContentArea: null,
46340 currentPageArea: null,
46341 noLayoutFailure: false,
46342 pageNumber: 1,
46343 pagePosition: "first",
46344 oddOrEven: "odd",
46345 blankOrNotBlank: "nonBlank",
46346 paraStack: []
46347 };
46348 const root = this.subform.children[0];
46349 root.pageSet[$cleanPage]();
46350 const pageAreas = root.pageSet.pageArea.children;
46351 const mainHtml = {
46352 name: "div",
46353 children: []
46354 };
46355 let pageArea = null;
46356 let breakBefore = null;
46357 let breakBeforeTarget = null;
46358 if (root.breakBefore.children.length >= 1) {
46359 breakBefore = root.breakBefore.children[0];
46360 breakBeforeTarget = breakBefore.target;
46361 } else if (root.subform.children.length >= 1 && root.subform.children[0].breakBefore.children.length >= 1) {
46362 breakBefore = root.subform.children[0].breakBefore.children[0];
46363 breakBeforeTarget = breakBefore.target;
46364 } else if (root.break?.beforeTarget) {
46365 breakBefore = root.break;
46366 breakBeforeTarget = breakBefore.beforeTarget;
46367 } else if (root.subform.children.length >= 1 && root.subform.children[0].break?.beforeTarget) {
46368 breakBefore = root.subform.children[0].break;
46369 breakBeforeTarget = breakBefore.beforeTarget;
46370 }
46371 if (breakBefore) {
46372 const target = this[$searchNode](breakBeforeTarget, breakBefore[$getParent]());
46373 if (target instanceof PageArea) {
46374 pageArea = target;
46375 breakBefore[$extra] = {};
46376 }
46377 }
46378 if (!pageArea) {
46379 pageArea = pageAreas[0];
46380 }
46381 pageArea[$extra] = {
46382 numberOfUse: 1
46383 };
46384 const pageAreaParent = pageArea[$getParent]();
46385 pageAreaParent[$extra] = {
46386 numberOfUse: 1,
46387 pageIndex: pageAreaParent.pageArea.children.indexOf(pageArea),
46388 pageSetIndex: 0
46389 };
46390 let targetPageArea;
46391 let leader = null;
46392 let trailer = null;
46393 let hasSomething = true;
46394 let hasSomethingCounter = 0;
46395 let startIndex = 0;
46396 while (true) {
46397 if (!hasSomething) {
46398 mainHtml.children.pop();
46399 if (++hasSomethingCounter === MAX_EMPTY_PAGES) {
46400 warn("XFA - Something goes wrong: please file a bug.");
46401 return mainHtml;
46402 }
46403 } else {
46404 hasSomethingCounter = 0;
46405 }
46406 targetPageArea = null;
46407 this[$extra].currentPageArea = pageArea;
46408 const page = pageArea[$toHTML]().html;
46409 mainHtml.children.push(page);
46410 if (leader) {
46411 this[$extra].noLayoutFailure = true;
46412 page.children.push(leader[$toHTML](pageArea[$extra].space).html);
46413 leader = null;
46414 }
46415 if (trailer) {
46416 this[$extra].noLayoutFailure = true;
46417 page.children.push(trailer[$toHTML](pageArea[$extra].space).html);
46418 trailer = null;
46419 }
46420 const contentAreas = pageArea.contentArea.children;
46421 const htmlContentAreas = page.children.filter(node => node.attributes.class.includes("xfaContentarea"));
46422 hasSomething = false;
46423 this[$extra].firstUnsplittable = null;
46424 this[$extra].noLayoutFailure = false;
46425 const flush = index => {
46426 const html = root[$flushHTML]();
46427 if (html) {
46428 hasSomething ||= html.children?.length > 0;
46429 htmlContentAreas[index].children.push(html);
46430 }
46431 };
46432 for (let i = startIndex, ii = contentAreas.length; i < ii; i++) {
46433 const contentArea = this[$extra].currentContentArea = contentAreas[i];
46434 const space = {
46435 width: contentArea.w,
46436 height: contentArea.h
46437 };
46438 startIndex = 0;
46439 if (leader) {
46440 htmlContentAreas[i].children.push(leader[$toHTML](space).html);
46441 leader = null;
46442 }
46443 if (trailer) {
46444 htmlContentAreas[i].children.push(trailer[$toHTML](space).html);
46445 trailer = null;
46446 }
46447 const html = root[$toHTML](space);
46448 if (html.success) {
46449 if (html.html) {
46450 hasSomething ||= html.html.children?.length > 0;
46451 htmlContentAreas[i].children.push(html.html);
46452 } else if (!hasSomething && mainHtml.children.length > 1) {
46453 mainHtml.children.pop();
46454 }
46455 return mainHtml;
46456 }
46457 if (html.isBreak()) {
46458 const node = html.breakNode;
46459 flush(i);
46460 if (node.targetType === "auto") {
46461 continue;
46462 }
46463 if (node.leader) {
46464 leader = this[$searchNode](node.leader, node[$getParent]());
46465 leader = leader ? leader[0] : null;
46466 }
46467 if (node.trailer) {
46468 trailer = this[$searchNode](node.trailer, node[$getParent]());
46469 trailer = trailer ? trailer[0] : null;
46470 }
46471 if (node.targetType === "pageArea") {
46472 targetPageArea = node[$extra].target;
46473 i = Infinity;
46474 } else if (!node[$extra].target) {
46475 i = node[$extra].index;
46476 } else {
46477 targetPageArea = node[$extra].target;
46478 startIndex = node[$extra].index + 1;
46479 i = Infinity;
46480 }
46481 continue;
46482 }
46483 if (this[$extra].overflowNode) {
46484 const node = this[$extra].overflowNode;
46485 this[$extra].overflowNode = null;
46486 const overflowExtra = node[$getExtra]();
46487 const target = overflowExtra.target;
46488 overflowExtra.addLeader = overflowExtra.leader !== null;
46489 overflowExtra.addTrailer = overflowExtra.trailer !== null;
46490 flush(i);
46491 const currentIndex = i;
46492 i = Infinity;
46493 if (target instanceof PageArea) {
46494 targetPageArea = target;
46495 } else if (target instanceof ContentArea) {
46496 const index = contentAreas.indexOf(target);
46497 if (index !== -1) {
46498 if (index > currentIndex) {
46499 i = index - 1;
46500 } else {
46501 startIndex = index;
46502 }
46503 } else {
46504 targetPageArea = target[$getParent]();
46505 startIndex = targetPageArea.contentArea.children.indexOf(target);
46506 }
46507 }
46508 continue;
46509 }
46510 flush(i);
46511 }
46512 this[$extra].pageNumber += 1;
46513 if (targetPageArea) {
46514 if (targetPageArea[$isUsable]()) {
46515 targetPageArea[$extra].numberOfUse += 1;
46516 } else {
46517 targetPageArea = null;
46518 }
46519 }
46520 pageArea = targetPageArea || pageArea[$getNextPage]();
46521 yield null;
46522 }
46523 }
46524}
46525class Text extends ContentObject {
46526 constructor(attributes) {
46527 super(TEMPLATE_NS_ID, "text");
46528 this.id = attributes.id || "";
46529 this.maxChars = getInteger({
46530 data: attributes.maxChars,
46531 defaultValue: 0,
46532 validate: x => x >= 0
46533 });
46534 this.name = attributes.name || "";
46535 this.rid = attributes.rid || "";
46536 this.use = attributes.use || "";
46537 this.usehref = attributes.usehref || "";
46538 }
46539 [$acceptWhitespace]() {
46540 return true;
46541 }
46542 [$onChild](child) {
46543 if (child[$namespaceId] === NamespaceIds.xhtml.id) {
46544 this[$content] = child;
46545 return true;
46546 }
46547 warn(`XFA - Invalid content in Text: ${child[$nodeName]}.`);
46548 return false;
46549 }
46550 [$onText](str) {
46551 if (this[$content] instanceof XFAObject) {
46552 return;
46553 }
46554 super[$onText](str);
46555 }
46556 [$finalize]() {
46557 if (typeof this[$content] === "string") {
46558 this[$content] = this[$content].replaceAll("\r\n", "\n");
46559 }
46560 }
46561 [$getExtra]() {
46562 if (typeof this[$content] === "string") {
46563 return this[$content].split(/[\u2029\u2028\n]/).reduce((acc, line) => {
46564 if (line) {
46565 acc.push(line);
46566 }
46567 return acc;
46568 }, []).join("\n");
46569 }
46570 return this[$content][$text]();
46571 }
46572 [$toHTML](availableSpace) {
46573 if (typeof this[$content] === "string") {
46574 const html = valueToHtml(this[$content]).html;
46575 if (this[$content].includes("\u2029")) {
46576 html.name = "div";
46577 html.children = [];
46578 this[$content].split("\u2029").map(para => para.split(/[\u2028\n]/).reduce((acc, line) => {
46579 acc.push({
46580 name: "span",
46581 value: line
46582 }, {
46583 name: "br"
46584 });
46585 return acc;
46586 }, [])).forEach(lines => {
46587 html.children.push({
46588 name: "p",
46589 children: lines
46590 });
46591 });
46592 } else if (/[\u2028\n]/.test(this[$content])) {
46593 html.name = "div";
46594 html.children = [];
46595 this[$content].split(/[\u2028\n]/).forEach(line => {
46596 html.children.push({
46597 name: "span",
46598 value: line
46599 }, {
46600 name: "br"
46601 });
46602 });
46603 }
46604 return HTMLResult.success(html);
46605 }
46606 return this[$content][$toHTML](availableSpace);
46607 }
46608}
46609class TextEdit extends XFAObject {
46610 constructor(attributes) {
46611 super(TEMPLATE_NS_ID, "textEdit", true);
46612 this.allowRichText = getInteger({
46613 data: attributes.allowRichText,
46614 defaultValue: 0,
46615 validate: x => x === 1
46616 });
46617 this.hScrollPolicy = getStringOption(attributes.hScrollPolicy, ["auto", "off", "on"]);
46618 this.id = attributes.id || "";
46619 this.multiLine = getInteger({
46620 data: attributes.multiLine,
46621 defaultValue: "",
46622 validate: x => x === 0 || x === 1
46623 });
46624 this.use = attributes.use || "";
46625 this.usehref = attributes.usehref || "";
46626 this.vScrollPolicy = getStringOption(attributes.vScrollPolicy, ["auto", "off", "on"]);
46627 this.border = null;
46628 this.comb = null;
46629 this.extras = null;
46630 this.margin = null;
46631 }
46632 [$toHTML](availableSpace) {
46633 const style = toStyle(this, "border", "font", "margin");
46634 let html;
46635 const field = this[$getParent]()[$getParent]();
46636 if (this.multiLine === "") {
46637 this.multiLine = field instanceof Draw ? 1 : 0;
46638 }
46639 if (this.multiLine === 1) {
46640 html = {
46641 name: "textarea",
46642 attributes: {
46643 dataId: field[$data]?.[$uid] || field[$uid],
46644 fieldId: field[$uid],
46645 class: ["xfaTextfield"],
46646 style,
46647 "aria-label": ariaLabel(field),
46648 "aria-required": false
46649 }
46650 };
46651 } else {
46652 html = {
46653 name: "input",
46654 attributes: {
46655 type: "text",
46656 dataId: field[$data]?.[$uid] || field[$uid],
46657 fieldId: field[$uid],
46658 class: ["xfaTextfield"],
46659 style,
46660 "aria-label": ariaLabel(field),
46661 "aria-required": false
46662 }
46663 };
46664 }
46665 if (isRequired(field)) {
46666 html.attributes["aria-required"] = true;
46667 html.attributes.required = true;
46668 }
46669 return HTMLResult.success({
46670 name: "label",
46671 attributes: {
46672 class: ["xfaLabel"]
46673 },
46674 children: [html]
46675 });
46676 }
46677}
46678class Time extends StringObject {
46679 constructor(attributes) {
46680 super(TEMPLATE_NS_ID, "time");
46681 this.id = attributes.id || "";
46682 this.name = attributes.name || "";
46683 this.use = attributes.use || "";
46684 this.usehref = attributes.usehref || "";
46685 }
46686 [$finalize]() {
46687 const date = this[$content].trim();
46688 this[$content] = date ? new Date(date) : null;
46689 }
46690 [$toHTML](availableSpace) {
46691 return valueToHtml(this[$content] ? this[$content].toString() : "");
46692 }
46693}
46694class TimeStamp extends XFAObject {
46695 constructor(attributes) {
46696 super(TEMPLATE_NS_ID, "timeStamp");
46697 this.id = attributes.id || "";
46698 this.server = attributes.server || "";
46699 this.type = getStringOption(attributes.type, ["optional", "required"]);
46700 this.use = attributes.use || "";
46701 this.usehref = attributes.usehref || "";
46702 }
46703}
46704class ToolTip extends StringObject {
46705 constructor(attributes) {
46706 super(TEMPLATE_NS_ID, "toolTip");
46707 this.id = attributes.id || "";
46708 this.rid = attributes.rid || "";
46709 this.use = attributes.use || "";
46710 this.usehref = attributes.usehref || "";
46711 }
46712}
46713class Traversal extends XFAObject {
46714 constructor(attributes) {
46715 super(TEMPLATE_NS_ID, "traversal", true);
46716 this.id = attributes.id || "";
46717 this.use = attributes.use || "";
46718 this.usehref = attributes.usehref || "";
46719 this.extras = null;
46720 this.traverse = new XFAObjectArray();
46721 }
46722}
46723class Traverse extends XFAObject {
46724 constructor(attributes) {
46725 super(TEMPLATE_NS_ID, "traverse", true);
46726 this.id = attributes.id || "";
46727 this.operation = getStringOption(attributes.operation, ["next", "back", "down", "first", "left", "right", "up"]);
46728 this.ref = attributes.ref || "";
46729 this.use = attributes.use || "";
46730 this.usehref = attributes.usehref || "";
46731 this.extras = null;
46732 this.script = null;
46733 }
46734 get name() {
46735 return this.operation;
46736 }
46737 [$isTransparent]() {
46738 return false;
46739 }
46740}
46741class Ui extends XFAObject {
46742 constructor(attributes) {
46743 super(TEMPLATE_NS_ID, "ui", true);
46744 this.id = attributes.id || "";
46745 this.use = attributes.use || "";
46746 this.usehref = attributes.usehref || "";
46747 this.extras = null;
46748 this.picture = null;
46749 this.barcode = null;
46750 this.button = null;
46751 this.checkButton = null;
46752 this.choiceList = null;
46753 this.dateTimeEdit = null;
46754 this.defaultUi = null;
46755 this.imageEdit = null;
46756 this.numericEdit = null;
46757 this.passwordEdit = null;
46758 this.signature = null;
46759 this.textEdit = null;
46760 }
46761 [$getExtra]() {
46762 if (this[$extra] === undefined) {
46763 for (const name of Object.getOwnPropertyNames(this)) {
46764 if (name === "extras" || name === "picture") {
46765 continue;
46766 }
46767 const obj = this[name];
46768 if (!(obj instanceof XFAObject)) {
46769 continue;
46770 }
46771 this[$extra] = obj;
46772 return obj;
46773 }
46774 this[$extra] = null;
46775 }
46776 return this[$extra];
46777 }
46778 [$toHTML](availableSpace) {
46779 const obj = this[$getExtra]();
46780 if (obj) {
46781 return obj[$toHTML](availableSpace);
46782 }
46783 return HTMLResult.EMPTY;
46784 }
46785}
46786class Validate extends XFAObject {
46787 constructor(attributes) {
46788 super(TEMPLATE_NS_ID, "validate", true);
46789 this.formatTest = getStringOption(attributes.formatTest, ["warning", "disabled", "error"]);
46790 this.id = attributes.id || "";
46791 this.nullTest = getStringOption(attributes.nullTest, ["disabled", "error", "warning"]);
46792 this.scriptTest = getStringOption(attributes.scriptTest, ["error", "disabled", "warning"]);
46793 this.use = attributes.use || "";
46794 this.usehref = attributes.usehref || "";
46795 this.extras = null;
46796 this.message = null;
46797 this.picture = null;
46798 this.script = null;
46799 }
46800}
46801class Value extends XFAObject {
46802 constructor(attributes) {
46803 super(TEMPLATE_NS_ID, "value", true);
46804 this.id = attributes.id || "";
46805 this.override = getInteger({
46806 data: attributes.override,
46807 defaultValue: 0,
46808 validate: x => x === 1
46809 });
46810 this.relevant = getRelevant(attributes.relevant);
46811 this.use = attributes.use || "";
46812 this.usehref = attributes.usehref || "";
46813 this.arc = null;
46814 this.boolean = null;
46815 this.date = null;
46816 this.dateTime = null;
46817 this.decimal = null;
46818 this.exData = null;
46819 this.float = null;
46820 this.image = null;
46821 this.integer = null;
46822 this.line = null;
46823 this.rectangle = null;
46824 this.text = null;
46825 this.time = null;
46826 }
46827 [$setValue](value) {
46828 const parent = this[$getParent]();
46829 if (parent instanceof Field) {
46830 if (parent.ui?.imageEdit) {
46831 if (!this.image) {
46832 this.image = new Image({});
46833 this[$appendChild](this.image);
46834 }
46835 this.image[$content] = value[$content];
46836 return;
46837 }
46838 }
46839 const valueName = value[$nodeName];
46840 if (this[valueName] !== null) {
46841 this[valueName][$content] = value[$content];
46842 return;
46843 }
46844 for (const name of Object.getOwnPropertyNames(this)) {
46845 const obj = this[name];
46846 if (obj instanceof XFAObject) {
46847 this[name] = null;
46848 this[$removeChild](obj);
46849 }
46850 }
46851 this[value[$nodeName]] = value;
46852 this[$appendChild](value);
46853 }
46854 [$text]() {
46855 if (this.exData) {
46856 if (typeof this.exData[$content] === "string") {
46857 return this.exData[$content].trim();
46858 }
46859 return this.exData[$content][$text]().trim();
46860 }
46861 for (const name of Object.getOwnPropertyNames(this)) {
46862 if (name === "image") {
46863 continue;
46864 }
46865 const obj = this[name];
46866 if (obj instanceof XFAObject) {
46867 return (obj[$content] || "").toString().trim();
46868 }
46869 }
46870 return null;
46871 }
46872 [$toHTML](availableSpace) {
46873 for (const name of Object.getOwnPropertyNames(this)) {
46874 const obj = this[name];
46875 if (!(obj instanceof XFAObject)) {
46876 continue;
46877 }
46878 return obj[$toHTML](availableSpace);
46879 }
46880 return HTMLResult.EMPTY;
46881 }
46882}
46883class Variables extends XFAObject {
46884 constructor(attributes) {
46885 super(TEMPLATE_NS_ID, "variables", true);
46886 this.id = attributes.id || "";
46887 this.use = attributes.use || "";
46888 this.usehref = attributes.usehref || "";
46889 this.boolean = new XFAObjectArray();
46890 this.date = new XFAObjectArray();
46891 this.dateTime = new XFAObjectArray();
46892 this.decimal = new XFAObjectArray();
46893 this.exData = new XFAObjectArray();
46894 this.float = new XFAObjectArray();
46895 this.image = new XFAObjectArray();
46896 this.integer = new XFAObjectArray();
46897 this.manifest = new XFAObjectArray();
46898 this.script = new XFAObjectArray();
46899 this.text = new XFAObjectArray();
46900 this.time = new XFAObjectArray();
46901 }
46902 [$isTransparent]() {
46903 return true;
46904 }
46905}
46906class TemplateNamespace {
46907 static [$buildXFAObject](name, attributes) {
46908 if (TemplateNamespace.hasOwnProperty(name)) {
46909 const node = TemplateNamespace[name](attributes);
46910 node[$setSetAttributes](attributes);
46911 return node;
46912 }
46913 return undefined;
46914 }
46915 static appearanceFilter(attrs) {
46916 return new AppearanceFilter(attrs);
46917 }
46918 static arc(attrs) {
46919 return new Arc(attrs);
46920 }
46921 static area(attrs) {
46922 return new Area(attrs);
46923 }
46924 static assist(attrs) {
46925 return new Assist(attrs);
46926 }
46927 static barcode(attrs) {
46928 return new Barcode(attrs);
46929 }
46930 static bind(attrs) {
46931 return new Bind(attrs);
46932 }
46933 static bindItems(attrs) {
46934 return new BindItems(attrs);
46935 }
46936 static bookend(attrs) {
46937 return new Bookend(attrs);
46938 }
46939 static boolean(attrs) {
46940 return new BooleanElement(attrs);
46941 }
46942 static border(attrs) {
46943 return new Border(attrs);
46944 }
46945 static break(attrs) {
46946 return new Break(attrs);
46947 }
46948 static breakAfter(attrs) {
46949 return new BreakAfter(attrs);
46950 }
46951 static breakBefore(attrs) {
46952 return new BreakBefore(attrs);
46953 }
46954 static button(attrs) {
46955 return new Button(attrs);
46956 }
46957 static calculate(attrs) {
46958 return new Calculate(attrs);
46959 }
46960 static caption(attrs) {
46961 return new Caption(attrs);
46962 }
46963 static certificate(attrs) {
46964 return new Certificate(attrs);
46965 }
46966 static certificates(attrs) {
46967 return new Certificates(attrs);
46968 }
46969 static checkButton(attrs) {
46970 return new CheckButton(attrs);
46971 }
46972 static choiceList(attrs) {
46973 return new ChoiceList(attrs);
46974 }
46975 static color(attrs) {
46976 return new Color(attrs);
46977 }
46978 static comb(attrs) {
46979 return new Comb(attrs);
46980 }
46981 static connect(attrs) {
46982 return new Connect(attrs);
46983 }
46984 static contentArea(attrs) {
46985 return new ContentArea(attrs);
46986 }
46987 static corner(attrs) {
46988 return new Corner(attrs);
46989 }
46990 static date(attrs) {
46991 return new DateElement(attrs);
46992 }
46993 static dateTime(attrs) {
46994 return new DateTime(attrs);
46995 }
46996 static dateTimeEdit(attrs) {
46997 return new DateTimeEdit(attrs);
46998 }
46999 static decimal(attrs) {
47000 return new Decimal(attrs);
47001 }
47002 static defaultUi(attrs) {
47003 return new DefaultUi(attrs);
47004 }
47005 static desc(attrs) {
47006 return new Desc(attrs);
47007 }
47008 static digestMethod(attrs) {
47009 return new DigestMethod(attrs);
47010 }
47011 static digestMethods(attrs) {
47012 return new DigestMethods(attrs);
47013 }
47014 static draw(attrs) {
47015 return new Draw(attrs);
47016 }
47017 static edge(attrs) {
47018 return new Edge(attrs);
47019 }
47020 static encoding(attrs) {
47021 return new Encoding(attrs);
47022 }
47023 static encodings(attrs) {
47024 return new Encodings(attrs);
47025 }
47026 static encrypt(attrs) {
47027 return new Encrypt(attrs);
47028 }
47029 static encryptData(attrs) {
47030 return new EncryptData(attrs);
47031 }
47032 static encryption(attrs) {
47033 return new Encryption(attrs);
47034 }
47035 static encryptionMethod(attrs) {
47036 return new EncryptionMethod(attrs);
47037 }
47038 static encryptionMethods(attrs) {
47039 return new EncryptionMethods(attrs);
47040 }
47041 static event(attrs) {
47042 return new Event(attrs);
47043 }
47044 static exData(attrs) {
47045 return new ExData(attrs);
47046 }
47047 static exObject(attrs) {
47048 return new ExObject(attrs);
47049 }
47050 static exclGroup(attrs) {
47051 return new ExclGroup(attrs);
47052 }
47053 static execute(attrs) {
47054 return new Execute(attrs);
47055 }
47056 static extras(attrs) {
47057 return new Extras(attrs);
47058 }
47059 static field(attrs) {
47060 return new Field(attrs);
47061 }
47062 static fill(attrs) {
47063 return new Fill(attrs);
47064 }
47065 static filter(attrs) {
47066 return new Filter(attrs);
47067 }
47068 static float(attrs) {
47069 return new Float(attrs);
47070 }
47071 static font(attrs) {
47072 return new template_Font(attrs);
47073 }
47074 static format(attrs) {
47075 return new Format(attrs);
47076 }
47077 static handler(attrs) {
47078 return new Handler(attrs);
47079 }
47080 static hyphenation(attrs) {
47081 return new Hyphenation(attrs);
47082 }
47083 static image(attrs) {
47084 return new Image(attrs);
47085 }
47086 static imageEdit(attrs) {
47087 return new ImageEdit(attrs);
47088 }
47089 static integer(attrs) {
47090 return new Integer(attrs);
47091 }
47092 static issuers(attrs) {
47093 return new Issuers(attrs);
47094 }
47095 static items(attrs) {
47096 return new Items(attrs);
47097 }
47098 static keep(attrs) {
47099 return new Keep(attrs);
47100 }
47101 static keyUsage(attrs) {
47102 return new KeyUsage(attrs);
47103 }
47104 static line(attrs) {
47105 return new Line(attrs);
47106 }
47107 static linear(attrs) {
47108 return new Linear(attrs);
47109 }
47110 static lockDocument(attrs) {
47111 return new LockDocument(attrs);
47112 }
47113 static manifest(attrs) {
47114 return new Manifest(attrs);
47115 }
47116 static margin(attrs) {
47117 return new Margin(attrs);
47118 }
47119 static mdp(attrs) {
47120 return new Mdp(attrs);
47121 }
47122 static medium(attrs) {
47123 return new Medium(attrs);
47124 }
47125 static message(attrs) {
47126 return new Message(attrs);
47127 }
47128 static numericEdit(attrs) {
47129 return new NumericEdit(attrs);
47130 }
47131 static occur(attrs) {
47132 return new Occur(attrs);
47133 }
47134 static oid(attrs) {
47135 return new Oid(attrs);
47136 }
47137 static oids(attrs) {
47138 return new Oids(attrs);
47139 }
47140 static overflow(attrs) {
47141 return new Overflow(attrs);
47142 }
47143 static pageArea(attrs) {
47144 return new PageArea(attrs);
47145 }
47146 static pageSet(attrs) {
47147 return new PageSet(attrs);
47148 }
47149 static para(attrs) {
47150 return new Para(attrs);
47151 }
47152 static passwordEdit(attrs) {
47153 return new PasswordEdit(attrs);
47154 }
47155 static pattern(attrs) {
47156 return new template_Pattern(attrs);
47157 }
47158 static picture(attrs) {
47159 return new Picture(attrs);
47160 }
47161 static proto(attrs) {
47162 return new Proto(attrs);
47163 }
47164 static radial(attrs) {
47165 return new Radial(attrs);
47166 }
47167 static reason(attrs) {
47168 return new Reason(attrs);
47169 }
47170 static reasons(attrs) {
47171 return new Reasons(attrs);
47172 }
47173 static rectangle(attrs) {
47174 return new Rectangle(attrs);
47175 }
47176 static ref(attrs) {
47177 return new RefElement(attrs);
47178 }
47179 static script(attrs) {
47180 return new Script(attrs);
47181 }
47182 static setProperty(attrs) {
47183 return new SetProperty(attrs);
47184 }
47185 static signData(attrs) {
47186 return new SignData(attrs);
47187 }
47188 static signature(attrs) {
47189 return new Signature(attrs);
47190 }
47191 static signing(attrs) {
47192 return new Signing(attrs);
47193 }
47194 static solid(attrs) {
47195 return new Solid(attrs);
47196 }
47197 static speak(attrs) {
47198 return new Speak(attrs);
47199 }
47200 static stipple(attrs) {
47201 return new Stipple(attrs);
47202 }
47203 static subform(attrs) {
47204 return new Subform(attrs);
47205 }
47206 static subformSet(attrs) {
47207 return new SubformSet(attrs);
47208 }
47209 static subjectDN(attrs) {
47210 return new SubjectDN(attrs);
47211 }
47212 static subjectDNs(attrs) {
47213 return new SubjectDNs(attrs);
47214 }
47215 static submit(attrs) {
47216 return new Submit(attrs);
47217 }
47218 static template(attrs) {
47219 return new Template(attrs);
47220 }
47221 static text(attrs) {
47222 return new Text(attrs);
47223 }
47224 static textEdit(attrs) {
47225 return new TextEdit(attrs);
47226 }
47227 static time(attrs) {
47228 return new Time(attrs);
47229 }
47230 static timeStamp(attrs) {
47231 return new TimeStamp(attrs);
47232 }
47233 static toolTip(attrs) {
47234 return new ToolTip(attrs);
47235 }
47236 static traversal(attrs) {
47237 return new Traversal(attrs);
47238 }
47239 static traverse(attrs) {
47240 return new Traverse(attrs);
47241 }
47242 static ui(attrs) {
47243 return new Ui(attrs);
47244 }
47245 static validate(attrs) {
47246 return new Validate(attrs);
47247 }
47248 static value(attrs) {
47249 return new Value(attrs);
47250 }
47251 static variables(attrs) {
47252 return new Variables(attrs);
47253 }
47254}
47255
47256;// CONCATENATED MODULE: ./src/core/xfa/bind.js
47257
47258
47259
47260
47261
47262
47263const bind_NS_DATASETS = NamespaceIds.datasets.id;
47264function createText(content) {
47265 const node = new Text({});
47266 node[$content] = content;
47267 return node;
47268}
47269class Binder {
47270 constructor(root) {
47271 this.root = root;
47272 this.datasets = root.datasets;
47273 this.data = root.datasets?.data || new XmlObject(NamespaceIds.datasets.id, "data");
47274 this.emptyMerge = this.data[$getChildren]().length === 0;
47275 this.root.form = this.form = root.template[$clone]();
47276 }
47277 _isConsumeData() {
47278 return !this.emptyMerge && this._mergeMode;
47279 }
47280 _isMatchTemplate() {
47281 return !this._isConsumeData();
47282 }
47283 bind() {
47284 this._bindElement(this.form, this.data);
47285 return this.form;
47286 }
47287 getData() {
47288 return this.data;
47289 }
47290 _bindValue(formNode, data, picture) {
47291 formNode[$data] = data;
47292 if (formNode[$hasSettableValue]()) {
47293 if (data[$isDataValue]()) {
47294 const value = data[$getDataValue]();
47295 formNode[$setValue](createText(value));
47296 } else if (formNode instanceof Field && formNode.ui?.choiceList?.open === "multiSelect") {
47297 const value = data[$getChildren]().map(child => child[$content].trim()).join("\n");
47298 formNode[$setValue](createText(value));
47299 } else if (this._isConsumeData()) {
47300 warn(`XFA - Nodes haven't the same type.`);
47301 }
47302 } else if (!data[$isDataValue]() || this._isMatchTemplate()) {
47303 this._bindElement(formNode, data);
47304 } else {
47305 warn(`XFA - Nodes haven't the same type.`);
47306 }
47307 }
47308 _findDataByNameToConsume(name, isValue, dataNode, global) {
47309 if (!name) {
47310 return null;
47311 }
47312 let generator, match;
47313 for (let i = 0; i < 3; i++) {
47314 generator = dataNode[$getRealChildrenByNameIt](name, false, true);
47315 while (true) {
47316 match = generator.next().value;
47317 if (!match) {
47318 break;
47319 }
47320 if (isValue === match[$isDataValue]()) {
47321 return match;
47322 }
47323 }
47324 if (dataNode[$namespaceId] === NamespaceIds.datasets.id && dataNode[$nodeName] === "data") {
47325 break;
47326 }
47327 dataNode = dataNode[$getParent]();
47328 }
47329 if (!global) {
47330 return null;
47331 }
47332 generator = this.data[$getRealChildrenByNameIt](name, true, false);
47333 match = generator.next().value;
47334 if (match) {
47335 return match;
47336 }
47337 generator = this.data[$getAttributeIt](name, true);
47338 match = generator.next().value;
47339 if (match?.[$isDataValue]()) {
47340 return match;
47341 }
47342 return null;
47343 }
47344 _setProperties(formNode, dataNode) {
47345 if (!formNode.hasOwnProperty("setProperty")) {
47346 return;
47347 }
47348 for (const {
47349 ref,
47350 target,
47351 connection
47352 } of formNode.setProperty.children) {
47353 if (connection) {
47354 continue;
47355 }
47356 if (!ref) {
47357 continue;
47358 }
47359 const nodes = searchNode(this.root, dataNode, ref, false, false);
47360 if (!nodes) {
47361 warn(`XFA - Invalid reference: ${ref}.`);
47362 continue;
47363 }
47364 const [node] = nodes;
47365 if (!node[$isDescendent](this.data)) {
47366 warn(`XFA - Invalid node: must be a data node.`);
47367 continue;
47368 }
47369 const targetNodes = searchNode(this.root, formNode, target, false, false);
47370 if (!targetNodes) {
47371 warn(`XFA - Invalid target: ${target}.`);
47372 continue;
47373 }
47374 const [targetNode] = targetNodes;
47375 if (!targetNode[$isDescendent](formNode)) {
47376 warn(`XFA - Invalid target: must be a property or subproperty.`);
47377 continue;
47378 }
47379 const targetParent = targetNode[$getParent]();
47380 if (targetNode instanceof SetProperty || targetParent instanceof SetProperty) {
47381 warn(`XFA - Invalid target: cannot be a setProperty or one of its properties.`);
47382 continue;
47383 }
47384 if (targetNode instanceof BindItems || targetParent instanceof BindItems) {
47385 warn(`XFA - Invalid target: cannot be a bindItems or one of its properties.`);
47386 continue;
47387 }
47388 const content = node[$text]();
47389 const name = targetNode[$nodeName];
47390 if (targetNode instanceof XFAAttribute) {
47391 const attrs = Object.create(null);
47392 attrs[name] = content;
47393 const obj = Reflect.construct(Object.getPrototypeOf(targetParent).constructor, [attrs]);
47394 targetParent[name] = obj[name];
47395 continue;
47396 }
47397 if (!targetNode.hasOwnProperty($content)) {
47398 warn(`XFA - Invalid node to use in setProperty`);
47399 continue;
47400 }
47401 targetNode[$data] = node;
47402 targetNode[$content] = content;
47403 targetNode[$finalize]();
47404 }
47405 }
47406 _bindItems(formNode, dataNode) {
47407 if (!formNode.hasOwnProperty("items") || !formNode.hasOwnProperty("bindItems") || formNode.bindItems.isEmpty()) {
47408 return;
47409 }
47410 for (const item of formNode.items.children) {
47411 formNode[$removeChild](item);
47412 }
47413 formNode.items.clear();
47414 const labels = new Items({});
47415 const values = new Items({});
47416 formNode[$appendChild](labels);
47417 formNode.items.push(labels);
47418 formNode[$appendChild](values);
47419 formNode.items.push(values);
47420 for (const {
47421 ref,
47422 labelRef,
47423 valueRef,
47424 connection
47425 } of formNode.bindItems.children) {
47426 if (connection) {
47427 continue;
47428 }
47429 if (!ref) {
47430 continue;
47431 }
47432 const nodes = searchNode(this.root, dataNode, ref, false, false);
47433 if (!nodes) {
47434 warn(`XFA - Invalid reference: ${ref}.`);
47435 continue;
47436 }
47437 for (const node of nodes) {
47438 if (!node[$isDescendent](this.datasets)) {
47439 warn(`XFA - Invalid ref (${ref}): must be a datasets child.`);
47440 continue;
47441 }
47442 const labelNodes = searchNode(this.root, node, labelRef, true, false);
47443 if (!labelNodes) {
47444 warn(`XFA - Invalid label: ${labelRef}.`);
47445 continue;
47446 }
47447 const [labelNode] = labelNodes;
47448 if (!labelNode[$isDescendent](this.datasets)) {
47449 warn(`XFA - Invalid label: must be a datasets child.`);
47450 continue;
47451 }
47452 const valueNodes = searchNode(this.root, node, valueRef, true, false);
47453 if (!valueNodes) {
47454 warn(`XFA - Invalid value: ${valueRef}.`);
47455 continue;
47456 }
47457 const [valueNode] = valueNodes;
47458 if (!valueNode[$isDescendent](this.datasets)) {
47459 warn(`XFA - Invalid value: must be a datasets child.`);
47460 continue;
47461 }
47462 const label = createText(labelNode[$text]());
47463 const value = createText(valueNode[$text]());
47464 labels[$appendChild](label);
47465 labels.text.push(label);
47466 values[$appendChild](value);
47467 values.text.push(value);
47468 }
47469 }
47470 }
47471 _bindOccurrences(formNode, matches, picture) {
47472 let baseClone;
47473 if (matches.length > 1) {
47474 baseClone = formNode[$clone]();
47475 baseClone[$removeChild](baseClone.occur);
47476 baseClone.occur = null;
47477 }
47478 this._bindValue(formNode, matches[0], picture);
47479 this._setProperties(formNode, matches[0]);
47480 this._bindItems(formNode, matches[0]);
47481 if (matches.length === 1) {
47482 return;
47483 }
47484 const parent = formNode[$getParent]();
47485 const name = formNode[$nodeName];
47486 const pos = parent[$indexOf](formNode);
47487 for (let i = 1, ii = matches.length; i < ii; i++) {
47488 const match = matches[i];
47489 const clone = baseClone[$clone]();
47490 parent[name].push(clone);
47491 parent[$insertAt](pos + i, clone);
47492 this._bindValue(clone, match, picture);
47493 this._setProperties(clone, match);
47494 this._bindItems(clone, match);
47495 }
47496 }
47497 _createOccurrences(formNode) {
47498 if (!this.emptyMerge) {
47499 return;
47500 }
47501 const {
47502 occur
47503 } = formNode;
47504 if (!occur || occur.initial <= 1) {
47505 return;
47506 }
47507 const parent = formNode[$getParent]();
47508 const name = formNode[$nodeName];
47509 if (!(parent[name] instanceof XFAObjectArray)) {
47510 return;
47511 }
47512 let currentNumber;
47513 if (formNode.name) {
47514 currentNumber = parent[name].children.filter(e => e.name === formNode.name).length;
47515 } else {
47516 currentNumber = parent[name].children.length;
47517 }
47518 const pos = parent[$indexOf](formNode) + 1;
47519 const ii = occur.initial - currentNumber;
47520 if (ii) {
47521 const nodeClone = formNode[$clone]();
47522 nodeClone[$removeChild](nodeClone.occur);
47523 nodeClone.occur = null;
47524 parent[name].push(nodeClone);
47525 parent[$insertAt](pos, nodeClone);
47526 for (let i = 1; i < ii; i++) {
47527 const clone = nodeClone[$clone]();
47528 parent[name].push(clone);
47529 parent[$insertAt](pos + i, clone);
47530 }
47531 }
47532 }
47533 _getOccurInfo(formNode) {
47534 const {
47535 name,
47536 occur
47537 } = formNode;
47538 if (!occur || !name) {
47539 return [1, 1];
47540 }
47541 const max = occur.max === -1 ? Infinity : occur.max;
47542 return [occur.min, max];
47543 }
47544 _setAndBind(formNode, dataNode) {
47545 this._setProperties(formNode, dataNode);
47546 this._bindItems(formNode, dataNode);
47547 this._bindElement(formNode, dataNode);
47548 }
47549 _bindElement(formNode, dataNode) {
47550 const uselessNodes = [];
47551 this._createOccurrences(formNode);
47552 for (const child of formNode[$getChildren]()) {
47553 if (child[$data]) {
47554 continue;
47555 }
47556 if (this._mergeMode === undefined && child[$nodeName] === "subform") {
47557 this._mergeMode = child.mergeMode === "consumeData";
47558 const dataChildren = dataNode[$getChildren]();
47559 if (dataChildren.length > 0) {
47560 this._bindOccurrences(child, [dataChildren[0]], null);
47561 } else if (this.emptyMerge) {
47562 const nsId = dataNode[$namespaceId] === bind_NS_DATASETS ? -1 : dataNode[$namespaceId];
47563 const dataChild = child[$data] = new XmlObject(nsId, child.name || "root");
47564 dataNode[$appendChild](dataChild);
47565 this._bindElement(child, dataChild);
47566 }
47567 continue;
47568 }
47569 if (!child[$isBindable]()) {
47570 continue;
47571 }
47572 let global = false;
47573 let picture = null;
47574 let ref = null;
47575 let match = null;
47576 if (child.bind) {
47577 switch (child.bind.match) {
47578 case "none":
47579 this._setAndBind(child, dataNode);
47580 continue;
47581 case "global":
47582 global = true;
47583 break;
47584 case "dataRef":
47585 if (!child.bind.ref) {
47586 warn(`XFA - ref is empty in node ${child[$nodeName]}.`);
47587 this._setAndBind(child, dataNode);
47588 continue;
47589 }
47590 ref = child.bind.ref;
47591 break;
47592 default:
47593 break;
47594 }
47595 if (child.bind.picture) {
47596 picture = child.bind.picture[$content];
47597 }
47598 }
47599 const [min, max] = this._getOccurInfo(child);
47600 if (ref) {
47601 match = searchNode(this.root, dataNode, ref, true, false);
47602 if (match === null) {
47603 match = createDataNode(this.data, dataNode, ref);
47604 if (!match) {
47605 continue;
47606 }
47607 if (this._isConsumeData()) {
47608 match[$consumed] = true;
47609 }
47610 this._setAndBind(child, match);
47611 continue;
47612 } else {
47613 if (this._isConsumeData()) {
47614 match = match.filter(node => !node[$consumed]);
47615 }
47616 if (match.length > max) {
47617 match = match.slice(0, max);
47618 } else if (match.length === 0) {
47619 match = null;
47620 }
47621 if (match && this._isConsumeData()) {
47622 match.forEach(node => {
47623 node[$consumed] = true;
47624 });
47625 }
47626 }
47627 } else {
47628 if (!child.name) {
47629 this._setAndBind(child, dataNode);
47630 continue;
47631 }
47632 if (this._isConsumeData()) {
47633 const matches = [];
47634 while (matches.length < max) {
47635 const found = this._findDataByNameToConsume(child.name, child[$hasSettableValue](), dataNode, global);
47636 if (!found) {
47637 break;
47638 }
47639 found[$consumed] = true;
47640 matches.push(found);
47641 }
47642 match = matches.length > 0 ? matches : null;
47643 } else {
47644 match = dataNode[$getRealChildrenByNameIt](child.name, false, this.emptyMerge).next().value;
47645 if (!match) {
47646 if (min === 0) {
47647 uselessNodes.push(child);
47648 continue;
47649 }
47650 const nsId = dataNode[$namespaceId] === bind_NS_DATASETS ? -1 : dataNode[$namespaceId];
47651 match = child[$data] = new XmlObject(nsId, child.name);
47652 if (this.emptyMerge) {
47653 match[$consumed] = true;
47654 }
47655 dataNode[$appendChild](match);
47656 this._setAndBind(child, match);
47657 continue;
47658 }
47659 if (this.emptyMerge) {
47660 match[$consumed] = true;
47661 }
47662 match = [match];
47663 }
47664 }
47665 if (match) {
47666 this._bindOccurrences(child, match, picture);
47667 } else if (min > 0) {
47668 this._setAndBind(child, dataNode);
47669 } else {
47670 uselessNodes.push(child);
47671 }
47672 }
47673 uselessNodes.forEach(node => node[$getParent]()[$removeChild](node));
47674 }
47675}
47676
47677;// CONCATENATED MODULE: ./src/core/xfa/data.js
47678
47679class DataHandler {
47680 constructor(root, data) {
47681 this.data = data;
47682 this.dataset = root.datasets || null;
47683 }
47684 serialize(storage) {
47685 const stack = [[-1, this.data[$getChildren]()]];
47686 while (stack.length > 0) {
47687 const last = stack.at(-1);
47688 const [i, children] = last;
47689 if (i + 1 === children.length) {
47690 stack.pop();
47691 continue;
47692 }
47693 const child = children[++last[0]];
47694 const storageEntry = storage.get(child[$uid]);
47695 if (storageEntry) {
47696 child[$setValue](storageEntry);
47697 } else {
47698 const attributes = child[$getAttributes]();
47699 for (const value of attributes.values()) {
47700 const entry = storage.get(value[$uid]);
47701 if (entry) {
47702 value[$setValue](entry);
47703 break;
47704 }
47705 }
47706 }
47707 const nodes = child[$getChildren]();
47708 if (nodes.length > 0) {
47709 stack.push([-1, nodes]);
47710 }
47711 }
47712 const buf = [`<xfa:datasets xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">`];
47713 if (this.dataset) {
47714 for (const child of this.dataset[$getChildren]()) {
47715 if (child[$nodeName] !== "data") {
47716 child[$toString](buf);
47717 }
47718 }
47719 }
47720 this.data[$toString](buf);
47721 buf.push("</xfa:datasets>");
47722 return buf.join("");
47723 }
47724}
47725
47726;// CONCATENATED MODULE: ./src/core/xfa/config.js
47727
47728
47729
47730
47731
47732const CONFIG_NS_ID = NamespaceIds.config.id;
47733class Acrobat extends XFAObject {
47734 constructor(attributes) {
47735 super(CONFIG_NS_ID, "acrobat", true);
47736 this.acrobat7 = null;
47737 this.autoSave = null;
47738 this.common = null;
47739 this.validate = null;
47740 this.validateApprovalSignatures = null;
47741 this.submitUrl = new XFAObjectArray();
47742 }
47743}
47744class Acrobat7 extends XFAObject {
47745 constructor(attributes) {
47746 super(CONFIG_NS_ID, "acrobat7", true);
47747 this.dynamicRender = null;
47748 }
47749}
47750class ADBE_JSConsole extends OptionObject {
47751 constructor(attributes) {
47752 super(CONFIG_NS_ID, "ADBE_JSConsole", ["delegate", "Enable", "Disable"]);
47753 }
47754}
47755class ADBE_JSDebugger extends OptionObject {
47756 constructor(attributes) {
47757 super(CONFIG_NS_ID, "ADBE_JSDebugger", ["delegate", "Enable", "Disable"]);
47758 }
47759}
47760class AddSilentPrint extends Option01 {
47761 constructor(attributes) {
47762 super(CONFIG_NS_ID, "addSilentPrint");
47763 }
47764}
47765class AddViewerPreferences extends Option01 {
47766 constructor(attributes) {
47767 super(CONFIG_NS_ID, "addViewerPreferences");
47768 }
47769}
47770class AdjustData extends Option10 {
47771 constructor(attributes) {
47772 super(CONFIG_NS_ID, "adjustData");
47773 }
47774}
47775class AdobeExtensionLevel extends IntegerObject {
47776 constructor(attributes) {
47777 super(CONFIG_NS_ID, "adobeExtensionLevel", 0, n => n >= 1 && n <= 8);
47778 }
47779}
47780class Agent extends XFAObject {
47781 constructor(attributes) {
47782 super(CONFIG_NS_ID, "agent", true);
47783 this.name = attributes.name ? attributes.name.trim() : "";
47784 this.common = new XFAObjectArray();
47785 }
47786}
47787class AlwaysEmbed extends ContentObject {
47788 constructor(attributes) {
47789 super(CONFIG_NS_ID, "alwaysEmbed");
47790 }
47791}
47792class Amd extends StringObject {
47793 constructor(attributes) {
47794 super(CONFIG_NS_ID, "amd");
47795 }
47796}
47797class config_Area extends XFAObject {
47798 constructor(attributes) {
47799 super(CONFIG_NS_ID, "area");
47800 this.level = getInteger({
47801 data: attributes.level,
47802 defaultValue: 0,
47803 validate: n => n >= 1 && n <= 3
47804 });
47805 this.name = getStringOption(attributes.name, ["", "barcode", "coreinit", "deviceDriver", "font", "general", "layout", "merge", "script", "signature", "sourceSet", "templateCache"]);
47806 }
47807}
47808class Attributes extends OptionObject {
47809 constructor(attributes) {
47810 super(CONFIG_NS_ID, "attributes", ["preserve", "delegate", "ignore"]);
47811 }
47812}
47813class AutoSave extends OptionObject {
47814 constructor(attributes) {
47815 super(CONFIG_NS_ID, "autoSave", ["disabled", "enabled"]);
47816 }
47817}
47818class Base extends StringObject {
47819 constructor(attributes) {
47820 super(CONFIG_NS_ID, "base");
47821 }
47822}
47823class BatchOutput extends XFAObject {
47824 constructor(attributes) {
47825 super(CONFIG_NS_ID, "batchOutput");
47826 this.format = getStringOption(attributes.format, ["none", "concat", "zip", "zipCompress"]);
47827 }
47828}
47829class BehaviorOverride extends ContentObject {
47830 constructor(attributes) {
47831 super(CONFIG_NS_ID, "behaviorOverride");
47832 }
47833 [$finalize]() {
47834 this[$content] = new Map(this[$content].trim().split(/\s+/).filter(x => x.includes(":")).map(x => x.split(":", 2)));
47835 }
47836}
47837class Cache extends XFAObject {
47838 constructor(attributes) {
47839 super(CONFIG_NS_ID, "cache", true);
47840 this.templateCache = null;
47841 }
47842}
47843class Change extends Option01 {
47844 constructor(attributes) {
47845 super(CONFIG_NS_ID, "change");
47846 }
47847}
47848class Common extends XFAObject {
47849 constructor(attributes) {
47850 super(CONFIG_NS_ID, "common", true);
47851 this.data = null;
47852 this.locale = null;
47853 this.localeSet = null;
47854 this.messaging = null;
47855 this.suppressBanner = null;
47856 this.template = null;
47857 this.validationMessaging = null;
47858 this.versionControl = null;
47859 this.log = new XFAObjectArray();
47860 }
47861}
47862class Compress extends XFAObject {
47863 constructor(attributes) {
47864 super(CONFIG_NS_ID, "compress");
47865 this.scope = getStringOption(attributes.scope, ["imageOnly", "document"]);
47866 }
47867}
47868class CompressLogicalStructure extends Option01 {
47869 constructor(attributes) {
47870 super(CONFIG_NS_ID, "compressLogicalStructure");
47871 }
47872}
47873class CompressObjectStream extends Option10 {
47874 constructor(attributes) {
47875 super(CONFIG_NS_ID, "compressObjectStream");
47876 }
47877}
47878class Compression extends XFAObject {
47879 constructor(attributes) {
47880 super(CONFIG_NS_ID, "compression", true);
47881 this.compressLogicalStructure = null;
47882 this.compressObjectStream = null;
47883 this.level = null;
47884 this.type = null;
47885 }
47886}
47887class Config extends XFAObject {
47888 constructor(attributes) {
47889 super(CONFIG_NS_ID, "config", true);
47890 this.acrobat = null;
47891 this.present = null;
47892 this.trace = null;
47893 this.agent = new XFAObjectArray();
47894 }
47895}
47896class Conformance extends OptionObject {
47897 constructor(attributes) {
47898 super(CONFIG_NS_ID, "conformance", ["A", "B"]);
47899 }
47900}
47901class ContentCopy extends Option01 {
47902 constructor(attributes) {
47903 super(CONFIG_NS_ID, "contentCopy");
47904 }
47905}
47906class Copies extends IntegerObject {
47907 constructor(attributes) {
47908 super(CONFIG_NS_ID, "copies", 1, n => n >= 1);
47909 }
47910}
47911class Creator extends StringObject {
47912 constructor(attributes) {
47913 super(CONFIG_NS_ID, "creator");
47914 }
47915}
47916class CurrentPage extends IntegerObject {
47917 constructor(attributes) {
47918 super(CONFIG_NS_ID, "currentPage", 0, n => n >= 0);
47919 }
47920}
47921class Data extends XFAObject {
47922 constructor(attributes) {
47923 super(CONFIG_NS_ID, "data", true);
47924 this.adjustData = null;
47925 this.attributes = null;
47926 this.incrementalLoad = null;
47927 this.outputXSL = null;
47928 this.range = null;
47929 this.record = null;
47930 this.startNode = null;
47931 this.uri = null;
47932 this.window = null;
47933 this.xsl = null;
47934 this.excludeNS = new XFAObjectArray();
47935 this.transform = new XFAObjectArray();
47936 }
47937}
47938class Debug extends XFAObject {
47939 constructor(attributes) {
47940 super(CONFIG_NS_ID, "debug", true);
47941 this.uri = null;
47942 }
47943}
47944class DefaultTypeface extends ContentObject {
47945 constructor(attributes) {
47946 super(CONFIG_NS_ID, "defaultTypeface");
47947 this.writingScript = getStringOption(attributes.writingScript, ["*", "Arabic", "Cyrillic", "EastEuropeanRoman", "Greek", "Hebrew", "Japanese", "Korean", "Roman", "SimplifiedChinese", "Thai", "TraditionalChinese", "Vietnamese"]);
47948 }
47949}
47950class Destination extends OptionObject {
47951 constructor(attributes) {
47952 super(CONFIG_NS_ID, "destination", ["pdf", "pcl", "ps", "webClient", "zpl"]);
47953 }
47954}
47955class DocumentAssembly extends Option01 {
47956 constructor(attributes) {
47957 super(CONFIG_NS_ID, "documentAssembly");
47958 }
47959}
47960class Driver extends XFAObject {
47961 constructor(attributes) {
47962 super(CONFIG_NS_ID, "driver", true);
47963 this.name = attributes.name ? attributes.name.trim() : "";
47964 this.fontInfo = null;
47965 this.xdc = null;
47966 }
47967}
47968class DuplexOption extends OptionObject {
47969 constructor(attributes) {
47970 super(CONFIG_NS_ID, "duplexOption", ["simplex", "duplexFlipLongEdge", "duplexFlipShortEdge"]);
47971 }
47972}
47973class DynamicRender extends OptionObject {
47974 constructor(attributes) {
47975 super(CONFIG_NS_ID, "dynamicRender", ["forbidden", "required"]);
47976 }
47977}
47978class Embed extends Option01 {
47979 constructor(attributes) {
47980 super(CONFIG_NS_ID, "embed");
47981 }
47982}
47983class config_Encrypt extends Option01 {
47984 constructor(attributes) {
47985 super(CONFIG_NS_ID, "encrypt");
47986 }
47987}
47988class config_Encryption extends XFAObject {
47989 constructor(attributes) {
47990 super(CONFIG_NS_ID, "encryption", true);
47991 this.encrypt = null;
47992 this.encryptionLevel = null;
47993 this.permissions = null;
47994 }
47995}
47996class EncryptionLevel extends OptionObject {
47997 constructor(attributes) {
47998 super(CONFIG_NS_ID, "encryptionLevel", ["40bit", "128bit"]);
47999 }
48000}
48001class Enforce extends StringObject {
48002 constructor(attributes) {
48003 super(CONFIG_NS_ID, "enforce");
48004 }
48005}
48006class Equate extends XFAObject {
48007 constructor(attributes) {
48008 super(CONFIG_NS_ID, "equate");
48009 this.force = getInteger({
48010 data: attributes.force,
48011 defaultValue: 1,
48012 validate: n => n === 0
48013 });
48014 this.from = attributes.from || "";
48015 this.to = attributes.to || "";
48016 }
48017}
48018class EquateRange extends XFAObject {
48019 constructor(attributes) {
48020 super(CONFIG_NS_ID, "equateRange");
48021 this.from = attributes.from || "";
48022 this.to = attributes.to || "";
48023 this._unicodeRange = attributes.unicodeRange || "";
48024 }
48025 get unicodeRange() {
48026 const ranges = [];
48027 const unicodeRegex = /U\+([0-9a-fA-F]+)/;
48028 const unicodeRange = this._unicodeRange;
48029 for (let range of unicodeRange.split(",").map(x => x.trim()).filter(x => !!x)) {
48030 range = range.split("-", 2).map(x => {
48031 const found = x.match(unicodeRegex);
48032 if (!found) {
48033 return 0;
48034 }
48035 return parseInt(found[1], 16);
48036 });
48037 if (range.length === 1) {
48038 range.push(range[0]);
48039 }
48040 ranges.push(range);
48041 }
48042 return shadow(this, "unicodeRange", ranges);
48043 }
48044}
48045class Exclude extends ContentObject {
48046 constructor(attributes) {
48047 super(CONFIG_NS_ID, "exclude");
48048 }
48049 [$finalize]() {
48050 this[$content] = this[$content].trim().split(/\s+/).filter(x => x && ["calculate", "close", "enter", "exit", "initialize", "ready", "validate"].includes(x));
48051 }
48052}
48053class ExcludeNS extends StringObject {
48054 constructor(attributes) {
48055 super(CONFIG_NS_ID, "excludeNS");
48056 }
48057}
48058class FlipLabel extends OptionObject {
48059 constructor(attributes) {
48060 super(CONFIG_NS_ID, "flipLabel", ["usePrinterSetting", "on", "off"]);
48061 }
48062}
48063class config_FontInfo extends XFAObject {
48064 constructor(attributes) {
48065 super(CONFIG_NS_ID, "fontInfo", true);
48066 this.embed = null;
48067 this.map = null;
48068 this.subsetBelow = null;
48069 this.alwaysEmbed = new XFAObjectArray();
48070 this.defaultTypeface = new XFAObjectArray();
48071 this.neverEmbed = new XFAObjectArray();
48072 }
48073}
48074class FormFieldFilling extends Option01 {
48075 constructor(attributes) {
48076 super(CONFIG_NS_ID, "formFieldFilling");
48077 }
48078}
48079class GroupParent extends StringObject {
48080 constructor(attributes) {
48081 super(CONFIG_NS_ID, "groupParent");
48082 }
48083}
48084class IfEmpty extends OptionObject {
48085 constructor(attributes) {
48086 super(CONFIG_NS_ID, "ifEmpty", ["dataValue", "dataGroup", "ignore", "remove"]);
48087 }
48088}
48089class IncludeXDPContent extends StringObject {
48090 constructor(attributes) {
48091 super(CONFIG_NS_ID, "includeXDPContent");
48092 }
48093}
48094class IncrementalLoad extends OptionObject {
48095 constructor(attributes) {
48096 super(CONFIG_NS_ID, "incrementalLoad", ["none", "forwardOnly"]);
48097 }
48098}
48099class IncrementalMerge extends Option01 {
48100 constructor(attributes) {
48101 super(CONFIG_NS_ID, "incrementalMerge");
48102 }
48103}
48104class Interactive extends Option01 {
48105 constructor(attributes) {
48106 super(CONFIG_NS_ID, "interactive");
48107 }
48108}
48109class Jog extends OptionObject {
48110 constructor(attributes) {
48111 super(CONFIG_NS_ID, "jog", ["usePrinterSetting", "none", "pageSet"]);
48112 }
48113}
48114class LabelPrinter extends XFAObject {
48115 constructor(attributes) {
48116 super(CONFIG_NS_ID, "labelPrinter", true);
48117 this.name = getStringOption(attributes.name, ["zpl", "dpl", "ipl", "tcpl"]);
48118 this.batchOutput = null;
48119 this.flipLabel = null;
48120 this.fontInfo = null;
48121 this.xdc = null;
48122 }
48123}
48124class Layout extends OptionObject {
48125 constructor(attributes) {
48126 super(CONFIG_NS_ID, "layout", ["paginate", "panel"]);
48127 }
48128}
48129class Level extends IntegerObject {
48130 constructor(attributes) {
48131 super(CONFIG_NS_ID, "level", 0, n => n > 0);
48132 }
48133}
48134class Linearized extends Option01 {
48135 constructor(attributes) {
48136 super(CONFIG_NS_ID, "linearized");
48137 }
48138}
48139class Locale extends StringObject {
48140 constructor(attributes) {
48141 super(CONFIG_NS_ID, "locale");
48142 }
48143}
48144class LocaleSet extends StringObject {
48145 constructor(attributes) {
48146 super(CONFIG_NS_ID, "localeSet");
48147 }
48148}
48149class Log extends XFAObject {
48150 constructor(attributes) {
48151 super(CONFIG_NS_ID, "log", true);
48152 this.mode = null;
48153 this.threshold = null;
48154 this.to = null;
48155 this.uri = null;
48156 }
48157}
48158class MapElement extends XFAObject {
48159 constructor(attributes) {
48160 super(CONFIG_NS_ID, "map", true);
48161 this.equate = new XFAObjectArray();
48162 this.equateRange = new XFAObjectArray();
48163 }
48164}
48165class MediumInfo extends XFAObject {
48166 constructor(attributes) {
48167 super(CONFIG_NS_ID, "mediumInfo", true);
48168 this.map = null;
48169 }
48170}
48171class config_Message extends XFAObject {
48172 constructor(attributes) {
48173 super(CONFIG_NS_ID, "message", true);
48174 this.msgId = null;
48175 this.severity = null;
48176 }
48177}
48178class Messaging extends XFAObject {
48179 constructor(attributes) {
48180 super(CONFIG_NS_ID, "messaging", true);
48181 this.message = new XFAObjectArray();
48182 }
48183}
48184class Mode extends OptionObject {
48185 constructor(attributes) {
48186 super(CONFIG_NS_ID, "mode", ["append", "overwrite"]);
48187 }
48188}
48189class ModifyAnnots extends Option01 {
48190 constructor(attributes) {
48191 super(CONFIG_NS_ID, "modifyAnnots");
48192 }
48193}
48194class MsgId extends IntegerObject {
48195 constructor(attributes) {
48196 super(CONFIG_NS_ID, "msgId", 1, n => n >= 1);
48197 }
48198}
48199class NameAttr extends StringObject {
48200 constructor(attributes) {
48201 super(CONFIG_NS_ID, "nameAttr");
48202 }
48203}
48204class NeverEmbed extends ContentObject {
48205 constructor(attributes) {
48206 super(CONFIG_NS_ID, "neverEmbed");
48207 }
48208}
48209class NumberOfCopies extends IntegerObject {
48210 constructor(attributes) {
48211 super(CONFIG_NS_ID, "numberOfCopies", null, n => n >= 2 && n <= 5);
48212 }
48213}
48214class OpenAction extends XFAObject {
48215 constructor(attributes) {
48216 super(CONFIG_NS_ID, "openAction", true);
48217 this.destination = null;
48218 }
48219}
48220class Output extends XFAObject {
48221 constructor(attributes) {
48222 super(CONFIG_NS_ID, "output", true);
48223 this.to = null;
48224 this.type = null;
48225 this.uri = null;
48226 }
48227}
48228class OutputBin extends StringObject {
48229 constructor(attributes) {
48230 super(CONFIG_NS_ID, "outputBin");
48231 }
48232}
48233class OutputXSL extends XFAObject {
48234 constructor(attributes) {
48235 super(CONFIG_NS_ID, "outputXSL", true);
48236 this.uri = null;
48237 }
48238}
48239class Overprint extends OptionObject {
48240 constructor(attributes) {
48241 super(CONFIG_NS_ID, "overprint", ["none", "both", "draw", "field"]);
48242 }
48243}
48244class Packets extends StringObject {
48245 constructor(attributes) {
48246 super(CONFIG_NS_ID, "packets");
48247 }
48248 [$finalize]() {
48249 if (this[$content] === "*") {
48250 return;
48251 }
48252 this[$content] = this[$content].trim().split(/\s+/).filter(x => ["config", "datasets", "template", "xfdf", "xslt"].includes(x));
48253 }
48254}
48255class PageOffset extends XFAObject {
48256 constructor(attributes) {
48257 super(CONFIG_NS_ID, "pageOffset");
48258 this.x = getInteger({
48259 data: attributes.x,
48260 defaultValue: "useXDCSetting",
48261 validate: n => true
48262 });
48263 this.y = getInteger({
48264 data: attributes.y,
48265 defaultValue: "useXDCSetting",
48266 validate: n => true
48267 });
48268 }
48269}
48270class PageRange extends StringObject {
48271 constructor(attributes) {
48272 super(CONFIG_NS_ID, "pageRange");
48273 }
48274 [$finalize]() {
48275 const numbers = this[$content].trim().split(/\s+/).map(x => parseInt(x, 10));
48276 const ranges = [];
48277 for (let i = 0, ii = numbers.length; i < ii; i += 2) {
48278 ranges.push(numbers.slice(i, i + 2));
48279 }
48280 this[$content] = ranges;
48281 }
48282}
48283class Pagination extends OptionObject {
48284 constructor(attributes) {
48285 super(CONFIG_NS_ID, "pagination", ["simplex", "duplexShortEdge", "duplexLongEdge"]);
48286 }
48287}
48288class PaginationOverride extends OptionObject {
48289 constructor(attributes) {
48290 super(CONFIG_NS_ID, "paginationOverride", ["none", "forceDuplex", "forceDuplexLongEdge", "forceDuplexShortEdge", "forceSimplex"]);
48291 }
48292}
48293class Part extends IntegerObject {
48294 constructor(attributes) {
48295 super(CONFIG_NS_ID, "part", 1, n => false);
48296 }
48297}
48298class Pcl extends XFAObject {
48299 constructor(attributes) {
48300 super(CONFIG_NS_ID, "pcl", true);
48301 this.name = attributes.name || "";
48302 this.batchOutput = null;
48303 this.fontInfo = null;
48304 this.jog = null;
48305 this.mediumInfo = null;
48306 this.outputBin = null;
48307 this.pageOffset = null;
48308 this.staple = null;
48309 this.xdc = null;
48310 }
48311}
48312class Pdf extends XFAObject {
48313 constructor(attributes) {
48314 super(CONFIG_NS_ID, "pdf", true);
48315 this.name = attributes.name || "";
48316 this.adobeExtensionLevel = null;
48317 this.batchOutput = null;
48318 this.compression = null;
48319 this.creator = null;
48320 this.encryption = null;
48321 this.fontInfo = null;
48322 this.interactive = null;
48323 this.linearized = null;
48324 this.openAction = null;
48325 this.pdfa = null;
48326 this.producer = null;
48327 this.renderPolicy = null;
48328 this.scriptModel = null;
48329 this.silentPrint = null;
48330 this.submitFormat = null;
48331 this.tagged = null;
48332 this.version = null;
48333 this.viewerPreferences = null;
48334 this.xdc = null;
48335 }
48336}
48337class Pdfa extends XFAObject {
48338 constructor(attributes) {
48339 super(CONFIG_NS_ID, "pdfa", true);
48340 this.amd = null;
48341 this.conformance = null;
48342 this.includeXDPContent = null;
48343 this.part = null;
48344 }
48345}
48346class Permissions extends XFAObject {
48347 constructor(attributes) {
48348 super(CONFIG_NS_ID, "permissions", true);
48349 this.accessibleContent = null;
48350 this.change = null;
48351 this.contentCopy = null;
48352 this.documentAssembly = null;
48353 this.formFieldFilling = null;
48354 this.modifyAnnots = null;
48355 this.plaintextMetadata = null;
48356 this.print = null;
48357 this.printHighQuality = null;
48358 }
48359}
48360class PickTrayByPDFSize extends Option01 {
48361 constructor(attributes) {
48362 super(CONFIG_NS_ID, "pickTrayByPDFSize");
48363 }
48364}
48365class config_Picture extends StringObject {
48366 constructor(attributes) {
48367 super(CONFIG_NS_ID, "picture");
48368 }
48369}
48370class PlaintextMetadata extends Option01 {
48371 constructor(attributes) {
48372 super(CONFIG_NS_ID, "plaintextMetadata");
48373 }
48374}
48375class Presence extends OptionObject {
48376 constructor(attributes) {
48377 super(CONFIG_NS_ID, "presence", ["preserve", "dissolve", "dissolveStructure", "ignore", "remove"]);
48378 }
48379}
48380class Present extends XFAObject {
48381 constructor(attributes) {
48382 super(CONFIG_NS_ID, "present", true);
48383 this.behaviorOverride = null;
48384 this.cache = null;
48385 this.common = null;
48386 this.copies = null;
48387 this.destination = null;
48388 this.incrementalMerge = null;
48389 this.layout = null;
48390 this.output = null;
48391 this.overprint = null;
48392 this.pagination = null;
48393 this.paginationOverride = null;
48394 this.script = null;
48395 this.validate = null;
48396 this.xdp = null;
48397 this.driver = new XFAObjectArray();
48398 this.labelPrinter = new XFAObjectArray();
48399 this.pcl = new XFAObjectArray();
48400 this.pdf = new XFAObjectArray();
48401 this.ps = new XFAObjectArray();
48402 this.submitUrl = new XFAObjectArray();
48403 this.webClient = new XFAObjectArray();
48404 this.zpl = new XFAObjectArray();
48405 }
48406}
48407class Print extends Option01 {
48408 constructor(attributes) {
48409 super(CONFIG_NS_ID, "print");
48410 }
48411}
48412class PrintHighQuality extends Option01 {
48413 constructor(attributes) {
48414 super(CONFIG_NS_ID, "printHighQuality");
48415 }
48416}
48417class PrintScaling extends OptionObject {
48418 constructor(attributes) {
48419 super(CONFIG_NS_ID, "printScaling", ["appdefault", "noScaling"]);
48420 }
48421}
48422class PrinterName extends StringObject {
48423 constructor(attributes) {
48424 super(CONFIG_NS_ID, "printerName");
48425 }
48426}
48427class Producer extends StringObject {
48428 constructor(attributes) {
48429 super(CONFIG_NS_ID, "producer");
48430 }
48431}
48432class Ps extends XFAObject {
48433 constructor(attributes) {
48434 super(CONFIG_NS_ID, "ps", true);
48435 this.name = attributes.name || "";
48436 this.batchOutput = null;
48437 this.fontInfo = null;
48438 this.jog = null;
48439 this.mediumInfo = null;
48440 this.outputBin = null;
48441 this.staple = null;
48442 this.xdc = null;
48443 }
48444}
48445class Range extends ContentObject {
48446 constructor(attributes) {
48447 super(CONFIG_NS_ID, "range");
48448 }
48449 [$finalize]() {
48450 this[$content] = this[$content].trim().split(/\s*,\s*/, 2).map(range => range.split("-").map(x => parseInt(x.trim(), 10))).filter(range => range.every(x => !isNaN(x))).map(range => {
48451 if (range.length === 1) {
48452 range.push(range[0]);
48453 }
48454 return range;
48455 });
48456 }
48457}
48458class Record extends ContentObject {
48459 constructor(attributes) {
48460 super(CONFIG_NS_ID, "record");
48461 }
48462 [$finalize]() {
48463 this[$content] = this[$content].trim();
48464 const n = parseInt(this[$content], 10);
48465 if (!isNaN(n) && n >= 0) {
48466 this[$content] = n;
48467 }
48468 }
48469}
48470class Relevant extends ContentObject {
48471 constructor(attributes) {
48472 super(CONFIG_NS_ID, "relevant");
48473 }
48474 [$finalize]() {
48475 this[$content] = this[$content].trim().split(/\s+/);
48476 }
48477}
48478class Rename extends ContentObject {
48479 constructor(attributes) {
48480 super(CONFIG_NS_ID, "rename");
48481 }
48482 [$finalize]() {
48483 this[$content] = this[$content].trim();
48484 if (this[$content].toLowerCase().startsWith("xml") || new RegExp("[\\p{L}_][\\p{L}\\d._\\p{M}-]*", "u").test(this[$content])) {
48485 warn("XFA - Rename: invalid XFA name");
48486 }
48487 }
48488}
48489class RenderPolicy extends OptionObject {
48490 constructor(attributes) {
48491 super(CONFIG_NS_ID, "renderPolicy", ["server", "client"]);
48492 }
48493}
48494class RunScripts extends OptionObject {
48495 constructor(attributes) {
48496 super(CONFIG_NS_ID, "runScripts", ["both", "client", "none", "server"]);
48497 }
48498}
48499class config_Script extends XFAObject {
48500 constructor(attributes) {
48501 super(CONFIG_NS_ID, "script", true);
48502 this.currentPage = null;
48503 this.exclude = null;
48504 this.runScripts = null;
48505 }
48506}
48507class ScriptModel extends OptionObject {
48508 constructor(attributes) {
48509 super(CONFIG_NS_ID, "scriptModel", ["XFA", "none"]);
48510 }
48511}
48512class Severity extends OptionObject {
48513 constructor(attributes) {
48514 super(CONFIG_NS_ID, "severity", ["ignore", "error", "information", "trace", "warning"]);
48515 }
48516}
48517class SilentPrint extends XFAObject {
48518 constructor(attributes) {
48519 super(CONFIG_NS_ID, "silentPrint", true);
48520 this.addSilentPrint = null;
48521 this.printerName = null;
48522 }
48523}
48524class Staple extends XFAObject {
48525 constructor(attributes) {
48526 super(CONFIG_NS_ID, "staple");
48527 this.mode = getStringOption(attributes.mode, ["usePrinterSetting", "on", "off"]);
48528 }
48529}
48530class StartNode extends StringObject {
48531 constructor(attributes) {
48532 super(CONFIG_NS_ID, "startNode");
48533 }
48534}
48535class StartPage extends IntegerObject {
48536 constructor(attributes) {
48537 super(CONFIG_NS_ID, "startPage", 0, n => true);
48538 }
48539}
48540class SubmitFormat extends OptionObject {
48541 constructor(attributes) {
48542 super(CONFIG_NS_ID, "submitFormat", ["html", "delegate", "fdf", "xml", "pdf"]);
48543 }
48544}
48545class SubmitUrl extends StringObject {
48546 constructor(attributes) {
48547 super(CONFIG_NS_ID, "submitUrl");
48548 }
48549}
48550class SubsetBelow extends IntegerObject {
48551 constructor(attributes) {
48552 super(CONFIG_NS_ID, "subsetBelow", 100, n => n >= 0 && n <= 100);
48553 }
48554}
48555class SuppressBanner extends Option01 {
48556 constructor(attributes) {
48557 super(CONFIG_NS_ID, "suppressBanner");
48558 }
48559}
48560class Tagged extends Option01 {
48561 constructor(attributes) {
48562 super(CONFIG_NS_ID, "tagged");
48563 }
48564}
48565class config_Template extends XFAObject {
48566 constructor(attributes) {
48567 super(CONFIG_NS_ID, "template", true);
48568 this.base = null;
48569 this.relevant = null;
48570 this.startPage = null;
48571 this.uri = null;
48572 this.xsl = null;
48573 }
48574}
48575class Threshold extends OptionObject {
48576 constructor(attributes) {
48577 super(CONFIG_NS_ID, "threshold", ["trace", "error", "information", "warning"]);
48578 }
48579}
48580class To extends OptionObject {
48581 constructor(attributes) {
48582 super(CONFIG_NS_ID, "to", ["null", "memory", "stderr", "stdout", "system", "uri"]);
48583 }
48584}
48585class TemplateCache extends XFAObject {
48586 constructor(attributes) {
48587 super(CONFIG_NS_ID, "templateCache");
48588 this.maxEntries = getInteger({
48589 data: attributes.maxEntries,
48590 defaultValue: 5,
48591 validate: n => n >= 0
48592 });
48593 }
48594}
48595class Trace extends XFAObject {
48596 constructor(attributes) {
48597 super(CONFIG_NS_ID, "trace", true);
48598 this.area = new XFAObjectArray();
48599 }
48600}
48601class config_Transform extends XFAObject {
48602 constructor(attributes) {
48603 super(CONFIG_NS_ID, "transform", true);
48604 this.groupParent = null;
48605 this.ifEmpty = null;
48606 this.nameAttr = null;
48607 this.picture = null;
48608 this.presence = null;
48609 this.rename = null;
48610 this.whitespace = null;
48611 }
48612}
48613class Type extends OptionObject {
48614 constructor(attributes) {
48615 super(CONFIG_NS_ID, "type", ["none", "ascii85", "asciiHex", "ccittfax", "flate", "lzw", "runLength", "native", "xdp", "mergedXDP"]);
48616 }
48617}
48618class Uri extends StringObject {
48619 constructor(attributes) {
48620 super(CONFIG_NS_ID, "uri");
48621 }
48622}
48623class config_Validate extends OptionObject {
48624 constructor(attributes) {
48625 super(CONFIG_NS_ID, "validate", ["preSubmit", "prePrint", "preExecute", "preSave"]);
48626 }
48627}
48628class ValidateApprovalSignatures extends ContentObject {
48629 constructor(attributes) {
48630 super(CONFIG_NS_ID, "validateApprovalSignatures");
48631 }
48632 [$finalize]() {
48633 this[$content] = this[$content].trim().split(/\s+/).filter(x => ["docReady", "postSign"].includes(x));
48634 }
48635}
48636class ValidationMessaging extends OptionObject {
48637 constructor(attributes) {
48638 super(CONFIG_NS_ID, "validationMessaging", ["allMessagesIndividually", "allMessagesTogether", "firstMessageOnly", "noMessages"]);
48639 }
48640}
48641class Version extends OptionObject {
48642 constructor(attributes) {
48643 super(CONFIG_NS_ID, "version", ["1.7", "1.6", "1.5", "1.4", "1.3", "1.2"]);
48644 }
48645}
48646class VersionControl extends XFAObject {
48647 constructor(attributes) {
48648 super(CONFIG_NS_ID, "VersionControl");
48649 this.outputBelow = getStringOption(attributes.outputBelow, ["warn", "error", "update"]);
48650 this.sourceAbove = getStringOption(attributes.sourceAbove, ["warn", "error"]);
48651 this.sourceBelow = getStringOption(attributes.sourceBelow, ["update", "maintain"]);
48652 }
48653}
48654class ViewerPreferences extends XFAObject {
48655 constructor(attributes) {
48656 super(CONFIG_NS_ID, "viewerPreferences", true);
48657 this.ADBE_JSConsole = null;
48658 this.ADBE_JSDebugger = null;
48659 this.addViewerPreferences = null;
48660 this.duplexOption = null;
48661 this.enforce = null;
48662 this.numberOfCopies = null;
48663 this.pageRange = null;
48664 this.pickTrayByPDFSize = null;
48665 this.printScaling = null;
48666 }
48667}
48668class WebClient extends XFAObject {
48669 constructor(attributes) {
48670 super(CONFIG_NS_ID, "webClient", true);
48671 this.name = attributes.name ? attributes.name.trim() : "";
48672 this.fontInfo = null;
48673 this.xdc = null;
48674 }
48675}
48676class Whitespace extends OptionObject {
48677 constructor(attributes) {
48678 super(CONFIG_NS_ID, "whitespace", ["preserve", "ltrim", "normalize", "rtrim", "trim"]);
48679 }
48680}
48681class Window extends ContentObject {
48682 constructor(attributes) {
48683 super(CONFIG_NS_ID, "window");
48684 }
48685 [$finalize]() {
48686 const pair = this[$content].trim().split(/\s*,\s*/, 2).map(x => parseInt(x, 10));
48687 if (pair.some(x => isNaN(x))) {
48688 this[$content] = [0, 0];
48689 return;
48690 }
48691 if (pair.length === 1) {
48692 pair.push(pair[0]);
48693 }
48694 this[$content] = pair;
48695 }
48696}
48697class Xdc extends XFAObject {
48698 constructor(attributes) {
48699 super(CONFIG_NS_ID, "xdc", true);
48700 this.uri = new XFAObjectArray();
48701 this.xsl = new XFAObjectArray();
48702 }
48703}
48704class Xdp extends XFAObject {
48705 constructor(attributes) {
48706 super(CONFIG_NS_ID, "xdp", true);
48707 this.packets = null;
48708 }
48709}
48710class Xsl extends XFAObject {
48711 constructor(attributes) {
48712 super(CONFIG_NS_ID, "xsl", true);
48713 this.debug = null;
48714 this.uri = null;
48715 }
48716}
48717class Zpl extends XFAObject {
48718 constructor(attributes) {
48719 super(CONFIG_NS_ID, "zpl", true);
48720 this.name = attributes.name ? attributes.name.trim() : "";
48721 this.batchOutput = null;
48722 this.flipLabel = null;
48723 this.fontInfo = null;
48724 this.xdc = null;
48725 }
48726}
48727class ConfigNamespace {
48728 static [$buildXFAObject](name, attributes) {
48729 if (ConfigNamespace.hasOwnProperty(name)) {
48730 return ConfigNamespace[name](attributes);
48731 }
48732 return undefined;
48733 }
48734 static acrobat(attrs) {
48735 return new Acrobat(attrs);
48736 }
48737 static acrobat7(attrs) {
48738 return new Acrobat7(attrs);
48739 }
48740 static ADBE_JSConsole(attrs) {
48741 return new ADBE_JSConsole(attrs);
48742 }
48743 static ADBE_JSDebugger(attrs) {
48744 return new ADBE_JSDebugger(attrs);
48745 }
48746 static addSilentPrint(attrs) {
48747 return new AddSilentPrint(attrs);
48748 }
48749 static addViewerPreferences(attrs) {
48750 return new AddViewerPreferences(attrs);
48751 }
48752 static adjustData(attrs) {
48753 return new AdjustData(attrs);
48754 }
48755 static adobeExtensionLevel(attrs) {
48756 return new AdobeExtensionLevel(attrs);
48757 }
48758 static agent(attrs) {
48759 return new Agent(attrs);
48760 }
48761 static alwaysEmbed(attrs) {
48762 return new AlwaysEmbed(attrs);
48763 }
48764 static amd(attrs) {
48765 return new Amd(attrs);
48766 }
48767 static area(attrs) {
48768 return new config_Area(attrs);
48769 }
48770 static attributes(attrs) {
48771 return new Attributes(attrs);
48772 }
48773 static autoSave(attrs) {
48774 return new AutoSave(attrs);
48775 }
48776 static base(attrs) {
48777 return new Base(attrs);
48778 }
48779 static batchOutput(attrs) {
48780 return new BatchOutput(attrs);
48781 }
48782 static behaviorOverride(attrs) {
48783 return new BehaviorOverride(attrs);
48784 }
48785 static cache(attrs) {
48786 return new Cache(attrs);
48787 }
48788 static change(attrs) {
48789 return new Change(attrs);
48790 }
48791 static common(attrs) {
48792 return new Common(attrs);
48793 }
48794 static compress(attrs) {
48795 return new Compress(attrs);
48796 }
48797 static compressLogicalStructure(attrs) {
48798 return new CompressLogicalStructure(attrs);
48799 }
48800 static compressObjectStream(attrs) {
48801 return new CompressObjectStream(attrs);
48802 }
48803 static compression(attrs) {
48804 return new Compression(attrs);
48805 }
48806 static config(attrs) {
48807 return new Config(attrs);
48808 }
48809 static conformance(attrs) {
48810 return new Conformance(attrs);
48811 }
48812 static contentCopy(attrs) {
48813 return new ContentCopy(attrs);
48814 }
48815 static copies(attrs) {
48816 return new Copies(attrs);
48817 }
48818 static creator(attrs) {
48819 return new Creator(attrs);
48820 }
48821 static currentPage(attrs) {
48822 return new CurrentPage(attrs);
48823 }
48824 static data(attrs) {
48825 return new Data(attrs);
48826 }
48827 static debug(attrs) {
48828 return new Debug(attrs);
48829 }
48830 static defaultTypeface(attrs) {
48831 return new DefaultTypeface(attrs);
48832 }
48833 static destination(attrs) {
48834 return new Destination(attrs);
48835 }
48836 static documentAssembly(attrs) {
48837 return new DocumentAssembly(attrs);
48838 }
48839 static driver(attrs) {
48840 return new Driver(attrs);
48841 }
48842 static duplexOption(attrs) {
48843 return new DuplexOption(attrs);
48844 }
48845 static dynamicRender(attrs) {
48846 return new DynamicRender(attrs);
48847 }
48848 static embed(attrs) {
48849 return new Embed(attrs);
48850 }
48851 static encrypt(attrs) {
48852 return new config_Encrypt(attrs);
48853 }
48854 static encryption(attrs) {
48855 return new config_Encryption(attrs);
48856 }
48857 static encryptionLevel(attrs) {
48858 return new EncryptionLevel(attrs);
48859 }
48860 static enforce(attrs) {
48861 return new Enforce(attrs);
48862 }
48863 static equate(attrs) {
48864 return new Equate(attrs);
48865 }
48866 static equateRange(attrs) {
48867 return new EquateRange(attrs);
48868 }
48869 static exclude(attrs) {
48870 return new Exclude(attrs);
48871 }
48872 static excludeNS(attrs) {
48873 return new ExcludeNS(attrs);
48874 }
48875 static flipLabel(attrs) {
48876 return new FlipLabel(attrs);
48877 }
48878 static fontInfo(attrs) {
48879 return new config_FontInfo(attrs);
48880 }
48881 static formFieldFilling(attrs) {
48882 return new FormFieldFilling(attrs);
48883 }
48884 static groupParent(attrs) {
48885 return new GroupParent(attrs);
48886 }
48887 static ifEmpty(attrs) {
48888 return new IfEmpty(attrs);
48889 }
48890 static includeXDPContent(attrs) {
48891 return new IncludeXDPContent(attrs);
48892 }
48893 static incrementalLoad(attrs) {
48894 return new IncrementalLoad(attrs);
48895 }
48896 static incrementalMerge(attrs) {
48897 return new IncrementalMerge(attrs);
48898 }
48899 static interactive(attrs) {
48900 return new Interactive(attrs);
48901 }
48902 static jog(attrs) {
48903 return new Jog(attrs);
48904 }
48905 static labelPrinter(attrs) {
48906 return new LabelPrinter(attrs);
48907 }
48908 static layout(attrs) {
48909 return new Layout(attrs);
48910 }
48911 static level(attrs) {
48912 return new Level(attrs);
48913 }
48914 static linearized(attrs) {
48915 return new Linearized(attrs);
48916 }
48917 static locale(attrs) {
48918 return new Locale(attrs);
48919 }
48920 static localeSet(attrs) {
48921 return new LocaleSet(attrs);
48922 }
48923 static log(attrs) {
48924 return new Log(attrs);
48925 }
48926 static map(attrs) {
48927 return new MapElement(attrs);
48928 }
48929 static mediumInfo(attrs) {
48930 return new MediumInfo(attrs);
48931 }
48932 static message(attrs) {
48933 return new config_Message(attrs);
48934 }
48935 static messaging(attrs) {
48936 return new Messaging(attrs);
48937 }
48938 static mode(attrs) {
48939 return new Mode(attrs);
48940 }
48941 static modifyAnnots(attrs) {
48942 return new ModifyAnnots(attrs);
48943 }
48944 static msgId(attrs) {
48945 return new MsgId(attrs);
48946 }
48947 static nameAttr(attrs) {
48948 return new NameAttr(attrs);
48949 }
48950 static neverEmbed(attrs) {
48951 return new NeverEmbed(attrs);
48952 }
48953 static numberOfCopies(attrs) {
48954 return new NumberOfCopies(attrs);
48955 }
48956 static openAction(attrs) {
48957 return new OpenAction(attrs);
48958 }
48959 static output(attrs) {
48960 return new Output(attrs);
48961 }
48962 static outputBin(attrs) {
48963 return new OutputBin(attrs);
48964 }
48965 static outputXSL(attrs) {
48966 return new OutputXSL(attrs);
48967 }
48968 static overprint(attrs) {
48969 return new Overprint(attrs);
48970 }
48971 static packets(attrs) {
48972 return new Packets(attrs);
48973 }
48974 static pageOffset(attrs) {
48975 return new PageOffset(attrs);
48976 }
48977 static pageRange(attrs) {
48978 return new PageRange(attrs);
48979 }
48980 static pagination(attrs) {
48981 return new Pagination(attrs);
48982 }
48983 static paginationOverride(attrs) {
48984 return new PaginationOverride(attrs);
48985 }
48986 static part(attrs) {
48987 return new Part(attrs);
48988 }
48989 static pcl(attrs) {
48990 return new Pcl(attrs);
48991 }
48992 static pdf(attrs) {
48993 return new Pdf(attrs);
48994 }
48995 static pdfa(attrs) {
48996 return new Pdfa(attrs);
48997 }
48998 static permissions(attrs) {
48999 return new Permissions(attrs);
49000 }
49001 static pickTrayByPDFSize(attrs) {
49002 return new PickTrayByPDFSize(attrs);
49003 }
49004 static picture(attrs) {
49005 return new config_Picture(attrs);
49006 }
49007 static plaintextMetadata(attrs) {
49008 return new PlaintextMetadata(attrs);
49009 }
49010 static presence(attrs) {
49011 return new Presence(attrs);
49012 }
49013 static present(attrs) {
49014 return new Present(attrs);
49015 }
49016 static print(attrs) {
49017 return new Print(attrs);
49018 }
49019 static printHighQuality(attrs) {
49020 return new PrintHighQuality(attrs);
49021 }
49022 static printScaling(attrs) {
49023 return new PrintScaling(attrs);
49024 }
49025 static printerName(attrs) {
49026 return new PrinterName(attrs);
49027 }
49028 static producer(attrs) {
49029 return new Producer(attrs);
49030 }
49031 static ps(attrs) {
49032 return new Ps(attrs);
49033 }
49034 static range(attrs) {
49035 return new Range(attrs);
49036 }
49037 static record(attrs) {
49038 return new Record(attrs);
49039 }
49040 static relevant(attrs) {
49041 return new Relevant(attrs);
49042 }
49043 static rename(attrs) {
49044 return new Rename(attrs);
49045 }
49046 static renderPolicy(attrs) {
49047 return new RenderPolicy(attrs);
49048 }
49049 static runScripts(attrs) {
49050 return new RunScripts(attrs);
49051 }
49052 static script(attrs) {
49053 return new config_Script(attrs);
49054 }
49055 static scriptModel(attrs) {
49056 return new ScriptModel(attrs);
49057 }
49058 static severity(attrs) {
49059 return new Severity(attrs);
49060 }
49061 static silentPrint(attrs) {
49062 return new SilentPrint(attrs);
49063 }
49064 static staple(attrs) {
49065 return new Staple(attrs);
49066 }
49067 static startNode(attrs) {
49068 return new StartNode(attrs);
49069 }
49070 static startPage(attrs) {
49071 return new StartPage(attrs);
49072 }
49073 static submitFormat(attrs) {
49074 return new SubmitFormat(attrs);
49075 }
49076 static submitUrl(attrs) {
49077 return new SubmitUrl(attrs);
49078 }
49079 static subsetBelow(attrs) {
49080 return new SubsetBelow(attrs);
49081 }
49082 static suppressBanner(attrs) {
49083 return new SuppressBanner(attrs);
49084 }
49085 static tagged(attrs) {
49086 return new Tagged(attrs);
49087 }
49088 static template(attrs) {
49089 return new config_Template(attrs);
49090 }
49091 static templateCache(attrs) {
49092 return new TemplateCache(attrs);
49093 }
49094 static threshold(attrs) {
49095 return new Threshold(attrs);
49096 }
49097 static to(attrs) {
49098 return new To(attrs);
49099 }
49100 static trace(attrs) {
49101 return new Trace(attrs);
49102 }
49103 static transform(attrs) {
49104 return new config_Transform(attrs);
49105 }
49106 static type(attrs) {
49107 return new Type(attrs);
49108 }
49109 static uri(attrs) {
49110 return new Uri(attrs);
49111 }
49112 static validate(attrs) {
49113 return new config_Validate(attrs);
49114 }
49115 static validateApprovalSignatures(attrs) {
49116 return new ValidateApprovalSignatures(attrs);
49117 }
49118 static validationMessaging(attrs) {
49119 return new ValidationMessaging(attrs);
49120 }
49121 static version(attrs) {
49122 return new Version(attrs);
49123 }
49124 static versionControl(attrs) {
49125 return new VersionControl(attrs);
49126 }
49127 static viewerPreferences(attrs) {
49128 return new ViewerPreferences(attrs);
49129 }
49130 static webClient(attrs) {
49131 return new WebClient(attrs);
49132 }
49133 static whitespace(attrs) {
49134 return new Whitespace(attrs);
49135 }
49136 static window(attrs) {
49137 return new Window(attrs);
49138 }
49139 static xdc(attrs) {
49140 return new Xdc(attrs);
49141 }
49142 static xdp(attrs) {
49143 return new Xdp(attrs);
49144 }
49145 static xsl(attrs) {
49146 return new Xsl(attrs);
49147 }
49148 static zpl(attrs) {
49149 return new Zpl(attrs);
49150 }
49151}
49152
49153;// CONCATENATED MODULE: ./src/core/xfa/connection_set.js
49154
49155
49156const CONNECTION_SET_NS_ID = NamespaceIds.connectionSet.id;
49157class ConnectionSet extends XFAObject {
49158 constructor(attributes) {
49159 super(CONNECTION_SET_NS_ID, "connectionSet", true);
49160 this.wsdlConnection = new XFAObjectArray();
49161 this.xmlConnection = new XFAObjectArray();
49162 this.xsdConnection = new XFAObjectArray();
49163 }
49164}
49165class EffectiveInputPolicy extends XFAObject {
49166 constructor(attributes) {
49167 super(CONNECTION_SET_NS_ID, "effectiveInputPolicy");
49168 this.id = attributes.id || "";
49169 this.name = attributes.name || "";
49170 this.use = attributes.use || "";
49171 this.usehref = attributes.usehref || "";
49172 }
49173}
49174class EffectiveOutputPolicy extends XFAObject {
49175 constructor(attributes) {
49176 super(CONNECTION_SET_NS_ID, "effectiveOutputPolicy");
49177 this.id = attributes.id || "";
49178 this.name = attributes.name || "";
49179 this.use = attributes.use || "";
49180 this.usehref = attributes.usehref || "";
49181 }
49182}
49183class Operation extends StringObject {
49184 constructor(attributes) {
49185 super(CONNECTION_SET_NS_ID, "operation");
49186 this.id = attributes.id || "";
49187 this.input = attributes.input || "";
49188 this.name = attributes.name || "";
49189 this.output = attributes.output || "";
49190 this.use = attributes.use || "";
49191 this.usehref = attributes.usehref || "";
49192 }
49193}
49194class RootElement extends StringObject {
49195 constructor(attributes) {
49196 super(CONNECTION_SET_NS_ID, "rootElement");
49197 this.id = attributes.id || "";
49198 this.name = attributes.name || "";
49199 this.use = attributes.use || "";
49200 this.usehref = attributes.usehref || "";
49201 }
49202}
49203class SoapAction extends StringObject {
49204 constructor(attributes) {
49205 super(CONNECTION_SET_NS_ID, "soapAction");
49206 this.id = attributes.id || "";
49207 this.name = attributes.name || "";
49208 this.use = attributes.use || "";
49209 this.usehref = attributes.usehref || "";
49210 }
49211}
49212class SoapAddress extends StringObject {
49213 constructor(attributes) {
49214 super(CONNECTION_SET_NS_ID, "soapAddress");
49215 this.id = attributes.id || "";
49216 this.name = attributes.name || "";
49217 this.use = attributes.use || "";
49218 this.usehref = attributes.usehref || "";
49219 }
49220}
49221class connection_set_Uri extends StringObject {
49222 constructor(attributes) {
49223 super(CONNECTION_SET_NS_ID, "uri");
49224 this.id = attributes.id || "";
49225 this.name = attributes.name || "";
49226 this.use = attributes.use || "";
49227 this.usehref = attributes.usehref || "";
49228 }
49229}
49230class WsdlAddress extends StringObject {
49231 constructor(attributes) {
49232 super(CONNECTION_SET_NS_ID, "wsdlAddress");
49233 this.id = attributes.id || "";
49234 this.name = attributes.name || "";
49235 this.use = attributes.use || "";
49236 this.usehref = attributes.usehref || "";
49237 }
49238}
49239class WsdlConnection extends XFAObject {
49240 constructor(attributes) {
49241 super(CONNECTION_SET_NS_ID, "wsdlConnection", true);
49242 this.dataDescription = attributes.dataDescription || "";
49243 this.name = attributes.name || "";
49244 this.effectiveInputPolicy = null;
49245 this.effectiveOutputPolicy = null;
49246 this.operation = null;
49247 this.soapAction = null;
49248 this.soapAddress = null;
49249 this.wsdlAddress = null;
49250 }
49251}
49252class XmlConnection extends XFAObject {
49253 constructor(attributes) {
49254 super(CONNECTION_SET_NS_ID, "xmlConnection", true);
49255 this.dataDescription = attributes.dataDescription || "";
49256 this.name = attributes.name || "";
49257 this.uri = null;
49258 }
49259}
49260class XsdConnection extends XFAObject {
49261 constructor(attributes) {
49262 super(CONNECTION_SET_NS_ID, "xsdConnection", true);
49263 this.dataDescription = attributes.dataDescription || "";
49264 this.name = attributes.name || "";
49265 this.rootElement = null;
49266 this.uri = null;
49267 }
49268}
49269class ConnectionSetNamespace {
49270 static [$buildXFAObject](name, attributes) {
49271 if (ConnectionSetNamespace.hasOwnProperty(name)) {
49272 return ConnectionSetNamespace[name](attributes);
49273 }
49274 return undefined;
49275 }
49276 static connectionSet(attrs) {
49277 return new ConnectionSet(attrs);
49278 }
49279 static effectiveInputPolicy(attrs) {
49280 return new EffectiveInputPolicy(attrs);
49281 }
49282 static effectiveOutputPolicy(attrs) {
49283 return new EffectiveOutputPolicy(attrs);
49284 }
49285 static operation(attrs) {
49286 return new Operation(attrs);
49287 }
49288 static rootElement(attrs) {
49289 return new RootElement(attrs);
49290 }
49291 static soapAction(attrs) {
49292 return new SoapAction(attrs);
49293 }
49294 static soapAddress(attrs) {
49295 return new SoapAddress(attrs);
49296 }
49297 static uri(attrs) {
49298 return new connection_set_Uri(attrs);
49299 }
49300 static wsdlAddress(attrs) {
49301 return new WsdlAddress(attrs);
49302 }
49303 static wsdlConnection(attrs) {
49304 return new WsdlConnection(attrs);
49305 }
49306 static xmlConnection(attrs) {
49307 return new XmlConnection(attrs);
49308 }
49309 static xsdConnection(attrs) {
49310 return new XsdConnection(attrs);
49311 }
49312}
49313
49314;// CONCATENATED MODULE: ./src/core/xfa/datasets.js
49315
49316
49317
49318const DATASETS_NS_ID = NamespaceIds.datasets.id;
49319class datasets_Data extends XmlObject {
49320 constructor(attributes) {
49321 super(DATASETS_NS_ID, "data", attributes);
49322 }
49323 [$isNsAgnostic]() {
49324 return true;
49325 }
49326}
49327class Datasets extends XFAObject {
49328 constructor(attributes) {
49329 super(DATASETS_NS_ID, "datasets", true);
49330 this.data = null;
49331 this.Signature = null;
49332 }
49333 [$onChild](child) {
49334 const name = child[$nodeName];
49335 if (name === "data" && child[$namespaceId] === DATASETS_NS_ID || name === "Signature" && child[$namespaceId] === NamespaceIds.signature.id) {
49336 this[name] = child;
49337 }
49338 this[$appendChild](child);
49339 }
49340}
49341class DatasetsNamespace {
49342 static [$buildXFAObject](name, attributes) {
49343 if (DatasetsNamespace.hasOwnProperty(name)) {
49344 return DatasetsNamespace[name](attributes);
49345 }
49346 return undefined;
49347 }
49348 static datasets(attributes) {
49349 return new Datasets(attributes);
49350 }
49351 static data(attributes) {
49352 return new datasets_Data(attributes);
49353 }
49354}
49355
49356;// CONCATENATED MODULE: ./src/core/xfa/locale_set.js
49357
49358
49359
49360const LOCALE_SET_NS_ID = NamespaceIds.localeSet.id;
49361class CalendarSymbols extends XFAObject {
49362 constructor(attributes) {
49363 super(LOCALE_SET_NS_ID, "calendarSymbols", true);
49364 this.name = "gregorian";
49365 this.dayNames = new XFAObjectArray(2);
49366 this.eraNames = null;
49367 this.meridiemNames = null;
49368 this.monthNames = new XFAObjectArray(2);
49369 }
49370}
49371class CurrencySymbol extends StringObject {
49372 constructor(attributes) {
49373 super(LOCALE_SET_NS_ID, "currencySymbol");
49374 this.name = getStringOption(attributes.name, ["symbol", "isoname", "decimal"]);
49375 }
49376}
49377class CurrencySymbols extends XFAObject {
49378 constructor(attributes) {
49379 super(LOCALE_SET_NS_ID, "currencySymbols", true);
49380 this.currencySymbol = new XFAObjectArray(3);
49381 }
49382}
49383class DatePattern extends StringObject {
49384 constructor(attributes) {
49385 super(LOCALE_SET_NS_ID, "datePattern");
49386 this.name = getStringOption(attributes.name, ["full", "long", "med", "short"]);
49387 }
49388}
49389class DatePatterns extends XFAObject {
49390 constructor(attributes) {
49391 super(LOCALE_SET_NS_ID, "datePatterns", true);
49392 this.datePattern = new XFAObjectArray(4);
49393 }
49394}
49395class DateTimeSymbols extends ContentObject {
49396 constructor(attributes) {
49397 super(LOCALE_SET_NS_ID, "dateTimeSymbols");
49398 }
49399}
49400class Day extends StringObject {
49401 constructor(attributes) {
49402 super(LOCALE_SET_NS_ID, "day");
49403 }
49404}
49405class DayNames extends XFAObject {
49406 constructor(attributes) {
49407 super(LOCALE_SET_NS_ID, "dayNames", true);
49408 this.abbr = getInteger({
49409 data: attributes.abbr,
49410 defaultValue: 0,
49411 validate: x => x === 1
49412 });
49413 this.day = new XFAObjectArray(7);
49414 }
49415}
49416class Era extends StringObject {
49417 constructor(attributes) {
49418 super(LOCALE_SET_NS_ID, "era");
49419 }
49420}
49421class EraNames extends XFAObject {
49422 constructor(attributes) {
49423 super(LOCALE_SET_NS_ID, "eraNames", true);
49424 this.era = new XFAObjectArray(2);
49425 }
49426}
49427class locale_set_Locale extends XFAObject {
49428 constructor(attributes) {
49429 super(LOCALE_SET_NS_ID, "locale", true);
49430 this.desc = attributes.desc || "";
49431 this.name = "isoname";
49432 this.calendarSymbols = null;
49433 this.currencySymbols = null;
49434 this.datePatterns = null;
49435 this.dateTimeSymbols = null;
49436 this.numberPatterns = null;
49437 this.numberSymbols = null;
49438 this.timePatterns = null;
49439 this.typeFaces = null;
49440 }
49441}
49442class locale_set_LocaleSet extends XFAObject {
49443 constructor(attributes) {
49444 super(LOCALE_SET_NS_ID, "localeSet", true);
49445 this.locale = new XFAObjectArray();
49446 }
49447}
49448class Meridiem extends StringObject {
49449 constructor(attributes) {
49450 super(LOCALE_SET_NS_ID, "meridiem");
49451 }
49452}
49453class MeridiemNames extends XFAObject {
49454 constructor(attributes) {
49455 super(LOCALE_SET_NS_ID, "meridiemNames", true);
49456 this.meridiem = new XFAObjectArray(2);
49457 }
49458}
49459class Month extends StringObject {
49460 constructor(attributes) {
49461 super(LOCALE_SET_NS_ID, "month");
49462 }
49463}
49464class MonthNames extends XFAObject {
49465 constructor(attributes) {
49466 super(LOCALE_SET_NS_ID, "monthNames", true);
49467 this.abbr = getInteger({
49468 data: attributes.abbr,
49469 defaultValue: 0,
49470 validate: x => x === 1
49471 });
49472 this.month = new XFAObjectArray(12);
49473 }
49474}
49475class NumberPattern extends StringObject {
49476 constructor(attributes) {
49477 super(LOCALE_SET_NS_ID, "numberPattern");
49478 this.name = getStringOption(attributes.name, ["full", "long", "med", "short"]);
49479 }
49480}
49481class NumberPatterns extends XFAObject {
49482 constructor(attributes) {
49483 super(LOCALE_SET_NS_ID, "numberPatterns", true);
49484 this.numberPattern = new XFAObjectArray(4);
49485 }
49486}
49487class NumberSymbol extends StringObject {
49488 constructor(attributes) {
49489 super(LOCALE_SET_NS_ID, "numberSymbol");
49490 this.name = getStringOption(attributes.name, ["decimal", "grouping", "percent", "minus", "zero"]);
49491 }
49492}
49493class NumberSymbols extends XFAObject {
49494 constructor(attributes) {
49495 super(LOCALE_SET_NS_ID, "numberSymbols", true);
49496 this.numberSymbol = new XFAObjectArray(5);
49497 }
49498}
49499class TimePattern extends StringObject {
49500 constructor(attributes) {
49501 super(LOCALE_SET_NS_ID, "timePattern");
49502 this.name = getStringOption(attributes.name, ["full", "long", "med", "short"]);
49503 }
49504}
49505class TimePatterns extends XFAObject {
49506 constructor(attributes) {
49507 super(LOCALE_SET_NS_ID, "timePatterns", true);
49508 this.timePattern = new XFAObjectArray(4);
49509 }
49510}
49511class TypeFace extends XFAObject {
49512 constructor(attributes) {
49513 super(LOCALE_SET_NS_ID, "typeFace", true);
49514 this.name = attributes.name | "";
49515 }
49516}
49517class TypeFaces extends XFAObject {
49518 constructor(attributes) {
49519 super(LOCALE_SET_NS_ID, "typeFaces", true);
49520 this.typeFace = new XFAObjectArray();
49521 }
49522}
49523class LocaleSetNamespace {
49524 static [$buildXFAObject](name, attributes) {
49525 if (LocaleSetNamespace.hasOwnProperty(name)) {
49526 return LocaleSetNamespace[name](attributes);
49527 }
49528 return undefined;
49529 }
49530 static calendarSymbols(attrs) {
49531 return new CalendarSymbols(attrs);
49532 }
49533 static currencySymbol(attrs) {
49534 return new CurrencySymbol(attrs);
49535 }
49536 static currencySymbols(attrs) {
49537 return new CurrencySymbols(attrs);
49538 }
49539 static datePattern(attrs) {
49540 return new DatePattern(attrs);
49541 }
49542 static datePatterns(attrs) {
49543 return new DatePatterns(attrs);
49544 }
49545 static dateTimeSymbols(attrs) {
49546 return new DateTimeSymbols(attrs);
49547 }
49548 static day(attrs) {
49549 return new Day(attrs);
49550 }
49551 static dayNames(attrs) {
49552 return new DayNames(attrs);
49553 }
49554 static era(attrs) {
49555 return new Era(attrs);
49556 }
49557 static eraNames(attrs) {
49558 return new EraNames(attrs);
49559 }
49560 static locale(attrs) {
49561 return new locale_set_Locale(attrs);
49562 }
49563 static localeSet(attrs) {
49564 return new locale_set_LocaleSet(attrs);
49565 }
49566 static meridiem(attrs) {
49567 return new Meridiem(attrs);
49568 }
49569 static meridiemNames(attrs) {
49570 return new MeridiemNames(attrs);
49571 }
49572 static month(attrs) {
49573 return new Month(attrs);
49574 }
49575 static monthNames(attrs) {
49576 return new MonthNames(attrs);
49577 }
49578 static numberPattern(attrs) {
49579 return new NumberPattern(attrs);
49580 }
49581 static numberPatterns(attrs) {
49582 return new NumberPatterns(attrs);
49583 }
49584 static numberSymbol(attrs) {
49585 return new NumberSymbol(attrs);
49586 }
49587 static numberSymbols(attrs) {
49588 return new NumberSymbols(attrs);
49589 }
49590 static timePattern(attrs) {
49591 return new TimePattern(attrs);
49592 }
49593 static timePatterns(attrs) {
49594 return new TimePatterns(attrs);
49595 }
49596 static typeFace(attrs) {
49597 return new TypeFace(attrs);
49598 }
49599 static typeFaces(attrs) {
49600 return new TypeFaces(attrs);
49601 }
49602}
49603
49604;// CONCATENATED MODULE: ./src/core/xfa/signature.js
49605
49606
49607const SIGNATURE_NS_ID = NamespaceIds.signature.id;
49608class signature_Signature extends XFAObject {
49609 constructor(attributes) {
49610 super(SIGNATURE_NS_ID, "signature", true);
49611 }
49612}
49613class SignatureNamespace {
49614 static [$buildXFAObject](name, attributes) {
49615 if (SignatureNamespace.hasOwnProperty(name)) {
49616 return SignatureNamespace[name](attributes);
49617 }
49618 return undefined;
49619 }
49620 static signature(attributes) {
49621 return new signature_Signature(attributes);
49622 }
49623}
49624
49625;// CONCATENATED MODULE: ./src/core/xfa/stylesheet.js
49626
49627
49628const STYLESHEET_NS_ID = NamespaceIds.stylesheet.id;
49629class Stylesheet extends XFAObject {
49630 constructor(attributes) {
49631 super(STYLESHEET_NS_ID, "stylesheet", true);
49632 }
49633}
49634class StylesheetNamespace {
49635 static [$buildXFAObject](name, attributes) {
49636 if (StylesheetNamespace.hasOwnProperty(name)) {
49637 return StylesheetNamespace[name](attributes);
49638 }
49639 return undefined;
49640 }
49641 static stylesheet(attributes) {
49642 return new Stylesheet(attributes);
49643 }
49644}
49645
49646;// CONCATENATED MODULE: ./src/core/xfa/xdp.js
49647
49648
49649
49650const XDP_NS_ID = NamespaceIds.xdp.id;
49651class xdp_Xdp extends XFAObject {
49652 constructor(attributes) {
49653 super(XDP_NS_ID, "xdp", true);
49654 this.uuid = attributes.uuid || "";
49655 this.timeStamp = attributes.timeStamp || "";
49656 this.config = null;
49657 this.connectionSet = null;
49658 this.datasets = null;
49659 this.localeSet = null;
49660 this.stylesheet = new XFAObjectArray();
49661 this.template = null;
49662 }
49663 [$onChildCheck](child) {
49664 const ns = NamespaceIds[child[$nodeName]];
49665 return ns && child[$namespaceId] === ns.id;
49666 }
49667}
49668class XdpNamespace {
49669 static [$buildXFAObject](name, attributes) {
49670 if (XdpNamespace.hasOwnProperty(name)) {
49671 return XdpNamespace[name](attributes);
49672 }
49673 return undefined;
49674 }
49675 static xdp(attributes) {
49676 return new xdp_Xdp(attributes);
49677 }
49678}
49679
49680;// CONCATENATED MODULE: ./src/core/xfa/xhtml.js
49681
49682
49683
49684
49685
49686const XHTML_NS_ID = NamespaceIds.xhtml.id;
49687const $richText = Symbol();
49688const 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"]);
49689const 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, Math.min(parseInt(value) / 100)).toFixed(2)})`], ["xfa-font-vertical-scale", value => `scaleY(${Math.max(0, Math.min(parseInt(value) / 100)).toFixed(2)})`], ["xfa-spacerun", ""], ["xfa-tab-stops", ""], ["font-size", (value, original) => {
49690 value = original.fontSize = getMeasurement(value);
49691 return measureToString(0.99 * value);
49692}], ["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))]]);
49693const spacesRegExp = /\s+/g;
49694const crlfRegExp = /[\r\n]+/g;
49695const crlfForRichTextRegExp = /\r\n?/g;
49696function mapStyle(styleStr, node, richText) {
49697 const style = Object.create(null);
49698 if (!styleStr) {
49699 return style;
49700 }
49701 const original = Object.create(null);
49702 for (const [key, value] of styleStr.split(";").map(s => s.split(":", 2))) {
49703 const mapping = StyleMapping.get(key);
49704 if (mapping === "") {
49705 continue;
49706 }
49707 let newValue = value;
49708 if (mapping) {
49709 newValue = typeof mapping === "string" ? mapping : mapping(value, original);
49710 }
49711 if (key.endsWith("scale")) {
49712 style.transform = style.transform ? `${style[key]} ${newValue}` : newValue;
49713 } else {
49714 style[key.replaceAll(/-([a-zA-Z])/g, (_, x) => x.toUpperCase())] = newValue;
49715 }
49716 }
49717 if (style.fontFamily) {
49718 setFontFamily({
49719 typeface: style.fontFamily,
49720 weight: style.fontWeight || "normal",
49721 posture: style.fontStyle || "normal",
49722 size: original.fontSize || 0
49723 }, node, node[$globalData].fontFinder, style);
49724 }
49725 if (richText && style.verticalAlign && style.verticalAlign !== "0px" && style.fontSize) {
49726 const SUB_SUPER_SCRIPT_FACTOR = 0.583;
49727 const VERTICAL_FACTOR = 0.333;
49728 const fontSize = getMeasurement(style.fontSize);
49729 style.fontSize = measureToString(fontSize * SUB_SUPER_SCRIPT_FACTOR);
49730 style.verticalAlign = measureToString(Math.sign(getMeasurement(style.verticalAlign)) * fontSize * VERTICAL_FACTOR);
49731 }
49732 if (richText && style.fontSize) {
49733 style.fontSize = `calc(${style.fontSize} * var(--scale-factor))`;
49734 }
49735 fixTextIndent(style);
49736 return style;
49737}
49738function checkStyle(node) {
49739 if (!node.style) {
49740 return "";
49741 }
49742 return node.style.trim().split(/\s*;\s*/).filter(s => !!s).map(s => s.split(/\s*:\s*/, 2)).filter(([key, value]) => {
49743 if (key === "font-family") {
49744 node[$globalData].usedTypefaces.add(value);
49745 }
49746 return VALID_STYLES.has(key);
49747 }).map(kv => kv.join(":")).join(";");
49748}
49749const NoWhites = new Set(["body", "html"]);
49750class XhtmlObject extends XmlObject {
49751 constructor(attributes, name) {
49752 super(XHTML_NS_ID, name);
49753 this[$richText] = false;
49754 this.style = attributes.style || "";
49755 }
49756 [$clean](builder) {
49757 super[$clean](builder);
49758 this.style = checkStyle(this);
49759 }
49760 [$acceptWhitespace]() {
49761 return !NoWhites.has(this[$nodeName]);
49762 }
49763 [$onText](str, richText = false) {
49764 if (!richText) {
49765 str = str.replaceAll(crlfRegExp, "");
49766 if (!this.style.includes("xfa-spacerun:yes")) {
49767 str = str.replaceAll(spacesRegExp, " ");
49768 }
49769 } else {
49770 this[$richText] = true;
49771 }
49772 if (str) {
49773 this[$content] += str;
49774 }
49775 }
49776 [$pushGlyphs](measure, mustPop = true) {
49777 const xfaFont = Object.create(null);
49778 const margin = {
49779 top: NaN,
49780 bottom: NaN,
49781 left: NaN,
49782 right: NaN
49783 };
49784 let lineHeight = null;
49785 for (const [key, value] of this.style.split(";").map(s => s.split(":", 2))) {
49786 switch (key) {
49787 case "font-family":
49788 xfaFont.typeface = stripQuotes(value);
49789 break;
49790 case "font-size":
49791 xfaFont.size = getMeasurement(value);
49792 break;
49793 case "font-weight":
49794 xfaFont.weight = value;
49795 break;
49796 case "font-style":
49797 xfaFont.posture = value;
49798 break;
49799 case "letter-spacing":
49800 xfaFont.letterSpacing = getMeasurement(value);
49801 break;
49802 case "margin":
49803 const values = value.split(/ \t/).map(x => getMeasurement(x));
49804 switch (values.length) {
49805 case 1:
49806 margin.top = margin.bottom = margin.left = margin.right = values[0];
49807 break;
49808 case 2:
49809 margin.top = margin.bottom = values[0];
49810 margin.left = margin.right = values[1];
49811 break;
49812 case 3:
49813 margin.top = values[0];
49814 margin.bottom = values[2];
49815 margin.left = margin.right = values[1];
49816 break;
49817 case 4:
49818 margin.top = values[0];
49819 margin.left = values[1];
49820 margin.bottom = values[2];
49821 margin.right = values[3];
49822 break;
49823 }
49824 break;
49825 case "margin-top":
49826 margin.top = getMeasurement(value);
49827 break;
49828 case "margin-bottom":
49829 margin.bottom = getMeasurement(value);
49830 break;
49831 case "margin-left":
49832 margin.left = getMeasurement(value);
49833 break;
49834 case "margin-right":
49835 margin.right = getMeasurement(value);
49836 break;
49837 case "line-height":
49838 lineHeight = getMeasurement(value);
49839 break;
49840 }
49841 }
49842 measure.pushData(xfaFont, margin, lineHeight);
49843 if (this[$content]) {
49844 measure.addString(this[$content]);
49845 } else {
49846 for (const child of this[$getChildren]()) {
49847 if (child[$nodeName] === "#text") {
49848 measure.addString(child[$content]);
49849 continue;
49850 }
49851 child[$pushGlyphs](measure);
49852 }
49853 }
49854 if (mustPop) {
49855 measure.popFont();
49856 }
49857 }
49858 [$toHTML](availableSpace) {
49859 const children = [];
49860 this[$extra] = {
49861 children
49862 };
49863 this[$childrenToHTML]({});
49864 if (children.length === 0 && !this[$content]) {
49865 return HTMLResult.EMPTY;
49866 }
49867 let value;
49868 if (this[$richText]) {
49869 value = this[$content] ? this[$content].replaceAll(crlfForRichTextRegExp, "\n") : undefined;
49870 } else {
49871 value = this[$content] || undefined;
49872 }
49873 return HTMLResult.success({
49874 name: this[$nodeName],
49875 attributes: {
49876 href: this.href,
49877 style: mapStyle(this.style, this, this[$richText])
49878 },
49879 children,
49880 value
49881 });
49882 }
49883}
49884class A extends XhtmlObject {
49885 constructor(attributes) {
49886 super(attributes, "a");
49887 this.href = fixURL(attributes.href) || "";
49888 }
49889}
49890class B extends XhtmlObject {
49891 constructor(attributes) {
49892 super(attributes, "b");
49893 }
49894 [$pushGlyphs](measure) {
49895 measure.pushFont({
49896 weight: "bold"
49897 });
49898 super[$pushGlyphs](measure);
49899 measure.popFont();
49900 }
49901}
49902class Body extends XhtmlObject {
49903 constructor(attributes) {
49904 super(attributes, "body");
49905 }
49906 [$toHTML](availableSpace) {
49907 const res = super[$toHTML](availableSpace);
49908 const {
49909 html
49910 } = res;
49911 if (!html) {
49912 return HTMLResult.EMPTY;
49913 }
49914 html.name = "div";
49915 html.attributes.class = ["xfaRich"];
49916 return res;
49917 }
49918}
49919class Br extends XhtmlObject {
49920 constructor(attributes) {
49921 super(attributes, "br");
49922 }
49923 [$text]() {
49924 return "\n";
49925 }
49926 [$pushGlyphs](measure) {
49927 measure.addString("\n");
49928 }
49929 [$toHTML](availableSpace) {
49930 return HTMLResult.success({
49931 name: "br"
49932 });
49933 }
49934}
49935class Html extends XhtmlObject {
49936 constructor(attributes) {
49937 super(attributes, "html");
49938 }
49939 [$toHTML](availableSpace) {
49940 const children = [];
49941 this[$extra] = {
49942 children
49943 };
49944 this[$childrenToHTML]({});
49945 if (children.length === 0) {
49946 return HTMLResult.success({
49947 name: "div",
49948 attributes: {
49949 class: ["xfaRich"],
49950 style: {}
49951 },
49952 value: this[$content] || ""
49953 });
49954 }
49955 if (children.length === 1) {
49956 const child = children[0];
49957 if (child.attributes?.class.includes("xfaRich")) {
49958 return HTMLResult.success(child);
49959 }
49960 }
49961 return HTMLResult.success({
49962 name: "div",
49963 attributes: {
49964 class: ["xfaRich"],
49965 style: {}
49966 },
49967 children
49968 });
49969 }
49970}
49971class I extends XhtmlObject {
49972 constructor(attributes) {
49973 super(attributes, "i");
49974 }
49975 [$pushGlyphs](measure) {
49976 measure.pushFont({
49977 posture: "italic"
49978 });
49979 super[$pushGlyphs](measure);
49980 measure.popFont();
49981 }
49982}
49983class Li extends XhtmlObject {
49984 constructor(attributes) {
49985 super(attributes, "li");
49986 }
49987}
49988class Ol extends XhtmlObject {
49989 constructor(attributes) {
49990 super(attributes, "ol");
49991 }
49992}
49993class P extends XhtmlObject {
49994 constructor(attributes) {
49995 super(attributes, "p");
49996 }
49997 [$pushGlyphs](measure) {
49998 super[$pushGlyphs](measure, false);
49999 measure.addString("\n");
50000 measure.addPara();
50001 measure.popFont();
50002 }
50003 [$text]() {
50004 const siblings = this[$getParent]()[$getChildren]();
50005 if (siblings.at(-1) === this) {
50006 return super[$text]();
50007 }
50008 return super[$text]() + "\n";
50009 }
50010}
50011class Span extends XhtmlObject {
50012 constructor(attributes) {
50013 super(attributes, "span");
50014 }
50015}
50016class Sub extends XhtmlObject {
50017 constructor(attributes) {
50018 super(attributes, "sub");
50019 }
50020}
50021class Sup extends XhtmlObject {
50022 constructor(attributes) {
50023 super(attributes, "sup");
50024 }
50025}
50026class Ul extends XhtmlObject {
50027 constructor(attributes) {
50028 super(attributes, "ul");
50029 }
50030}
50031class XhtmlNamespace {
50032 static [$buildXFAObject](name, attributes) {
50033 if (XhtmlNamespace.hasOwnProperty(name)) {
50034 return XhtmlNamespace[name](attributes);
50035 }
50036 return undefined;
50037 }
50038 static a(attributes) {
50039 return new A(attributes);
50040 }
50041 static b(attributes) {
50042 return new B(attributes);
50043 }
50044 static body(attributes) {
50045 return new Body(attributes);
50046 }
50047 static br(attributes) {
50048 return new Br(attributes);
50049 }
50050 static html(attributes) {
50051 return new Html(attributes);
50052 }
50053 static i(attributes) {
50054 return new I(attributes);
50055 }
50056 static li(attributes) {
50057 return new Li(attributes);
50058 }
50059 static ol(attributes) {
50060 return new Ol(attributes);
50061 }
50062 static p(attributes) {
50063 return new P(attributes);
50064 }
50065 static span(attributes) {
50066 return new Span(attributes);
50067 }
50068 static sub(attributes) {
50069 return new Sub(attributes);
50070 }
50071 static sup(attributes) {
50072 return new Sup(attributes);
50073 }
50074 static ul(attributes) {
50075 return new Ul(attributes);
50076 }
50077}
50078
50079;// CONCATENATED MODULE: ./src/core/xfa/setup.js
50080
50081
50082
50083
50084
50085
50086
50087
50088
50089const NamespaceSetUp = {
50090 config: ConfigNamespace,
50091 connection: ConnectionSetNamespace,
50092 datasets: DatasetsNamespace,
50093 localeSet: LocaleSetNamespace,
50094 signature: SignatureNamespace,
50095 stylesheet: StylesheetNamespace,
50096 template: TemplateNamespace,
50097 xdp: XdpNamespace,
50098 xhtml: XhtmlNamespace
50099};
50100
50101;// CONCATENATED MODULE: ./src/core/xfa/unknown.js
50102
50103
50104class UnknownNamespace {
50105 constructor(nsId) {
50106 this.namespaceId = nsId;
50107 }
50108 [$buildXFAObject](name, attributes) {
50109 return new XmlObject(this.namespaceId, name, attributes);
50110 }
50111}
50112
50113;// CONCATENATED MODULE: ./src/core/xfa/builder.js
50114
50115
50116
50117
50118
50119
50120
50121class Root extends XFAObject {
50122 constructor(ids) {
50123 super(-1, "root", Object.create(null));
50124 this.element = null;
50125 this[$ids] = ids;
50126 }
50127 [$onChild](child) {
50128 this.element = child;
50129 return true;
50130 }
50131 [$finalize]() {
50132 super[$finalize]();
50133 if (this.element.template instanceof Template) {
50134 this[$ids].set($root, this.element);
50135 this.element.template[$resolvePrototypes](this[$ids]);
50136 this.element.template[$ids] = this[$ids];
50137 }
50138 }
50139}
50140class Empty extends XFAObject {
50141 constructor() {
50142 super(-1, "", Object.create(null));
50143 }
50144 [$onChild](_) {
50145 return false;
50146 }
50147}
50148class Builder {
50149 constructor(rootNameSpace = null) {
50150 this._namespaceStack = [];
50151 this._nsAgnosticLevel = 0;
50152 this._namespacePrefixes = new Map();
50153 this._namespaces = new Map();
50154 this._nextNsId = Math.max(...Object.values(NamespaceIds).map(({
50155 id
50156 }) => id));
50157 this._currentNamespace = rootNameSpace || new UnknownNamespace(++this._nextNsId);
50158 }
50159 buildRoot(ids) {
50160 return new Root(ids);
50161 }
50162 build({
50163 nsPrefix,
50164 name,
50165 attributes,
50166 namespace,
50167 prefixes
50168 }) {
50169 const hasNamespaceDef = namespace !== null;
50170 if (hasNamespaceDef) {
50171 this._namespaceStack.push(this._currentNamespace);
50172 this._currentNamespace = this._searchNamespace(namespace);
50173 }
50174 if (prefixes) {
50175 this._addNamespacePrefix(prefixes);
50176 }
50177 if (attributes.hasOwnProperty($nsAttributes)) {
50178 const dataTemplate = NamespaceSetUp.datasets;
50179 const nsAttrs = attributes[$nsAttributes];
50180 let xfaAttrs = null;
50181 for (const [ns, attrs] of Object.entries(nsAttrs)) {
50182 const nsToUse = this._getNamespaceToUse(ns);
50183 if (nsToUse === dataTemplate) {
50184 xfaAttrs = {
50185 xfa: attrs
50186 };
50187 break;
50188 }
50189 }
50190 if (xfaAttrs) {
50191 attributes[$nsAttributes] = xfaAttrs;
50192 } else {
50193 delete attributes[$nsAttributes];
50194 }
50195 }
50196 const namespaceToUse = this._getNamespaceToUse(nsPrefix);
50197 const node = namespaceToUse?.[$buildXFAObject](name, attributes) || new Empty();
50198 if (node[$isNsAgnostic]()) {
50199 this._nsAgnosticLevel++;
50200 }
50201 if (hasNamespaceDef || prefixes || node[$isNsAgnostic]()) {
50202 node[$cleanup] = {
50203 hasNamespace: hasNamespaceDef,
50204 prefixes,
50205 nsAgnostic: node[$isNsAgnostic]()
50206 };
50207 }
50208 return node;
50209 }
50210 isNsAgnostic() {
50211 return this._nsAgnosticLevel > 0;
50212 }
50213 _searchNamespace(nsName) {
50214 let ns = this._namespaces.get(nsName);
50215 if (ns) {
50216 return ns;
50217 }
50218 for (const [name, {
50219 check
50220 }] of Object.entries(NamespaceIds)) {
50221 if (check(nsName)) {
50222 ns = NamespaceSetUp[name];
50223 if (ns) {
50224 this._namespaces.set(nsName, ns);
50225 return ns;
50226 }
50227 break;
50228 }
50229 }
50230 ns = new UnknownNamespace(++this._nextNsId);
50231 this._namespaces.set(nsName, ns);
50232 return ns;
50233 }
50234 _addNamespacePrefix(prefixes) {
50235 for (const {
50236 prefix,
50237 value
50238 } of prefixes) {
50239 const namespace = this._searchNamespace(value);
50240 let prefixStack = this._namespacePrefixes.get(prefix);
50241 if (!prefixStack) {
50242 prefixStack = [];
50243 this._namespacePrefixes.set(prefix, prefixStack);
50244 }
50245 prefixStack.push(namespace);
50246 }
50247 }
50248 _getNamespaceToUse(prefix) {
50249 if (!prefix) {
50250 return this._currentNamespace;
50251 }
50252 const prefixStack = this._namespacePrefixes.get(prefix);
50253 if (prefixStack?.length > 0) {
50254 return prefixStack.at(-1);
50255 }
50256 warn(`Unknown namespace prefix: ${prefix}.`);
50257 return null;
50258 }
50259 clean(data) {
50260 const {
50261 hasNamespace,
50262 prefixes,
50263 nsAgnostic
50264 } = data;
50265 if (hasNamespace) {
50266 this._currentNamespace = this._namespaceStack.pop();
50267 }
50268 if (prefixes) {
50269 prefixes.forEach(({
50270 prefix
50271 }) => {
50272 this._namespacePrefixes.get(prefix).pop();
50273 });
50274 }
50275 if (nsAgnostic) {
50276 this._nsAgnosticLevel--;
50277 }
50278 }
50279}
50280
50281;// CONCATENATED MODULE: ./src/core/xfa/parser.js
50282
50283
50284
50285
50286class XFAParser extends XMLParserBase {
50287 constructor(rootNameSpace = null, richText = false) {
50288 super();
50289 this._builder = new Builder(rootNameSpace);
50290 this._stack = [];
50291 this._globalData = {
50292 usedTypefaces: new Set()
50293 };
50294 this._ids = new Map();
50295 this._current = this._builder.buildRoot(this._ids);
50296 this._errorCode = XMLParserErrorCode.NoError;
50297 this._whiteRegex = /^\s+$/;
50298 this._nbsps = /\xa0+/g;
50299 this._richText = richText;
50300 }
50301 parse(data) {
50302 this.parseXml(data);
50303 if (this._errorCode !== XMLParserErrorCode.NoError) {
50304 return undefined;
50305 }
50306 this._current[$finalize]();
50307 return this._current.element;
50308 }
50309 onText(text) {
50310 text = text.replace(this._nbsps, match => match.slice(1) + " ");
50311 if (this._richText || this._current[$acceptWhitespace]()) {
50312 this._current[$onText](text, this._richText);
50313 return;
50314 }
50315 if (this._whiteRegex.test(text)) {
50316 return;
50317 }
50318 this._current[$onText](text.trim());
50319 }
50320 onCdata(text) {
50321 this._current[$onText](text);
50322 }
50323 _mkAttributes(attributes, tagName) {
50324 let namespace = null;
50325 let prefixes = null;
50326 const attributeObj = Object.create({});
50327 for (const {
50328 name,
50329 value
50330 } of attributes) {
50331 if (name === "xmlns") {
50332 if (!namespace) {
50333 namespace = value;
50334 } else {
50335 warn(`XFA - multiple namespace definition in <${tagName}>`);
50336 }
50337 } else if (name.startsWith("xmlns:")) {
50338 const prefix = name.substring("xmlns:".length);
50339 if (!prefixes) {
50340 prefixes = [];
50341 }
50342 prefixes.push({
50343 prefix,
50344 value
50345 });
50346 } else {
50347 const i = name.indexOf(":");
50348 if (i === -1) {
50349 attributeObj[name] = value;
50350 } else {
50351 let nsAttrs = attributeObj[$nsAttributes];
50352 if (!nsAttrs) {
50353 nsAttrs = attributeObj[$nsAttributes] = Object.create(null);
50354 }
50355 const [ns, attrName] = [name.slice(0, i), name.slice(i + 1)];
50356 const attrs = nsAttrs[ns] ||= Object.create(null);
50357 attrs[attrName] = value;
50358 }
50359 }
50360 }
50361 return [namespace, prefixes, attributeObj];
50362 }
50363 _getNameAndPrefix(name, nsAgnostic) {
50364 const i = name.indexOf(":");
50365 if (i === -1) {
50366 return [name, null];
50367 }
50368 return [name.substring(i + 1), nsAgnostic ? "" : name.substring(0, i)];
50369 }
50370 onBeginElement(tagName, attributes, isEmpty) {
50371 const [namespace, prefixes, attributesObj] = this._mkAttributes(attributes, tagName);
50372 const [name, nsPrefix] = this._getNameAndPrefix(tagName, this._builder.isNsAgnostic());
50373 const node = this._builder.build({
50374 nsPrefix,
50375 name,
50376 attributes: attributesObj,
50377 namespace,
50378 prefixes
50379 });
50380 node[$globalData] = this._globalData;
50381 if (isEmpty) {
50382 node[$finalize]();
50383 if (this._current[$onChild](node)) {
50384 node[$setId](this._ids);
50385 }
50386 node[$clean](this._builder);
50387 return;
50388 }
50389 this._stack.push(this._current);
50390 this._current = node;
50391 }
50392 onEndElement(name) {
50393 const node = this._current;
50394 if (node[$isCDATAXml]() && typeof node[$content] === "string") {
50395 const parser = new XFAParser();
50396 parser._globalData = this._globalData;
50397 const root = parser.parse(node[$content]);
50398 node[$content] = null;
50399 node[$onChild](root);
50400 }
50401 node[$finalize]();
50402 this._current = this._stack.pop();
50403 if (this._current[$onChild](node)) {
50404 node[$setId](this._ids);
50405 }
50406 node[$clean](this._builder);
50407 }
50408 onError(code) {
50409 this._errorCode = code;
50410 }
50411}
50412
50413;// CONCATENATED MODULE: ./src/core/xfa/factory.js
50414
50415
50416
50417
50418
50419
50420
50421
50422class XFAFactory {
50423 constructor(data) {
50424 try {
50425 this.root = new XFAParser().parse(XFAFactory._createDocument(data));
50426 const binder = new Binder(this.root);
50427 this.form = binder.bind();
50428 this.dataHandler = new DataHandler(this.root, binder.getData());
50429 this.form[$globalData].template = this.form;
50430 } catch (e) {
50431 warn(`XFA - an error occurred during parsing and binding: ${e}`);
50432 }
50433 }
50434 isValid() {
50435 return this.root && this.form;
50436 }
50437 _createPagesHelper() {
50438 const iterator = this.form[$toPages]();
50439 return new Promise((resolve, reject) => {
50440 const nextIteration = () => {
50441 try {
50442 const value = iterator.next();
50443 if (value.done) {
50444 resolve(value.value);
50445 } else {
50446 setTimeout(nextIteration, 0);
50447 }
50448 } catch (e) {
50449 reject(e);
50450 }
50451 };
50452 setTimeout(nextIteration, 0);
50453 });
50454 }
50455 async _createPages() {
50456 try {
50457 this.pages = await this._createPagesHelper();
50458 this.dims = this.pages.children.map(c => {
50459 const {
50460 width,
50461 height
50462 } = c.attributes.style;
50463 return [0, 0, parseInt(width), parseInt(height)];
50464 });
50465 } catch (e) {
50466 warn(`XFA - an error occurred during layout: ${e}`);
50467 }
50468 }
50469 getBoundingBox(pageIndex) {
50470 return this.dims[pageIndex];
50471 }
50472 async getNumPages() {
50473 if (!this.pages) {
50474 await this._createPages();
50475 }
50476 return this.dims.length;
50477 }
50478 setImages(images) {
50479 this.form[$globalData].images = images;
50480 }
50481 setFonts(fonts) {
50482 this.form[$globalData].fontFinder = new FontFinder(fonts);
50483 const missingFonts = [];
50484 for (let typeface of this.form[$globalData].usedTypefaces) {
50485 typeface = stripQuotes(typeface);
50486 const font = this.form[$globalData].fontFinder.find(typeface);
50487 if (!font) {
50488 missingFonts.push(typeface);
50489 }
50490 }
50491 if (missingFonts.length > 0) {
50492 return missingFonts;
50493 }
50494 return null;
50495 }
50496 appendFonts(fonts, reallyMissingFonts) {
50497 this.form[$globalData].fontFinder.add(fonts, reallyMissingFonts);
50498 }
50499 async getPages() {
50500 if (!this.pages) {
50501 await this._createPages();
50502 }
50503 const pages = this.pages;
50504 this.pages = null;
50505 return pages;
50506 }
50507 serializeData(storage) {
50508 return this.dataHandler.serialize(storage);
50509 }
50510 static _createDocument(data) {
50511 if (!data["/xdp:xdp"]) {
50512 return data["xdp:xdp"];
50513 }
50514 return Object.values(data).join("");
50515 }
50516 static getRichTextAsHtml(rc) {
50517 if (!rc || typeof rc !== "string") {
50518 return null;
50519 }
50520 try {
50521 let root = new XFAParser(XhtmlNamespace, true).parse(rc);
50522 if (!["body", "xhtml"].includes(root[$nodeName])) {
50523 const newRoot = XhtmlNamespace.body({});
50524 newRoot[$appendChild](root);
50525 root = newRoot;
50526 }
50527 const result = root[$toHTML]();
50528 if (!result.success) {
50529 return null;
50530 }
50531 const {
50532 html
50533 } = result;
50534 const {
50535 attributes
50536 } = html;
50537 if (attributes) {
50538 if (attributes.class) {
50539 attributes.class = attributes.class.filter(attr => !attr.startsWith("xfa"));
50540 }
50541 attributes.dir = "auto";
50542 }
50543 return {
50544 html,
50545 str: root[$text]()
50546 };
50547 } catch (e) {
50548 warn(`XFA - an error occurred during parsing of rich text: ${e}`);
50549 }
50550 return null;
50551 }
50552}
50553
50554;// CONCATENATED MODULE: ./src/core/annotation.js
50555
50556
50557
50558
50559
50560
50561
50562
50563
50564
50565
50566
50567
50568
50569
50570class AnnotationFactory {
50571 static createGlobals(pdfManager) {
50572 return Promise.all([pdfManager.ensureCatalog("acroForm"), pdfManager.ensureDoc("xfaDatasets"), pdfManager.ensureCatalog("structTreeRoot"), pdfManager.ensureCatalog("baseUrl"), pdfManager.ensureCatalog("attachments")]).then(([acroForm, xfaDatasets, structTreeRoot, baseUrl, attachments]) => {
50573 return {
50574 pdfManager,
50575 acroForm: acroForm instanceof Dict ? acroForm : Dict.empty,
50576 xfaDatasets,
50577 structTreeRoot,
50578 baseUrl,
50579 attachments
50580 };
50581 }, reason => {
50582 warn(`createGlobals: "${reason}".`);
50583 return null;
50584 });
50585 }
50586 static async create(xref, ref, annotationGlobals, idFactory, collectFields, pageRef) {
50587 const pageIndex = collectFields ? await this._getPageIndex(xref, ref, annotationGlobals.pdfManager) : null;
50588 return annotationGlobals.pdfManager.ensure(this, "_create", [xref, ref, annotationGlobals, idFactory, collectFields, pageIndex, pageRef]);
50589 }
50590 static _create(xref, ref, annotationGlobals, idFactory, collectFields = false, pageIndex = null, pageRef = null) {
50591 const dict = xref.fetchIfRef(ref);
50592 if (!(dict instanceof Dict)) {
50593 return undefined;
50594 }
50595 const {
50596 acroForm,
50597 pdfManager
50598 } = annotationGlobals;
50599 const id = ref instanceof Ref ? ref.toString() : `annot_${idFactory.createObjId()}`;
50600 let subtype = dict.get("Subtype");
50601 subtype = subtype instanceof Name ? subtype.name : null;
50602 const parameters = {
50603 xref,
50604 ref,
50605 dict,
50606 subtype,
50607 id,
50608 annotationGlobals,
50609 collectFields,
50610 needAppearances: !collectFields && acroForm.get("NeedAppearances") === true,
50611 pageIndex,
50612 evaluatorOptions: pdfManager.evaluatorOptions,
50613 pageRef
50614 };
50615 switch (subtype) {
50616 case "Link":
50617 return new LinkAnnotation(parameters);
50618 case "Text":
50619 return new TextAnnotation(parameters);
50620 case "Widget":
50621 let fieldType = getInheritableProperty({
50622 dict,
50623 key: "FT"
50624 });
50625 fieldType = fieldType instanceof Name ? fieldType.name : null;
50626 switch (fieldType) {
50627 case "Tx":
50628 return new TextWidgetAnnotation(parameters);
50629 case "Btn":
50630 return new ButtonWidgetAnnotation(parameters);
50631 case "Ch":
50632 return new ChoiceWidgetAnnotation(parameters);
50633 case "Sig":
50634 return new SignatureWidgetAnnotation(parameters);
50635 }
50636 warn(`Unimplemented widget field type "${fieldType}", ` + "falling back to base field type.");
50637 return new WidgetAnnotation(parameters);
50638 case "Popup":
50639 return new PopupAnnotation(parameters);
50640 case "FreeText":
50641 return new FreeTextAnnotation(parameters);
50642 case "Line":
50643 return new LineAnnotation(parameters);
50644 case "Square":
50645 return new SquareAnnotation(parameters);
50646 case "Circle":
50647 return new CircleAnnotation(parameters);
50648 case "PolyLine":
50649 return new PolylineAnnotation(parameters);
50650 case "Polygon":
50651 return new PolygonAnnotation(parameters);
50652 case "Caret":
50653 return new CaretAnnotation(parameters);
50654 case "Ink":
50655 return new InkAnnotation(parameters);
50656 case "Highlight":
50657 return new HighlightAnnotation(parameters);
50658 case "Underline":
50659 return new UnderlineAnnotation(parameters);
50660 case "Squiggly":
50661 return new SquigglyAnnotation(parameters);
50662 case "StrikeOut":
50663 return new StrikeOutAnnotation(parameters);
50664 case "Stamp":
50665 return new StampAnnotation(parameters);
50666 case "FileAttachment":
50667 return new FileAttachmentAnnotation(parameters);
50668 default:
50669 if (!collectFields) {
50670 if (!subtype) {
50671 warn("Annotation is missing the required /Subtype.");
50672 } else {
50673 warn(`Unimplemented annotation type "${subtype}", ` + "falling back to base annotation.");
50674 }
50675 }
50676 return new Annotation(parameters);
50677 }
50678 }
50679 static async _getPageIndex(xref, ref, pdfManager) {
50680 try {
50681 const annotDict = await xref.fetchIfRefAsync(ref);
50682 if (!(annotDict instanceof Dict)) {
50683 return -1;
50684 }
50685 const pageRef = annotDict.getRaw("P");
50686 if (pageRef instanceof Ref) {
50687 try {
50688 const pageIndex = await pdfManager.ensureCatalog("getPageIndex", [pageRef]);
50689 return pageIndex;
50690 } catch (ex) {
50691 info(`_getPageIndex -- not a valid page reference: "${ex}".`);
50692 }
50693 }
50694 if (annotDict.has("Kids")) {
50695 return -1;
50696 }
50697 const numPages = await pdfManager.ensureDoc("numPages");
50698 for (let pageIndex = 0; pageIndex < numPages; pageIndex++) {
50699 const page = await pdfManager.getPage(pageIndex);
50700 const annotations = await pdfManager.ensure(page, "annotations");
50701 for (const annotRef of annotations) {
50702 if (annotRef instanceof Ref && isRefsEqual(annotRef, ref)) {
50703 return pageIndex;
50704 }
50705 }
50706 }
50707 } catch (ex) {
50708 warn(`_getPageIndex: "${ex}".`);
50709 }
50710 return -1;
50711 }
50712 static generateImages(annotations, xref, isOffscreenCanvasSupported) {
50713 if (!isOffscreenCanvasSupported) {
50714 warn("generateImages: OffscreenCanvas is not supported, cannot save or print some annotations with images.");
50715 return null;
50716 }
50717 let imagePromises;
50718 for (const {
50719 bitmapId,
50720 bitmap
50721 } of annotations) {
50722 if (!bitmap) {
50723 continue;
50724 }
50725 imagePromises ||= new Map();
50726 imagePromises.set(bitmapId, StampAnnotation.createImage(bitmap, xref));
50727 }
50728 return imagePromises;
50729 }
50730 static async saveNewAnnotations(evaluator, task, annotations, imagePromises) {
50731 const xref = evaluator.xref;
50732 let baseFontRef;
50733 const dependencies = [];
50734 const promises = [];
50735 const {
50736 isOffscreenCanvasSupported
50737 } = evaluator.options;
50738 for (const annotation of annotations) {
50739 if (annotation.deleted) {
50740 continue;
50741 }
50742 switch (annotation.annotationType) {
50743 case AnnotationEditorType.FREETEXT:
50744 if (!baseFontRef) {
50745 const baseFont = new Dict(xref);
50746 baseFont.set("BaseFont", Name.get("Helvetica"));
50747 baseFont.set("Type", Name.get("Font"));
50748 baseFont.set("Subtype", Name.get("Type1"));
50749 baseFont.set("Encoding", Name.get("WinAnsiEncoding"));
50750 const buffer = [];
50751 baseFontRef = xref.getNewTemporaryRef();
50752 await writeObject(baseFontRef, baseFont, buffer, xref);
50753 dependencies.push({
50754 ref: baseFontRef,
50755 data: buffer.join("")
50756 });
50757 }
50758 promises.push(FreeTextAnnotation.createNewAnnotation(xref, annotation, dependencies, {
50759 evaluator,
50760 task,
50761 baseFontRef
50762 }));
50763 break;
50764 case AnnotationEditorType.HIGHLIGHT:
50765 if (annotation.quadPoints) {
50766 promises.push(HighlightAnnotation.createNewAnnotation(xref, annotation, dependencies));
50767 } else {
50768 promises.push(InkAnnotation.createNewAnnotation(xref, annotation, dependencies));
50769 }
50770 break;
50771 case AnnotationEditorType.INK:
50772 promises.push(InkAnnotation.createNewAnnotation(xref, annotation, dependencies));
50773 break;
50774 case AnnotationEditorType.STAMP:
50775 if (!isOffscreenCanvasSupported) {
50776 break;
50777 }
50778 const image = await imagePromises.get(annotation.bitmapId);
50779 if (image.imageStream) {
50780 const {
50781 imageStream,
50782 smaskStream
50783 } = image;
50784 const buffer = [];
50785 if (smaskStream) {
50786 const smaskRef = xref.getNewTemporaryRef();
50787 await writeObject(smaskRef, smaskStream, buffer, xref);
50788 dependencies.push({
50789 ref: smaskRef,
50790 data: buffer.join("")
50791 });
50792 imageStream.dict.set("SMask", smaskRef);
50793 buffer.length = 0;
50794 }
50795 const imageRef = image.imageRef = xref.getNewTemporaryRef();
50796 await writeObject(imageRef, imageStream, buffer, xref);
50797 dependencies.push({
50798 ref: imageRef,
50799 data: buffer.join("")
50800 });
50801 image.imageStream = image.smaskStream = null;
50802 }
50803 promises.push(StampAnnotation.createNewAnnotation(xref, annotation, dependencies, {
50804 image
50805 }));
50806 break;
50807 }
50808 }
50809 return {
50810 annotations: await Promise.all(promises),
50811 dependencies
50812 };
50813 }
50814 static async printNewAnnotations(annotationGlobals, evaluator, task, annotations, imagePromises) {
50815 if (!annotations) {
50816 return null;
50817 }
50818 const {
50819 options,
50820 xref
50821 } = evaluator;
50822 const promises = [];
50823 for (const annotation of annotations) {
50824 if (annotation.deleted) {
50825 continue;
50826 }
50827 switch (annotation.annotationType) {
50828 case AnnotationEditorType.FREETEXT:
50829 promises.push(FreeTextAnnotation.createNewPrintAnnotation(annotationGlobals, xref, annotation, {
50830 evaluator,
50831 task,
50832 evaluatorOptions: options
50833 }));
50834 break;
50835 case AnnotationEditorType.HIGHLIGHT:
50836 if (annotation.quadPoints) {
50837 promises.push(HighlightAnnotation.createNewPrintAnnotation(annotationGlobals, xref, annotation, {
50838 evaluatorOptions: options
50839 }));
50840 } else {
50841 promises.push(InkAnnotation.createNewPrintAnnotation(annotationGlobals, xref, annotation, {
50842 evaluatorOptions: options
50843 }));
50844 }
50845 break;
50846 case AnnotationEditorType.INK:
50847 promises.push(InkAnnotation.createNewPrintAnnotation(annotationGlobals, xref, annotation, {
50848 evaluatorOptions: options
50849 }));
50850 break;
50851 case AnnotationEditorType.STAMP:
50852 if (!options.isOffscreenCanvasSupported) {
50853 break;
50854 }
50855 const image = await imagePromises.get(annotation.bitmapId);
50856 if (image.imageStream) {
50857 const {
50858 imageStream,
50859 smaskStream
50860 } = image;
50861 if (smaskStream) {
50862 imageStream.dict.set("SMask", smaskStream);
50863 }
50864 image.imageRef = new JpegStream(imageStream, imageStream.length);
50865 image.imageStream = image.smaskStream = null;
50866 }
50867 promises.push(StampAnnotation.createNewPrintAnnotation(annotationGlobals, xref, annotation, {
50868 image,
50869 evaluatorOptions: options
50870 }));
50871 break;
50872 }
50873 }
50874 return Promise.all(promises);
50875 }
50876}
50877function getRgbColor(color, defaultColor = new Uint8ClampedArray(3)) {
50878 if (!Array.isArray(color)) {
50879 return defaultColor;
50880 }
50881 const rgbColor = defaultColor || new Uint8ClampedArray(3);
50882 switch (color.length) {
50883 case 0:
50884 return null;
50885 case 1:
50886 ColorSpace.singletons.gray.getRgbItem(color, 0, rgbColor, 0);
50887 return rgbColor;
50888 case 3:
50889 ColorSpace.singletons.rgb.getRgbItem(color, 0, rgbColor, 0);
50890 return rgbColor;
50891 case 4:
50892 ColorSpace.singletons.cmyk.getRgbItem(color, 0, rgbColor, 0);
50893 return rgbColor;
50894 default:
50895 return defaultColor;
50896 }
50897}
50898function getPdfColorArray(color) {
50899 return Array.from(color, c => c / 255);
50900}
50901function getQuadPoints(dict, rect) {
50902 const quadPoints = dict.getArray("QuadPoints");
50903 if (!Array.isArray(quadPoints) || quadPoints.length === 0 || quadPoints.length % 8 > 0) {
50904 return null;
50905 }
50906 const quadPointsLists = [];
50907 for (let i = 0, ii = quadPoints.length / 8; i < ii; i++) {
50908 let minX = Infinity,
50909 maxX = -Infinity,
50910 minY = Infinity,
50911 maxY = -Infinity;
50912 for (let j = i * 8, jj = i * 8 + 8; j < jj; j += 2) {
50913 const x = quadPoints[j];
50914 const y = quadPoints[j + 1];
50915 minX = Math.min(x, minX);
50916 maxX = Math.max(x, maxX);
50917 minY = Math.min(y, minY);
50918 maxY = Math.max(y, maxY);
50919 }
50920 if (rect !== null && (minX < rect[0] || maxX > rect[2] || minY < rect[1] || maxY > rect[3])) {
50921 return null;
50922 }
50923 quadPointsLists.push([{
50924 x: minX,
50925 y: maxY
50926 }, {
50927 x: maxX,
50928 y: maxY
50929 }, {
50930 x: minX,
50931 y: minY
50932 }, {
50933 x: maxX,
50934 y: minY
50935 }]);
50936 }
50937 return quadPointsLists;
50938}
50939function getTransformMatrix(rect, bbox, matrix) {
50940 const [minX, minY, maxX, maxY] = Util.getAxialAlignedBoundingBox(bbox, matrix);
50941 if (minX === maxX || minY === maxY) {
50942 return [1, 0, 0, 1, rect[0], rect[1]];
50943 }
50944 const xRatio = (rect[2] - rect[0]) / (maxX - minX);
50945 const yRatio = (rect[3] - rect[1]) / (maxY - minY);
50946 return [xRatio, 0, 0, yRatio, rect[0] - minX * xRatio, rect[1] - minY * yRatio];
50947}
50948class Annotation {
50949 constructor(params) {
50950 const {
50951 dict,
50952 xref,
50953 annotationGlobals
50954 } = params;
50955 this.setTitle(dict.get("T"));
50956 this.setContents(dict.get("Contents"));
50957 this.setModificationDate(dict.get("M"));
50958 this.setFlags(dict.get("F"));
50959 this.setRectangle(dict.getArray("Rect"));
50960 this.setColor(dict.getArray("C"));
50961 this.setBorderStyle(dict);
50962 this.setAppearance(dict);
50963 this.setOptionalContent(dict);
50964 const MK = dict.get("MK");
50965 this.setBorderAndBackgroundColors(MK);
50966 this.setRotation(MK, dict);
50967 this.ref = params.ref instanceof Ref ? params.ref : null;
50968 this._streams = [];
50969 if (this.appearance) {
50970 this._streams.push(this.appearance);
50971 }
50972 const isLocked = !!(this.flags & AnnotationFlag.LOCKED);
50973 const isContentLocked = !!(this.flags & AnnotationFlag.LOCKEDCONTENTS);
50974 if (annotationGlobals.structTreeRoot) {
50975 let structParent = dict.get("StructParent");
50976 structParent = Number.isInteger(structParent) && structParent >= 0 ? structParent : -1;
50977 annotationGlobals.structTreeRoot.addAnnotationIdToPage(params.pageRef, structParent);
50978 }
50979 this.data = {
50980 annotationFlags: this.flags,
50981 borderStyle: this.borderStyle,
50982 color: this.color,
50983 backgroundColor: this.backgroundColor,
50984 borderColor: this.borderColor,
50985 rotation: this.rotation,
50986 contentsObj: this._contents,
50987 hasAppearance: !!this.appearance,
50988 id: params.id,
50989 modificationDate: this.modificationDate,
50990 rect: this.rectangle,
50991 subtype: params.subtype,
50992 hasOwnCanvas: false,
50993 noRotate: !!(this.flags & AnnotationFlag.NOROTATE),
50994 noHTML: isLocked && isContentLocked
50995 };
50996 if (params.collectFields) {
50997 const kids = dict.get("Kids");
50998 if (Array.isArray(kids)) {
50999 const kidIds = [];
51000 for (const kid of kids) {
51001 if (kid instanceof Ref) {
51002 kidIds.push(kid.toString());
51003 }
51004 }
51005 if (kidIds.length !== 0) {
51006 this.data.kidIds = kidIds;
51007 }
51008 }
51009 this.data.actions = collectActions(xref, dict, AnnotationActionEventType);
51010 this.data.fieldName = this._constructFieldName(dict);
51011 this.data.pageIndex = params.pageIndex;
51012 }
51013 this._isOffscreenCanvasSupported = params.evaluatorOptions.isOffscreenCanvasSupported;
51014 this._fallbackFontDict = null;
51015 this._needAppearances = false;
51016 }
51017 _hasFlag(flags, flag) {
51018 return !!(flags & flag);
51019 }
51020 _isViewable(flags) {
51021 return !this._hasFlag(flags, AnnotationFlag.INVISIBLE) && !this._hasFlag(flags, AnnotationFlag.NOVIEW);
51022 }
51023 _isPrintable(flags) {
51024 return this._hasFlag(flags, AnnotationFlag.PRINT) && !this._hasFlag(flags, AnnotationFlag.HIDDEN) && !this._hasFlag(flags, AnnotationFlag.INVISIBLE);
51025 }
51026 mustBeViewed(annotationStorage, _renderForms) {
51027 const noView = annotationStorage?.get(this.data.id)?.noView;
51028 if (noView !== undefined) {
51029 return !noView;
51030 }
51031 return this.viewable && !this._hasFlag(this.flags, AnnotationFlag.HIDDEN);
51032 }
51033 mustBePrinted(annotationStorage) {
51034 const noPrint = annotationStorage?.get(this.data.id)?.noPrint;
51035 if (noPrint !== undefined) {
51036 return !noPrint;
51037 }
51038 return this.printable;
51039 }
51040 get viewable() {
51041 if (this.data.quadPoints === null) {
51042 return false;
51043 }
51044 if (this.flags === 0) {
51045 return true;
51046 }
51047 return this._isViewable(this.flags);
51048 }
51049 get printable() {
51050 if (this.data.quadPoints === null) {
51051 return false;
51052 }
51053 if (this.flags === 0) {
51054 return false;
51055 }
51056 return this._isPrintable(this.flags);
51057 }
51058 _parseStringHelper(data) {
51059 const str = typeof data === "string" ? stringToPDFString(data) : "";
51060 const dir = str && bidi(str).dir === "rtl" ? "rtl" : "ltr";
51061 return {
51062 str,
51063 dir
51064 };
51065 }
51066 setDefaultAppearance(params) {
51067 const {
51068 dict,
51069 annotationGlobals
51070 } = params;
51071 const defaultAppearance = getInheritableProperty({
51072 dict,
51073 key: "DA"
51074 }) || annotationGlobals.acroForm.get("DA");
51075 this._defaultAppearance = typeof defaultAppearance === "string" ? defaultAppearance : "";
51076 this.data.defaultAppearanceData = parseDefaultAppearance(this._defaultAppearance);
51077 }
51078 setTitle(title) {
51079 this._title = this._parseStringHelper(title);
51080 }
51081 setContents(contents) {
51082 this._contents = this._parseStringHelper(contents);
51083 }
51084 setModificationDate(modificationDate) {
51085 this.modificationDate = typeof modificationDate === "string" ? modificationDate : null;
51086 }
51087 setFlags(flags) {
51088 this.flags = Number.isInteger(flags) && flags > 0 ? flags : 0;
51089 if (this.flags & AnnotationFlag.INVISIBLE && this.constructor.name !== "Annotation") {
51090 this.flags ^= AnnotationFlag.INVISIBLE;
51091 }
51092 }
51093 hasFlag(flag) {
51094 return this._hasFlag(this.flags, flag);
51095 }
51096 setRectangle(rectangle) {
51097 this.rectangle = Array.isArray(rectangle) && rectangle.length === 4 ? Util.normalizeRect(rectangle) : [0, 0, 0, 0];
51098 }
51099 setColor(color) {
51100 this.color = getRgbColor(color);
51101 }
51102 setLineEndings(lineEndings) {
51103 this.lineEndings = ["None", "None"];
51104 if (Array.isArray(lineEndings) && lineEndings.length === 2) {
51105 for (let i = 0; i < 2; i++) {
51106 const obj = lineEndings[i];
51107 if (obj instanceof Name) {
51108 switch (obj.name) {
51109 case "None":
51110 continue;
51111 case "Square":
51112 case "Circle":
51113 case "Diamond":
51114 case "OpenArrow":
51115 case "ClosedArrow":
51116 case "Butt":
51117 case "ROpenArrow":
51118 case "RClosedArrow":
51119 case "Slash":
51120 this.lineEndings[i] = obj.name;
51121 continue;
51122 }
51123 }
51124 warn(`Ignoring invalid lineEnding: ${obj}`);
51125 }
51126 }
51127 }
51128 setRotation(mk, dict) {
51129 this.rotation = 0;
51130 let angle = mk instanceof Dict ? mk.get("R") || 0 : dict.get("Rotate") || 0;
51131 if (Number.isInteger(angle) && angle !== 0) {
51132 angle %= 360;
51133 if (angle < 0) {
51134 angle += 360;
51135 }
51136 if (angle % 90 === 0) {
51137 this.rotation = angle;
51138 }
51139 }
51140 }
51141 setBorderAndBackgroundColors(mk) {
51142 if (mk instanceof Dict) {
51143 this.borderColor = getRgbColor(mk.getArray("BC"), null);
51144 this.backgroundColor = getRgbColor(mk.getArray("BG"), null);
51145 } else {
51146 this.borderColor = this.backgroundColor = null;
51147 }
51148 }
51149 setBorderStyle(borderStyle) {
51150 this.borderStyle = new AnnotationBorderStyle();
51151 if (!(borderStyle instanceof Dict)) {
51152 return;
51153 }
51154 if (borderStyle.has("BS")) {
51155 const dict = borderStyle.get("BS");
51156 if (dict instanceof Dict) {
51157 const dictType = dict.get("Type");
51158 if (!dictType || isName(dictType, "Border")) {
51159 this.borderStyle.setWidth(dict.get("W"), this.rectangle);
51160 this.borderStyle.setStyle(dict.get("S"));
51161 this.borderStyle.setDashArray(dict.getArray("D"));
51162 }
51163 }
51164 } else if (borderStyle.has("Border")) {
51165 const array = borderStyle.getArray("Border");
51166 if (Array.isArray(array) && array.length >= 3) {
51167 this.borderStyle.setHorizontalCornerRadius(array[0]);
51168 this.borderStyle.setVerticalCornerRadius(array[1]);
51169 this.borderStyle.setWidth(array[2], this.rectangle);
51170 if (array.length === 4) {
51171 this.borderStyle.setDashArray(array[3], true);
51172 }
51173 }
51174 } else {
51175 this.borderStyle.setWidth(0);
51176 }
51177 }
51178 setAppearance(dict) {
51179 this.appearance = null;
51180 const appearanceStates = dict.get("AP");
51181 if (!(appearanceStates instanceof Dict)) {
51182 return;
51183 }
51184 const normalAppearanceState = appearanceStates.get("N");
51185 if (normalAppearanceState instanceof BaseStream) {
51186 this.appearance = normalAppearanceState;
51187 return;
51188 }
51189 if (!(normalAppearanceState instanceof Dict)) {
51190 return;
51191 }
51192 const as = dict.get("AS");
51193 if (!(as instanceof Name) || !normalAppearanceState.has(as.name)) {
51194 return;
51195 }
51196 const appearance = normalAppearanceState.get(as.name);
51197 if (appearance instanceof BaseStream) {
51198 this.appearance = appearance;
51199 }
51200 }
51201 setOptionalContent(dict) {
51202 this.oc = null;
51203 const oc = dict.get("OC");
51204 if (oc instanceof Name) {
51205 warn("setOptionalContent: Support for /Name-entry is not implemented.");
51206 } else if (oc instanceof Dict) {
51207 this.oc = oc;
51208 }
51209 }
51210 loadResources(keys, appearance) {
51211 return appearance.dict.getAsync("Resources").then(resources => {
51212 if (!resources) {
51213 return undefined;
51214 }
51215 const objectLoader = new ObjectLoader(resources, keys, resources.xref);
51216 return objectLoader.load().then(function () {
51217 return resources;
51218 });
51219 });
51220 }
51221 async getOperatorList(evaluator, task, intent, renderForms, annotationStorage) {
51222 const {
51223 hasOwnCanvas,
51224 id,
51225 rect
51226 } = this.data;
51227 let appearance = this.appearance;
51228 const isUsingOwnCanvas = !!(hasOwnCanvas && intent & RenderingIntentFlag.DISPLAY);
51229 if (isUsingOwnCanvas && (rect[0] === rect[2] || rect[1] === rect[3])) {
51230 this.data.hasOwnCanvas = false;
51231 return {
51232 opList: new OperatorList(),
51233 separateForm: false,
51234 separateCanvas: false
51235 };
51236 }
51237 if (!appearance) {
51238 if (!isUsingOwnCanvas) {
51239 return {
51240 opList: new OperatorList(),
51241 separateForm: false,
51242 separateCanvas: false
51243 };
51244 }
51245 appearance = new StringStream("");
51246 appearance.dict = new Dict();
51247 }
51248 const appearanceDict = appearance.dict;
51249 const resources = await this.loadResources(["ExtGState", "ColorSpace", "Pattern", "Shading", "XObject", "Font"], appearance);
51250 const bbox = appearanceDict.getArray("BBox") || [0, 0, 1, 1];
51251 const matrix = appearanceDict.getArray("Matrix") || [1, 0, 0, 1, 0, 0];
51252 const transform = getTransformMatrix(rect, bbox, matrix);
51253 const opList = new OperatorList();
51254 let optionalContent;
51255 if (this.oc) {
51256 optionalContent = await evaluator.parseMarkedContentProps(this.oc, null);
51257 }
51258 if (optionalContent !== undefined) {
51259 opList.addOp(OPS.beginMarkedContentProps, ["OC", optionalContent]);
51260 }
51261 opList.addOp(OPS.beginAnnotation, [id, rect, transform, matrix, isUsingOwnCanvas]);
51262 await evaluator.getOperatorList({
51263 stream: appearance,
51264 task,
51265 resources,
51266 operatorList: opList,
51267 fallbackFontDict: this._fallbackFontDict
51268 });
51269 opList.addOp(OPS.endAnnotation, []);
51270 if (optionalContent !== undefined) {
51271 opList.addOp(OPS.endMarkedContent, []);
51272 }
51273 this.reset();
51274 return {
51275 opList,
51276 separateForm: false,
51277 separateCanvas: isUsingOwnCanvas
51278 };
51279 }
51280 async save(evaluator, task, annotationStorage) {
51281 return null;
51282 }
51283 get hasTextContent() {
51284 return false;
51285 }
51286 async extractTextContent(evaluator, task, viewBox) {
51287 if (!this.appearance) {
51288 return;
51289 }
51290 const resources = await this.loadResources(["ExtGState", "Font", "Properties", "XObject"], this.appearance);
51291 const text = [];
51292 const buffer = [];
51293 let firstPosition = null;
51294 const sink = {
51295 desiredSize: Math.Infinity,
51296 ready: true,
51297 enqueue(chunk, size) {
51298 for (const item of chunk.items) {
51299 if (item.str === undefined) {
51300 continue;
51301 }
51302 firstPosition ||= item.transform.slice(-2);
51303 buffer.push(item.str);
51304 if (item.hasEOL) {
51305 text.push(buffer.join("").trimEnd());
51306 buffer.length = 0;
51307 }
51308 }
51309 }
51310 };
51311 await evaluator.getTextContent({
51312 stream: this.appearance,
51313 task,
51314 resources,
51315 includeMarkedContent: true,
51316 keepWhiteSpace: true,
51317 sink,
51318 viewBox
51319 });
51320 this.reset();
51321 if (buffer.length) {
51322 text.push(buffer.join("").trimEnd());
51323 }
51324 if (text.length > 1 || text[0]) {
51325 const appearanceDict = this.appearance.dict;
51326 this.data.textPosition = this._transformPoint(firstPosition, appearanceDict.getArray("BBox"), appearanceDict.getArray("Matrix"));
51327 this.data.textContent = text;
51328 }
51329 }
51330 _transformPoint(coords, bbox, matrix) {
51331 const {
51332 rect
51333 } = this.data;
51334 bbox ||= [0, 0, 1, 1];
51335 matrix ||= [1, 0, 0, 1, 0, 0];
51336 const transform = getTransformMatrix(rect, bbox, matrix);
51337 transform[4] -= rect[0];
51338 transform[5] -= rect[1];
51339 coords = Util.applyTransform(coords, transform);
51340 return Util.applyTransform(coords, matrix);
51341 }
51342 getFieldObject() {
51343 if (this.data.kidIds) {
51344 return {
51345 id: this.data.id,
51346 actions: this.data.actions,
51347 name: this.data.fieldName,
51348 strokeColor: this.data.borderColor,
51349 fillColor: this.data.backgroundColor,
51350 type: "",
51351 kidIds: this.data.kidIds,
51352 page: this.data.pageIndex,
51353 rotation: this.rotation
51354 };
51355 }
51356 return null;
51357 }
51358 reset() {
51359 for (const stream of this._streams) {
51360 stream.reset();
51361 }
51362 }
51363 _constructFieldName(dict) {
51364 if (!dict.has("T") && !dict.has("Parent")) {
51365 warn("Unknown field name, falling back to empty field name.");
51366 return "";
51367 }
51368 if (!dict.has("Parent")) {
51369 return stringToPDFString(dict.get("T"));
51370 }
51371 const fieldName = [];
51372 if (dict.has("T")) {
51373 fieldName.unshift(stringToPDFString(dict.get("T")));
51374 }
51375 let loopDict = dict;
51376 const visited = new RefSet();
51377 if (dict.objId) {
51378 visited.put(dict.objId);
51379 }
51380 while (loopDict.has("Parent")) {
51381 loopDict = loopDict.get("Parent");
51382 if (!(loopDict instanceof Dict) || loopDict.objId && visited.has(loopDict.objId)) {
51383 break;
51384 }
51385 if (loopDict.objId) {
51386 visited.put(loopDict.objId);
51387 }
51388 if (loopDict.has("T")) {
51389 fieldName.unshift(stringToPDFString(loopDict.get("T")));
51390 }
51391 }
51392 return fieldName.join(".");
51393 }
51394}
51395class AnnotationBorderStyle {
51396 constructor() {
51397 this.width = 1;
51398 this.style = AnnotationBorderStyleType.SOLID;
51399 this.dashArray = [3];
51400 this.horizontalCornerRadius = 0;
51401 this.verticalCornerRadius = 0;
51402 }
51403 setWidth(width, rect = [0, 0, 0, 0]) {
51404 if (width instanceof Name) {
51405 this.width = 0;
51406 return;
51407 }
51408 if (typeof width === "number") {
51409 if (width > 0) {
51410 const maxWidth = (rect[2] - rect[0]) / 2;
51411 const maxHeight = (rect[3] - rect[1]) / 2;
51412 if (maxWidth > 0 && maxHeight > 0 && (width > maxWidth || width > maxHeight)) {
51413 warn(`AnnotationBorderStyle.setWidth - ignoring width: ${width}`);
51414 width = 1;
51415 }
51416 }
51417 this.width = width;
51418 }
51419 }
51420 setStyle(style) {
51421 if (!(style instanceof Name)) {
51422 return;
51423 }
51424 switch (style.name) {
51425 case "S":
51426 this.style = AnnotationBorderStyleType.SOLID;
51427 break;
51428 case "D":
51429 this.style = AnnotationBorderStyleType.DASHED;
51430 break;
51431 case "B":
51432 this.style = AnnotationBorderStyleType.BEVELED;
51433 break;
51434 case "I":
51435 this.style = AnnotationBorderStyleType.INSET;
51436 break;
51437 case "U":
51438 this.style = AnnotationBorderStyleType.UNDERLINE;
51439 break;
51440 default:
51441 break;
51442 }
51443 }
51444 setDashArray(dashArray, forceStyle = false) {
51445 if (Array.isArray(dashArray)) {
51446 let isValid = true;
51447 let allZeros = true;
51448 for (const element of dashArray) {
51449 const validNumber = +element >= 0;
51450 if (!validNumber) {
51451 isValid = false;
51452 break;
51453 } else if (element > 0) {
51454 allZeros = false;
51455 }
51456 }
51457 if (dashArray.length === 0 || isValid && !allZeros) {
51458 this.dashArray = dashArray;
51459 if (forceStyle) {
51460 this.setStyle(Name.get("D"));
51461 }
51462 } else {
51463 this.width = 0;
51464 }
51465 } else if (dashArray) {
51466 this.width = 0;
51467 }
51468 }
51469 setHorizontalCornerRadius(radius) {
51470 if (Number.isInteger(radius)) {
51471 this.horizontalCornerRadius = radius;
51472 }
51473 }
51474 setVerticalCornerRadius(radius) {
51475 if (Number.isInteger(radius)) {
51476 this.verticalCornerRadius = radius;
51477 }
51478 }
51479}
51480class MarkupAnnotation extends Annotation {
51481 constructor(params) {
51482 super(params);
51483 const {
51484 dict
51485 } = params;
51486 if (dict.has("IRT")) {
51487 const rawIRT = dict.getRaw("IRT");
51488 this.data.inReplyTo = rawIRT instanceof Ref ? rawIRT.toString() : null;
51489 const rt = dict.get("RT");
51490 this.data.replyType = rt instanceof Name ? rt.name : AnnotationReplyType.REPLY;
51491 }
51492 let popupRef = null;
51493 if (this.data.replyType === AnnotationReplyType.GROUP) {
51494 const parent = dict.get("IRT");
51495 this.setTitle(parent.get("T"));
51496 this.data.titleObj = this._title;
51497 this.setContents(parent.get("Contents"));
51498 this.data.contentsObj = this._contents;
51499 if (!parent.has("CreationDate")) {
51500 this.data.creationDate = null;
51501 } else {
51502 this.setCreationDate(parent.get("CreationDate"));
51503 this.data.creationDate = this.creationDate;
51504 }
51505 if (!parent.has("M")) {
51506 this.data.modificationDate = null;
51507 } else {
51508 this.setModificationDate(parent.get("M"));
51509 this.data.modificationDate = this.modificationDate;
51510 }
51511 popupRef = parent.getRaw("Popup");
51512 if (!parent.has("C")) {
51513 this.data.color = null;
51514 } else {
51515 this.setColor(parent.getArray("C"));
51516 this.data.color = this.color;
51517 }
51518 } else {
51519 this.data.titleObj = this._title;
51520 this.setCreationDate(dict.get("CreationDate"));
51521 this.data.creationDate = this.creationDate;
51522 popupRef = dict.getRaw("Popup");
51523 if (!dict.has("C")) {
51524 this.data.color = null;
51525 }
51526 }
51527 this.data.popupRef = popupRef instanceof Ref ? popupRef.toString() : null;
51528 if (dict.has("RC")) {
51529 this.data.richText = XFAFactory.getRichTextAsHtml(dict.get("RC"));
51530 }
51531 }
51532 setCreationDate(creationDate) {
51533 this.creationDate = typeof creationDate === "string" ? creationDate : null;
51534 }
51535 _setDefaultAppearance({
51536 xref,
51537 extra,
51538 strokeColor,
51539 fillColor,
51540 blendMode,
51541 strokeAlpha,
51542 fillAlpha,
51543 pointsCallback
51544 }) {
51545 let minX = Number.MAX_VALUE;
51546 let minY = Number.MAX_VALUE;
51547 let maxX = Number.MIN_VALUE;
51548 let maxY = Number.MIN_VALUE;
51549 const buffer = ["q"];
51550 if (extra) {
51551 buffer.push(extra);
51552 }
51553 if (strokeColor) {
51554 buffer.push(`${strokeColor[0]} ${strokeColor[1]} ${strokeColor[2]} RG`);
51555 }
51556 if (fillColor) {
51557 buffer.push(`${fillColor[0]} ${fillColor[1]} ${fillColor[2]} rg`);
51558 }
51559 let pointsArray = this.data.quadPoints;
51560 if (!pointsArray) {
51561 pointsArray = [[{
51562 x: this.rectangle[0],
51563 y: this.rectangle[3]
51564 }, {
51565 x: this.rectangle[2],
51566 y: this.rectangle[3]
51567 }, {
51568 x: this.rectangle[0],
51569 y: this.rectangle[1]
51570 }, {
51571 x: this.rectangle[2],
51572 y: this.rectangle[1]
51573 }]];
51574 }
51575 for (const points of pointsArray) {
51576 const [mX, MX, mY, MY] = pointsCallback(buffer, points);
51577 minX = Math.min(minX, mX);
51578 maxX = Math.max(maxX, MX);
51579 minY = Math.min(minY, mY);
51580 maxY = Math.max(maxY, MY);
51581 }
51582 buffer.push("Q");
51583 const formDict = new Dict(xref);
51584 const appearanceStreamDict = new Dict(xref);
51585 appearanceStreamDict.set("Subtype", Name.get("Form"));
51586 const appearanceStream = new StringStream(buffer.join(" "));
51587 appearanceStream.dict = appearanceStreamDict;
51588 formDict.set("Fm0", appearanceStream);
51589 const gsDict = new Dict(xref);
51590 if (blendMode) {
51591 gsDict.set("BM", Name.get(blendMode));
51592 }
51593 if (typeof strokeAlpha === "number") {
51594 gsDict.set("CA", strokeAlpha);
51595 }
51596 if (typeof fillAlpha === "number") {
51597 gsDict.set("ca", fillAlpha);
51598 }
51599 const stateDict = new Dict(xref);
51600 stateDict.set("GS0", gsDict);
51601 const resources = new Dict(xref);
51602 resources.set("ExtGState", stateDict);
51603 resources.set("XObject", formDict);
51604 const appearanceDict = new Dict(xref);
51605 appearanceDict.set("Resources", resources);
51606 const bbox = this.data.rect = [minX, minY, maxX, maxY];
51607 appearanceDict.set("BBox", bbox);
51608 this.appearance = new StringStream("/GS0 gs /Fm0 Do");
51609 this.appearance.dict = appearanceDict;
51610 this._streams.push(this.appearance, appearanceStream);
51611 }
51612 static async createNewAnnotation(xref, annotation, dependencies, params) {
51613 const annotationRef = annotation.ref ||= xref.getNewTemporaryRef();
51614 const ap = await this.createNewAppearanceStream(annotation, xref, params);
51615 const buffer = [];
51616 let annotationDict;
51617 if (ap) {
51618 const apRef = xref.getNewTemporaryRef();
51619 annotationDict = this.createNewDict(annotation, xref, {
51620 apRef
51621 });
51622 await writeObject(apRef, ap, buffer, xref);
51623 dependencies.push({
51624 ref: apRef,
51625 data: buffer.join("")
51626 });
51627 } else {
51628 annotationDict = this.createNewDict(annotation, xref, {});
51629 }
51630 if (Number.isInteger(annotation.parentTreeId)) {
51631 annotationDict.set("StructParent", annotation.parentTreeId);
51632 }
51633 buffer.length = 0;
51634 await writeObject(annotationRef, annotationDict, buffer, xref);
51635 return {
51636 ref: annotationRef,
51637 data: buffer.join("")
51638 };
51639 }
51640 static async createNewPrintAnnotation(annotationGlobals, xref, annotation, params) {
51641 const ap = await this.createNewAppearanceStream(annotation, xref, params);
51642 const annotationDict = this.createNewDict(annotation, xref, {
51643 ap
51644 });
51645 const newAnnotation = new this.prototype.constructor({
51646 dict: annotationDict,
51647 xref,
51648 annotationGlobals,
51649 evaluatorOptions: params.evaluatorOptions
51650 });
51651 if (annotation.ref) {
51652 newAnnotation.ref = newAnnotation.refToReplace = annotation.ref;
51653 }
51654 return newAnnotation;
51655 }
51656}
51657class WidgetAnnotation extends Annotation {
51658 constructor(params) {
51659 super(params);
51660 const {
51661 dict,
51662 xref,
51663 annotationGlobals
51664 } = params;
51665 const data = this.data;
51666 this._needAppearances = params.needAppearances;
51667 data.annotationType = AnnotationType.WIDGET;
51668 if (data.fieldName === undefined) {
51669 data.fieldName = this._constructFieldName(dict);
51670 }
51671 if (data.actions === undefined) {
51672 data.actions = collectActions(xref, dict, AnnotationActionEventType);
51673 }
51674 let fieldValue = getInheritableProperty({
51675 dict,
51676 key: "V",
51677 getArray: true
51678 });
51679 data.fieldValue = this._decodeFormValue(fieldValue);
51680 const defaultFieldValue = getInheritableProperty({
51681 dict,
51682 key: "DV",
51683 getArray: true
51684 });
51685 data.defaultFieldValue = this._decodeFormValue(defaultFieldValue);
51686 if (fieldValue === undefined && annotationGlobals.xfaDatasets) {
51687 const path = this._title.str;
51688 if (path) {
51689 this._hasValueFromXFA = true;
51690 data.fieldValue = fieldValue = annotationGlobals.xfaDatasets.getValue(path);
51691 }
51692 }
51693 if (fieldValue === undefined && data.defaultFieldValue !== null) {
51694 data.fieldValue = data.defaultFieldValue;
51695 }
51696 data.alternativeText = stringToPDFString(dict.get("TU") || "");
51697 this.setDefaultAppearance(params);
51698 data.hasAppearance ||= this._needAppearances && data.fieldValue !== undefined && data.fieldValue !== null;
51699 const fieldType = getInheritableProperty({
51700 dict,
51701 key: "FT"
51702 });
51703 data.fieldType = fieldType instanceof Name ? fieldType.name : null;
51704 const localResources = getInheritableProperty({
51705 dict,
51706 key: "DR"
51707 });
51708 const acroFormResources = annotationGlobals.acroForm.get("DR");
51709 const appearanceResources = this.appearance?.dict.get("Resources");
51710 this._fieldResources = {
51711 localResources,
51712 acroFormResources,
51713 appearanceResources,
51714 mergedResources: Dict.merge({
51715 xref,
51716 dictArray: [localResources, appearanceResources, acroFormResources],
51717 mergeSubDicts: true
51718 })
51719 };
51720 data.fieldFlags = getInheritableProperty({
51721 dict,
51722 key: "Ff"
51723 });
51724 if (!Number.isInteger(data.fieldFlags) || data.fieldFlags < 0) {
51725 data.fieldFlags = 0;
51726 }
51727 data.readOnly = this.hasFieldFlag(AnnotationFieldFlag.READONLY);
51728 data.required = this.hasFieldFlag(AnnotationFieldFlag.REQUIRED);
51729 data.hidden = this._hasFlag(data.annotationFlags, AnnotationFlag.HIDDEN) || this._hasFlag(data.annotationFlags, AnnotationFlag.NOVIEW);
51730 }
51731 _decodeFormValue(formValue) {
51732 if (Array.isArray(formValue)) {
51733 return formValue.filter(item => typeof item === "string").map(item => stringToPDFString(item));
51734 } else if (formValue instanceof Name) {
51735 return stringToPDFString(formValue.name);
51736 } else if (typeof formValue === "string") {
51737 return stringToPDFString(formValue);
51738 }
51739 return null;
51740 }
51741 hasFieldFlag(flag) {
51742 return !!(this.data.fieldFlags & flag);
51743 }
51744 _isViewable(flags) {
51745 return true;
51746 }
51747 mustBeViewed(annotationStorage, renderForms) {
51748 if (renderForms) {
51749 return this.viewable;
51750 }
51751 return super.mustBeViewed(annotationStorage, renderForms) && !this._hasFlag(this.flags, AnnotationFlag.NOVIEW);
51752 }
51753 getRotationMatrix(annotationStorage) {
51754 let rotation = annotationStorage?.get(this.data.id)?.rotation;
51755 if (rotation === undefined) {
51756 rotation = this.rotation;
51757 }
51758 if (rotation === 0) {
51759 return IDENTITY_MATRIX;
51760 }
51761 const width = this.data.rect[2] - this.data.rect[0];
51762 const height = this.data.rect[3] - this.data.rect[1];
51763 return getRotationMatrix(rotation, width, height);
51764 }
51765 getBorderAndBackgroundAppearances(annotationStorage) {
51766 let rotation = annotationStorage?.get(this.data.id)?.rotation;
51767 if (rotation === undefined) {
51768 rotation = this.rotation;
51769 }
51770 if (!this.backgroundColor && !this.borderColor) {
51771 return "";
51772 }
51773 const width = this.data.rect[2] - this.data.rect[0];
51774 const height = this.data.rect[3] - this.data.rect[1];
51775 const rect = rotation === 0 || rotation === 180 ? `0 0 ${width} ${height} re` : `0 0 ${height} ${width} re`;
51776 let str = "";
51777 if (this.backgroundColor) {
51778 str = `${getPdfColor(this.backgroundColor, true)} ${rect} f `;
51779 }
51780 if (this.borderColor) {
51781 const borderWidth = this.borderStyle.width || 1;
51782 str += `${borderWidth} w ${getPdfColor(this.borderColor, false)} ${rect} S `;
51783 }
51784 return str;
51785 }
51786 async getOperatorList(evaluator, task, intent, renderForms, annotationStorage) {
51787 if (renderForms && !(this instanceof SignatureWidgetAnnotation) && !this.data.noHTML && !this.data.hasOwnCanvas) {
51788 return {
51789 opList: new OperatorList(),
51790 separateForm: true,
51791 separateCanvas: false
51792 };
51793 }
51794 if (!this._hasText) {
51795 return super.getOperatorList(evaluator, task, intent, renderForms, annotationStorage);
51796 }
51797 const content = await this._getAppearance(evaluator, task, intent, annotationStorage);
51798 if (this.appearance && content === null) {
51799 return super.getOperatorList(evaluator, task, intent, renderForms, annotationStorage);
51800 }
51801 const opList = new OperatorList();
51802 if (!this._defaultAppearance || content === null) {
51803 return {
51804 opList,
51805 separateForm: false,
51806 separateCanvas: false
51807 };
51808 }
51809 const isUsingOwnCanvas = !!(this.data.hasOwnCanvas && intent & RenderingIntentFlag.DISPLAY);
51810 const matrix = [1, 0, 0, 1, 0, 0];
51811 const bbox = [0, 0, this.data.rect[2] - this.data.rect[0], this.data.rect[3] - this.data.rect[1]];
51812 const transform = getTransformMatrix(this.data.rect, bbox, matrix);
51813 let optionalContent;
51814 if (this.oc) {
51815 optionalContent = await evaluator.parseMarkedContentProps(this.oc, null);
51816 }
51817 if (optionalContent !== undefined) {
51818 opList.addOp(OPS.beginMarkedContentProps, ["OC", optionalContent]);
51819 }
51820 opList.addOp(OPS.beginAnnotation, [this.data.id, this.data.rect, transform, this.getRotationMatrix(annotationStorage), isUsingOwnCanvas]);
51821 const stream = new StringStream(content);
51822 await evaluator.getOperatorList({
51823 stream,
51824 task,
51825 resources: this._fieldResources.mergedResources,
51826 operatorList: opList
51827 });
51828 opList.addOp(OPS.endAnnotation, []);
51829 if (optionalContent !== undefined) {
51830 opList.addOp(OPS.endMarkedContent, []);
51831 }
51832 return {
51833 opList,
51834 separateForm: false,
51835 separateCanvas: isUsingOwnCanvas
51836 };
51837 }
51838 _getMKDict(rotation) {
51839 const mk = new Dict(null);
51840 if (rotation) {
51841 mk.set("R", rotation);
51842 }
51843 if (this.borderColor) {
51844 mk.set("BC", getPdfColorArray(this.borderColor));
51845 }
51846 if (this.backgroundColor) {
51847 mk.set("BG", getPdfColorArray(this.backgroundColor));
51848 }
51849 return mk.size > 0 ? mk : null;
51850 }
51851 amendSavedDict(annotationStorage, dict) {}
51852 async save(evaluator, task, annotationStorage) {
51853 const storageEntry = annotationStorage?.get(this.data.id);
51854 let value = storageEntry?.value,
51855 rotation = storageEntry?.rotation;
51856 if (value === this.data.fieldValue || value === undefined) {
51857 if (!this._hasValueFromXFA && rotation === undefined) {
51858 return null;
51859 }
51860 value ||= this.data.fieldValue;
51861 }
51862 if (rotation === undefined && !this._hasValueFromXFA && Array.isArray(value) && Array.isArray(this.data.fieldValue) && value.length === this.data.fieldValue.length && value.every((x, i) => x === this.data.fieldValue[i])) {
51863 return null;
51864 }
51865 if (rotation === undefined) {
51866 rotation = this.rotation;
51867 }
51868 let appearance = null;
51869 if (!this._needAppearances) {
51870 appearance = await this._getAppearance(evaluator, task, RenderingIntentFlag.SAVE, annotationStorage);
51871 if (appearance === null) {
51872 return null;
51873 }
51874 } else {}
51875 let needAppearances = false;
51876 if (appearance?.needAppearances) {
51877 needAppearances = true;
51878 appearance = null;
51879 }
51880 const {
51881 xref
51882 } = evaluator;
51883 const originalDict = xref.fetchIfRef(this.ref);
51884 if (!(originalDict instanceof Dict)) {
51885 return null;
51886 }
51887 const dict = new Dict(xref);
51888 for (const key of originalDict.getKeys()) {
51889 if (key !== "AP") {
51890 dict.set(key, originalDict.getRaw(key));
51891 }
51892 }
51893 const xfa = {
51894 path: this.data.fieldName,
51895 value
51896 };
51897 const encoder = val => isAscii(val) ? val : stringToUTF16String(val, true);
51898 dict.set("V", Array.isArray(value) ? value.map(encoder) : encoder(value));
51899 this.amendSavedDict(annotationStorage, dict);
51900 const maybeMK = this._getMKDict(rotation);
51901 if (maybeMK) {
51902 dict.set("MK", maybeMK);
51903 }
51904 const buffer = [];
51905 const changes = [{
51906 ref: this.ref,
51907 data: "",
51908 xfa,
51909 needAppearances
51910 }];
51911 if (appearance !== null) {
51912 const newRef = xref.getNewTemporaryRef();
51913 const AP = new Dict(xref);
51914 dict.set("AP", AP);
51915 AP.set("N", newRef);
51916 const resources = this._getSaveFieldResources(xref);
51917 const appearanceStream = new StringStream(appearance);
51918 const appearanceDict = appearanceStream.dict = new Dict(xref);
51919 appearanceDict.set("Subtype", Name.get("Form"));
51920 appearanceDict.set("Resources", resources);
51921 appearanceDict.set("BBox", [0, 0, this.data.rect[2] - this.data.rect[0], this.data.rect[3] - this.data.rect[1]]);
51922 const rotationMatrix = this.getRotationMatrix(annotationStorage);
51923 if (rotationMatrix !== IDENTITY_MATRIX) {
51924 appearanceDict.set("Matrix", rotationMatrix);
51925 }
51926 await writeObject(newRef, appearanceStream, buffer, xref);
51927 changes.push({
51928 ref: newRef,
51929 data: buffer.join(""),
51930 xfa: null,
51931 needAppearances: false
51932 });
51933 buffer.length = 0;
51934 }
51935 dict.set("M", `D:${getModificationDate()}`);
51936 await writeObject(this.ref, dict, buffer, xref);
51937 changes[0].data = buffer.join("");
51938 return changes;
51939 }
51940 async _getAppearance(evaluator, task, intent, annotationStorage) {
51941 const isPassword = this.hasFieldFlag(AnnotationFieldFlag.PASSWORD);
51942 if (isPassword) {
51943 return null;
51944 }
51945 const storageEntry = annotationStorage?.get(this.data.id);
51946 let value, rotation;
51947 if (storageEntry) {
51948 value = storageEntry.formattedValue || storageEntry.value;
51949 rotation = storageEntry.rotation;
51950 }
51951 if (rotation === undefined && value === undefined && !this._needAppearances) {
51952 if (!this._hasValueFromXFA || this.appearance) {
51953 return null;
51954 }
51955 }
51956 const colors = this.getBorderAndBackgroundAppearances(annotationStorage);
51957 if (value === undefined) {
51958 value = this.data.fieldValue;
51959 if (!value) {
51960 return `/Tx BMC q ${colors}Q EMC`;
51961 }
51962 }
51963 if (Array.isArray(value) && value.length === 1) {
51964 value = value[0];
51965 }
51966 assert(typeof value === "string", "Expected `value` to be a string.");
51967 value = value.trim();
51968 if (this.data.combo) {
51969 const option = this.data.options.find(({
51970 exportValue
51971 }) => value === exportValue);
51972 value = option?.displayValue || value;
51973 }
51974 if (value === "") {
51975 return `/Tx BMC q ${colors}Q EMC`;
51976 }
51977 if (rotation === undefined) {
51978 rotation = this.rotation;
51979 }
51980 let lineCount = -1;
51981 let lines;
51982 if (this.data.multiLine) {
51983 lines = value.split(/\r\n?|\n/).map(line => line.normalize("NFC"));
51984 lineCount = lines.length;
51985 } else {
51986 lines = [value.replace(/\r\n?|\n/, "").normalize("NFC")];
51987 }
51988 const defaultPadding = 1;
51989 const defaultHPadding = 2;
51990 let totalHeight = this.data.rect[3] - this.data.rect[1];
51991 let totalWidth = this.data.rect[2] - this.data.rect[0];
51992 if (rotation === 90 || rotation === 270) {
51993 [totalWidth, totalHeight] = [totalHeight, totalWidth];
51994 }
51995 if (!this._defaultAppearance) {
51996 this.data.defaultAppearanceData = parseDefaultAppearance(this._defaultAppearance = "/Helvetica 0 Tf 0 g");
51997 }
51998 let font = await WidgetAnnotation._getFontData(evaluator, task, this.data.defaultAppearanceData, this._fieldResources.mergedResources);
51999 let defaultAppearance, fontSize, lineHeight;
52000 const encodedLines = [];
52001 let encodingError = false;
52002 for (const line of lines) {
52003 const encodedString = font.encodeString(line);
52004 if (encodedString.length > 1) {
52005 encodingError = true;
52006 }
52007 encodedLines.push(encodedString.join(""));
52008 }
52009 if (encodingError && intent & RenderingIntentFlag.SAVE) {
52010 return {
52011 needAppearances: true
52012 };
52013 }
52014 if (encodingError && this._isOffscreenCanvasSupported) {
52015 const fontFamily = this.data.comb ? "monospace" : "sans-serif";
52016 const fakeUnicodeFont = new FakeUnicodeFont(evaluator.xref, fontFamily);
52017 const resources = fakeUnicodeFont.createFontResources(lines.join(""));
52018 const newFont = resources.getRaw("Font");
52019 if (this._fieldResources.mergedResources.has("Font")) {
52020 const oldFont = this._fieldResources.mergedResources.get("Font");
52021 for (const key of newFont.getKeys()) {
52022 oldFont.set(key, newFont.getRaw(key));
52023 }
52024 } else {
52025 this._fieldResources.mergedResources.set("Font", newFont);
52026 }
52027 const fontName = fakeUnicodeFont.fontName.name;
52028 font = await WidgetAnnotation._getFontData(evaluator, task, {
52029 fontName,
52030 fontSize: 0
52031 }, resources);
52032 for (let i = 0, ii = encodedLines.length; i < ii; i++) {
52033 encodedLines[i] = stringToUTF16String(lines[i]);
52034 }
52035 const savedDefaultAppearance = Object.assign(Object.create(null), this.data.defaultAppearanceData);
52036 this.data.defaultAppearanceData.fontSize = 0;
52037 this.data.defaultAppearanceData.fontName = fontName;
52038 [defaultAppearance, fontSize, lineHeight] = this._computeFontSize(totalHeight - 2 * defaultPadding, totalWidth - 2 * defaultHPadding, value, font, lineCount);
52039 this.data.defaultAppearanceData = savedDefaultAppearance;
52040 } else {
52041 if (!this._isOffscreenCanvasSupported) {
52042 warn("_getAppearance: OffscreenCanvas is not supported, annotation may not render correctly.");
52043 }
52044 [defaultAppearance, fontSize, lineHeight] = this._computeFontSize(totalHeight - 2 * defaultPadding, totalWidth - 2 * defaultHPadding, value, font, lineCount);
52045 }
52046 let descent = font.descent;
52047 if (isNaN(descent)) {
52048 descent = BASELINE_FACTOR * lineHeight;
52049 } else {
52050 descent = Math.max(BASELINE_FACTOR * lineHeight, Math.abs(descent) * fontSize);
52051 }
52052 const defaultVPadding = Math.min(Math.floor((totalHeight - fontSize) / 2), defaultPadding);
52053 const alignment = this.data.textAlignment;
52054 if (this.data.multiLine) {
52055 return this._getMultilineAppearance(defaultAppearance, encodedLines, font, fontSize, totalWidth, totalHeight, alignment, defaultHPadding, defaultVPadding, descent, lineHeight, annotationStorage);
52056 }
52057 if (this.data.comb) {
52058 return this._getCombAppearance(defaultAppearance, font, encodedLines[0], fontSize, totalWidth, totalHeight, defaultHPadding, defaultVPadding, descent, lineHeight, annotationStorage);
52059 }
52060 const bottomPadding = defaultVPadding + descent;
52061 if (alignment === 0 || alignment > 2) {
52062 return `/Tx BMC q ${colors}BT ` + defaultAppearance + ` 1 0 0 1 ${numberToString(defaultHPadding)} ${numberToString(bottomPadding)} Tm (${escapeString(encodedLines[0])}) Tj` + " ET Q EMC";
52063 }
52064 const prevInfo = {
52065 shift: 0
52066 };
52067 const renderedText = this._renderText(encodedLines[0], font, fontSize, totalWidth, alignment, prevInfo, defaultHPadding, bottomPadding);
52068 return `/Tx BMC q ${colors}BT ` + defaultAppearance + ` 1 0 0 1 0 0 Tm ${renderedText}` + " ET Q EMC";
52069 }
52070 static async _getFontData(evaluator, task, appearanceData, resources) {
52071 const operatorList = new OperatorList();
52072 const initialState = {
52073 font: null,
52074 clone() {
52075 return this;
52076 }
52077 };
52078 const {
52079 fontName,
52080 fontSize
52081 } = appearanceData;
52082 await evaluator.handleSetFont(resources, [fontName && Name.get(fontName), fontSize], null, operatorList, task, initialState, null);
52083 return initialState.font;
52084 }
52085 _getTextWidth(text, font) {
52086 return font.charsToGlyphs(text).reduce((width, glyph) => width + glyph.width, 0) / 1000;
52087 }
52088 _computeFontSize(height, width, text, font, lineCount) {
52089 let {
52090 fontSize
52091 } = this.data.defaultAppearanceData;
52092 let lineHeight = (fontSize || 12) * LINE_FACTOR,
52093 numberOfLines = Math.round(height / lineHeight);
52094 if (!fontSize) {
52095 const roundWithTwoDigits = x => Math.floor(x * 100) / 100;
52096 if (lineCount === -1) {
52097 const textWidth = this._getTextWidth(text, font);
52098 fontSize = roundWithTwoDigits(Math.min(height / LINE_FACTOR, textWidth > width ? width / textWidth : Infinity));
52099 numberOfLines = 1;
52100 } else {
52101 const lines = text.split(/\r\n?|\n/);
52102 const cachedLines = [];
52103 for (const line of lines) {
52104 const encoded = font.encodeString(line).join("");
52105 const glyphs = font.charsToGlyphs(encoded);
52106 const positions = font.getCharPositions(encoded);
52107 cachedLines.push({
52108 line: encoded,
52109 glyphs,
52110 positions
52111 });
52112 }
52113 const isTooBig = fsize => {
52114 let totalHeight = 0;
52115 for (const cache of cachedLines) {
52116 const chunks = this._splitLine(null, font, fsize, width, cache);
52117 totalHeight += chunks.length * fsize;
52118 if (totalHeight > height) {
52119 return true;
52120 }
52121 }
52122 return false;
52123 };
52124 numberOfLines = Math.max(numberOfLines, lineCount);
52125 while (true) {
52126 lineHeight = height / numberOfLines;
52127 fontSize = roundWithTwoDigits(lineHeight / LINE_FACTOR);
52128 if (isTooBig(fontSize)) {
52129 numberOfLines++;
52130 continue;
52131 }
52132 break;
52133 }
52134 }
52135 const {
52136 fontName,
52137 fontColor
52138 } = this.data.defaultAppearanceData;
52139 this._defaultAppearance = createDefaultAppearance({
52140 fontSize,
52141 fontName,
52142 fontColor
52143 });
52144 }
52145 return [this._defaultAppearance, fontSize, height / numberOfLines];
52146 }
52147 _renderText(text, font, fontSize, totalWidth, alignment, prevInfo, hPadding, vPadding) {
52148 let shift;
52149 if (alignment === 1) {
52150 const width = this._getTextWidth(text, font) * fontSize;
52151 shift = (totalWidth - width) / 2;
52152 } else if (alignment === 2) {
52153 const width = this._getTextWidth(text, font) * fontSize;
52154 shift = totalWidth - width - hPadding;
52155 } else {
52156 shift = hPadding;
52157 }
52158 const shiftStr = numberToString(shift - prevInfo.shift);
52159 prevInfo.shift = shift;
52160 vPadding = numberToString(vPadding);
52161 return `${shiftStr} ${vPadding} Td (${escapeString(text)}) Tj`;
52162 }
52163 _getSaveFieldResources(xref) {
52164 const {
52165 localResources,
52166 appearanceResources,
52167 acroFormResources
52168 } = this._fieldResources;
52169 const fontName = this.data.defaultAppearanceData?.fontName;
52170 if (!fontName) {
52171 return localResources || Dict.empty;
52172 }
52173 for (const resources of [localResources, appearanceResources]) {
52174 if (resources instanceof Dict) {
52175 const localFont = resources.get("Font");
52176 if (localFont instanceof Dict && localFont.has(fontName)) {
52177 return resources;
52178 }
52179 }
52180 }
52181 if (acroFormResources instanceof Dict) {
52182 const acroFormFont = acroFormResources.get("Font");
52183 if (acroFormFont instanceof Dict && acroFormFont.has(fontName)) {
52184 const subFontDict = new Dict(xref);
52185 subFontDict.set(fontName, acroFormFont.getRaw(fontName));
52186 const subResourcesDict = new Dict(xref);
52187 subResourcesDict.set("Font", subFontDict);
52188 return Dict.merge({
52189 xref,
52190 dictArray: [subResourcesDict, localResources],
52191 mergeSubDicts: true
52192 });
52193 }
52194 }
52195 return localResources || Dict.empty;
52196 }
52197 getFieldObject() {
52198 return null;
52199 }
52200}
52201class TextWidgetAnnotation extends WidgetAnnotation {
52202 constructor(params) {
52203 super(params);
52204 this.data.hasOwnCanvas = this.data.readOnly && !this.data.noHTML;
52205 this._hasText = true;
52206 const dict = params.dict;
52207 if (typeof this.data.fieldValue !== "string") {
52208 this.data.fieldValue = "";
52209 }
52210 let alignment = getInheritableProperty({
52211 dict,
52212 key: "Q"
52213 });
52214 if (!Number.isInteger(alignment) || alignment < 0 || alignment > 2) {
52215 alignment = null;
52216 }
52217 this.data.textAlignment = alignment;
52218 let maximumLength = getInheritableProperty({
52219 dict,
52220 key: "MaxLen"
52221 });
52222 if (!Number.isInteger(maximumLength) || maximumLength < 0) {
52223 maximumLength = 0;
52224 }
52225 this.data.maxLen = maximumLength;
52226 this.data.multiLine = this.hasFieldFlag(AnnotationFieldFlag.MULTILINE);
52227 this.data.comb = this.hasFieldFlag(AnnotationFieldFlag.COMB) && !this.hasFieldFlag(AnnotationFieldFlag.MULTILINE) && !this.hasFieldFlag(AnnotationFieldFlag.PASSWORD) && !this.hasFieldFlag(AnnotationFieldFlag.FILESELECT) && this.data.maxLen !== 0;
52228 this.data.doNotScroll = this.hasFieldFlag(AnnotationFieldFlag.DONOTSCROLL);
52229 }
52230 get hasTextContent() {
52231 return !!this.appearance && !this._needAppearances;
52232 }
52233 _getCombAppearance(defaultAppearance, font, text, fontSize, width, height, hPadding, vPadding, descent, lineHeight, annotationStorage) {
52234 const combWidth = width / this.data.maxLen;
52235 const colors = this.getBorderAndBackgroundAppearances(annotationStorage);
52236 const buf = [];
52237 const positions = font.getCharPositions(text);
52238 for (const [start, end] of positions) {
52239 buf.push(`(${escapeString(text.substring(start, end))}) Tj`);
52240 }
52241 const renderedComb = buf.join(` ${numberToString(combWidth)} 0 Td `);
52242 return `/Tx BMC q ${colors}BT ` + defaultAppearance + ` 1 0 0 1 ${numberToString(hPadding)} ${numberToString(vPadding + descent)} Tm ${renderedComb}` + " ET Q EMC";
52243 }
52244 _getMultilineAppearance(defaultAppearance, lines, font, fontSize, width, height, alignment, hPadding, vPadding, descent, lineHeight, annotationStorage) {
52245 const buf = [];
52246 const totalWidth = width - 2 * hPadding;
52247 const prevInfo = {
52248 shift: 0
52249 };
52250 for (let i = 0, ii = lines.length; i < ii; i++) {
52251 const line = lines[i];
52252 const chunks = this._splitLine(line, font, fontSize, totalWidth);
52253 for (let j = 0, jj = chunks.length; j < jj; j++) {
52254 const chunk = chunks[j];
52255 const vShift = i === 0 && j === 0 ? -vPadding - (lineHeight - descent) : -lineHeight;
52256 buf.push(this._renderText(chunk, font, fontSize, width, alignment, prevInfo, hPadding, vShift));
52257 }
52258 }
52259 const colors = this.getBorderAndBackgroundAppearances(annotationStorage);
52260 const renderedText = buf.join("\n");
52261 return `/Tx BMC q ${colors}BT ` + defaultAppearance + ` 1 0 0 1 0 ${numberToString(height)} Tm ${renderedText}` + " ET Q EMC";
52262 }
52263 _splitLine(line, font, fontSize, width, cache = {}) {
52264 line = cache.line || line;
52265 const glyphs = cache.glyphs || font.charsToGlyphs(line);
52266 if (glyphs.length <= 1) {
52267 return [line];
52268 }
52269 const positions = cache.positions || font.getCharPositions(line);
52270 const scale = fontSize / 1000;
52271 const chunks = [];
52272 let lastSpacePosInStringStart = -1,
52273 lastSpacePosInStringEnd = -1,
52274 lastSpacePos = -1,
52275 startChunk = 0,
52276 currentWidth = 0;
52277 for (let i = 0, ii = glyphs.length; i < ii; i++) {
52278 const [start, end] = positions[i];
52279 const glyph = glyphs[i];
52280 const glyphWidth = glyph.width * scale;
52281 if (glyph.unicode === " ") {
52282 if (currentWidth + glyphWidth > width) {
52283 chunks.push(line.substring(startChunk, start));
52284 startChunk = start;
52285 currentWidth = glyphWidth;
52286 lastSpacePosInStringStart = -1;
52287 lastSpacePos = -1;
52288 } else {
52289 currentWidth += glyphWidth;
52290 lastSpacePosInStringStart = start;
52291 lastSpacePosInStringEnd = end;
52292 lastSpacePos = i;
52293 }
52294 } else if (currentWidth + glyphWidth > width) {
52295 if (lastSpacePosInStringStart !== -1) {
52296 chunks.push(line.substring(startChunk, lastSpacePosInStringEnd));
52297 startChunk = lastSpacePosInStringEnd;
52298 i = lastSpacePos + 1;
52299 lastSpacePosInStringStart = -1;
52300 currentWidth = 0;
52301 } else {
52302 chunks.push(line.substring(startChunk, start));
52303 startChunk = start;
52304 currentWidth = glyphWidth;
52305 }
52306 } else {
52307 currentWidth += glyphWidth;
52308 }
52309 }
52310 if (startChunk < line.length) {
52311 chunks.push(line.substring(startChunk, line.length));
52312 }
52313 return chunks;
52314 }
52315 getFieldObject() {
52316 return {
52317 id: this.data.id,
52318 value: this.data.fieldValue,
52319 defaultValue: this.data.defaultFieldValue || "",
52320 multiline: this.data.multiLine,
52321 password: this.hasFieldFlag(AnnotationFieldFlag.PASSWORD),
52322 charLimit: this.data.maxLen,
52323 comb: this.data.comb,
52324 editable: !this.data.readOnly,
52325 hidden: this.data.hidden,
52326 name: this.data.fieldName,
52327 rect: this.data.rect,
52328 actions: this.data.actions,
52329 page: this.data.pageIndex,
52330 strokeColor: this.data.borderColor,
52331 fillColor: this.data.backgroundColor,
52332 rotation: this.rotation,
52333 type: "text"
52334 };
52335 }
52336}
52337class ButtonWidgetAnnotation extends WidgetAnnotation {
52338 constructor(params) {
52339 super(params);
52340 this.checkedAppearance = null;
52341 this.uncheckedAppearance = null;
52342 this.data.checkBox = !this.hasFieldFlag(AnnotationFieldFlag.RADIO) && !this.hasFieldFlag(AnnotationFieldFlag.PUSHBUTTON);
52343 this.data.radioButton = this.hasFieldFlag(AnnotationFieldFlag.RADIO) && !this.hasFieldFlag(AnnotationFieldFlag.PUSHBUTTON);
52344 this.data.pushButton = this.hasFieldFlag(AnnotationFieldFlag.PUSHBUTTON);
52345 this.data.isTooltipOnly = false;
52346 if (this.data.checkBox) {
52347 this._processCheckBox(params);
52348 } else if (this.data.radioButton) {
52349 this._processRadioButton(params);
52350 } else if (this.data.pushButton) {
52351 this.data.hasOwnCanvas = true;
52352 this.data.noHTML = false;
52353 this._processPushButton(params);
52354 } else {
52355 warn("Invalid field flags for button widget annotation");
52356 }
52357 }
52358 async getOperatorList(evaluator, task, intent, renderForms, annotationStorage) {
52359 if (this.data.pushButton) {
52360 return super.getOperatorList(evaluator, task, intent, false, annotationStorage);
52361 }
52362 let value = null;
52363 let rotation = null;
52364 if (annotationStorage) {
52365 const storageEntry = annotationStorage.get(this.data.id);
52366 value = storageEntry ? storageEntry.value : null;
52367 rotation = storageEntry ? storageEntry.rotation : null;
52368 }
52369 if (value === null && this.appearance) {
52370 return super.getOperatorList(evaluator, task, intent, renderForms, annotationStorage);
52371 }
52372 if (value === null || value === undefined) {
52373 value = this.data.checkBox ? this.data.fieldValue === this.data.exportValue : this.data.fieldValue === this.data.buttonValue;
52374 }
52375 const appearance = value ? this.checkedAppearance : this.uncheckedAppearance;
52376 if (appearance) {
52377 const savedAppearance = this.appearance;
52378 const savedMatrix = appearance.dict.getArray("Matrix") || IDENTITY_MATRIX;
52379 if (rotation) {
52380 appearance.dict.set("Matrix", this.getRotationMatrix(annotationStorage));
52381 }
52382 this.appearance = appearance;
52383 const operatorList = super.getOperatorList(evaluator, task, intent, renderForms, annotationStorage);
52384 this.appearance = savedAppearance;
52385 appearance.dict.set("Matrix", savedMatrix);
52386 return operatorList;
52387 }
52388 return {
52389 opList: new OperatorList(),
52390 separateForm: false,
52391 separateCanvas: false
52392 };
52393 }
52394 async save(evaluator, task, annotationStorage) {
52395 if (this.data.checkBox) {
52396 return this._saveCheckbox(evaluator, task, annotationStorage);
52397 }
52398 if (this.data.radioButton) {
52399 return this._saveRadioButton(evaluator, task, annotationStorage);
52400 }
52401 return null;
52402 }
52403 async _saveCheckbox(evaluator, task, annotationStorage) {
52404 if (!annotationStorage) {
52405 return null;
52406 }
52407 const storageEntry = annotationStorage.get(this.data.id);
52408 let rotation = storageEntry?.rotation,
52409 value = storageEntry?.value;
52410 if (rotation === undefined) {
52411 if (value === undefined) {
52412 return null;
52413 }
52414 const defaultValue = this.data.fieldValue === this.data.exportValue;
52415 if (defaultValue === value) {
52416 return null;
52417 }
52418 }
52419 const dict = evaluator.xref.fetchIfRef(this.ref);
52420 if (!(dict instanceof Dict)) {
52421 return null;
52422 }
52423 if (rotation === undefined) {
52424 rotation = this.rotation;
52425 }
52426 if (value === undefined) {
52427 value = this.data.fieldValue === this.data.exportValue;
52428 }
52429 const xfa = {
52430 path: this.data.fieldName,
52431 value: value ? this.data.exportValue : ""
52432 };
52433 const name = Name.get(value ? this.data.exportValue : "Off");
52434 dict.set("V", name);
52435 dict.set("AS", name);
52436 dict.set("M", `D:${getModificationDate()}`);
52437 const maybeMK = this._getMKDict(rotation);
52438 if (maybeMK) {
52439 dict.set("MK", maybeMK);
52440 }
52441 const buffer = [];
52442 await writeObject(this.ref, dict, buffer, evaluator.xref);
52443 return [{
52444 ref: this.ref,
52445 data: buffer.join(""),
52446 xfa
52447 }];
52448 }
52449 async _saveRadioButton(evaluator, task, annotationStorage) {
52450 if (!annotationStorage) {
52451 return null;
52452 }
52453 const storageEntry = annotationStorage.get(this.data.id);
52454 let rotation = storageEntry?.rotation,
52455 value = storageEntry?.value;
52456 if (rotation === undefined) {
52457 if (value === undefined) {
52458 return null;
52459 }
52460 const defaultValue = this.data.fieldValue === this.data.buttonValue;
52461 if (defaultValue === value) {
52462 return null;
52463 }
52464 }
52465 const dict = evaluator.xref.fetchIfRef(this.ref);
52466 if (!(dict instanceof Dict)) {
52467 return null;
52468 }
52469 if (value === undefined) {
52470 value = this.data.fieldValue === this.data.buttonValue;
52471 }
52472 if (rotation === undefined) {
52473 rotation = this.rotation;
52474 }
52475 const xfa = {
52476 path: this.data.fieldName,
52477 value: value ? this.data.buttonValue : ""
52478 };
52479 const name = Name.get(value ? this.data.buttonValue : "Off");
52480 const buffer = [];
52481 let parentData = null;
52482 if (value) {
52483 if (this.parent instanceof Ref) {
52484 const parent = evaluator.xref.fetch(this.parent);
52485 parent.set("V", name);
52486 await writeObject(this.parent, parent, buffer, evaluator.xref);
52487 parentData = buffer.join("");
52488 buffer.length = 0;
52489 } else if (this.parent instanceof Dict) {
52490 this.parent.set("V", name);
52491 }
52492 }
52493 dict.set("AS", name);
52494 dict.set("M", `D:${getModificationDate()}`);
52495 const maybeMK = this._getMKDict(rotation);
52496 if (maybeMK) {
52497 dict.set("MK", maybeMK);
52498 }
52499 await writeObject(this.ref, dict, buffer, evaluator.xref);
52500 const newRefs = [{
52501 ref: this.ref,
52502 data: buffer.join(""),
52503 xfa
52504 }];
52505 if (parentData) {
52506 newRefs.push({
52507 ref: this.parent,
52508 data: parentData,
52509 xfa: null
52510 });
52511 }
52512 return newRefs;
52513 }
52514 _getDefaultCheckedAppearance(params, type) {
52515 const width = this.data.rect[2] - this.data.rect[0];
52516 const height = this.data.rect[3] - this.data.rect[1];
52517 const bbox = [0, 0, width, height];
52518 const FONT_RATIO = 0.8;
52519 const fontSize = Math.min(width, height) * FONT_RATIO;
52520 let metrics, char;
52521 if (type === "check") {
52522 metrics = {
52523 width: 0.755 * fontSize,
52524 height: 0.705 * fontSize
52525 };
52526 char = "\x33";
52527 } else if (type === "disc") {
52528 metrics = {
52529 width: 0.791 * fontSize,
52530 height: 0.705 * fontSize
52531 };
52532 char = "\x6C";
52533 } else {
52534 unreachable(`_getDefaultCheckedAppearance - unsupported type: ${type}`);
52535 }
52536 const xShift = numberToString((width - metrics.width) / 2);
52537 const yShift = numberToString((height - metrics.height) / 2);
52538 const appearance = `q BT /PdfJsZaDb ${fontSize} Tf 0 g ${xShift} ${yShift} Td (${char}) Tj ET Q`;
52539 const appearanceStreamDict = new Dict(params.xref);
52540 appearanceStreamDict.set("FormType", 1);
52541 appearanceStreamDict.set("Subtype", Name.get("Form"));
52542 appearanceStreamDict.set("Type", Name.get("XObject"));
52543 appearanceStreamDict.set("BBox", bbox);
52544 appearanceStreamDict.set("Matrix", [1, 0, 0, 1, 0, 0]);
52545 appearanceStreamDict.set("Length", appearance.length);
52546 const resources = new Dict(params.xref);
52547 const font = new Dict(params.xref);
52548 font.set("PdfJsZaDb", this.fallbackFontDict);
52549 resources.set("Font", font);
52550 appearanceStreamDict.set("Resources", resources);
52551 this.checkedAppearance = new StringStream(appearance);
52552 this.checkedAppearance.dict = appearanceStreamDict;
52553 this._streams.push(this.checkedAppearance);
52554 }
52555 _processCheckBox(params) {
52556 const customAppearance = params.dict.get("AP");
52557 if (!(customAppearance instanceof Dict)) {
52558 return;
52559 }
52560 const normalAppearance = customAppearance.get("N");
52561 if (!(normalAppearance instanceof Dict)) {
52562 return;
52563 }
52564 const asValue = this._decodeFormValue(params.dict.get("AS"));
52565 if (typeof asValue === "string") {
52566 this.data.fieldValue = asValue;
52567 }
52568 const yes = this.data.fieldValue !== null && this.data.fieldValue !== "Off" ? this.data.fieldValue : "Yes";
52569 const exportValues = normalAppearance.getKeys();
52570 if (exportValues.length === 0) {
52571 exportValues.push("Off", yes);
52572 } else if (exportValues.length === 1) {
52573 if (exportValues[0] === "Off") {
52574 exportValues.push(yes);
52575 } else {
52576 exportValues.unshift("Off");
52577 }
52578 } else if (exportValues.includes(yes)) {
52579 exportValues.length = 0;
52580 exportValues.push("Off", yes);
52581 } else {
52582 const otherYes = exportValues.find(v => v !== "Off");
52583 exportValues.length = 0;
52584 exportValues.push("Off", otherYes);
52585 }
52586 if (!exportValues.includes(this.data.fieldValue)) {
52587 this.data.fieldValue = "Off";
52588 }
52589 this.data.exportValue = exportValues[1];
52590 const checkedAppearance = normalAppearance.get(this.data.exportValue);
52591 this.checkedAppearance = checkedAppearance instanceof BaseStream ? checkedAppearance : null;
52592 const uncheckedAppearance = normalAppearance.get("Off");
52593 this.uncheckedAppearance = uncheckedAppearance instanceof BaseStream ? uncheckedAppearance : null;
52594 if (this.checkedAppearance) {
52595 this._streams.push(this.checkedAppearance);
52596 } else {
52597 this._getDefaultCheckedAppearance(params, "check");
52598 }
52599 if (this.uncheckedAppearance) {
52600 this._streams.push(this.uncheckedAppearance);
52601 }
52602 this._fallbackFontDict = this.fallbackFontDict;
52603 if (this.data.defaultFieldValue === null) {
52604 this.data.defaultFieldValue = "Off";
52605 }
52606 }
52607 _processRadioButton(params) {
52608 this.data.buttonValue = null;
52609 const fieldParent = params.dict.get("Parent");
52610 if (fieldParent instanceof Dict) {
52611 this.parent = params.dict.getRaw("Parent");
52612 const fieldParentValue = fieldParent.get("V");
52613 if (fieldParentValue instanceof Name) {
52614 this.data.fieldValue = this._decodeFormValue(fieldParentValue);
52615 }
52616 }
52617 const appearanceStates = params.dict.get("AP");
52618 if (!(appearanceStates instanceof Dict)) {
52619 return;
52620 }
52621 const normalAppearance = appearanceStates.get("N");
52622 if (!(normalAppearance instanceof Dict)) {
52623 return;
52624 }
52625 for (const key of normalAppearance.getKeys()) {
52626 if (key !== "Off") {
52627 this.data.buttonValue = this._decodeFormValue(key);
52628 break;
52629 }
52630 }
52631 const checkedAppearance = normalAppearance.get(this.data.buttonValue);
52632 this.checkedAppearance = checkedAppearance instanceof BaseStream ? checkedAppearance : null;
52633 const uncheckedAppearance = normalAppearance.get("Off");
52634 this.uncheckedAppearance = uncheckedAppearance instanceof BaseStream ? uncheckedAppearance : null;
52635 if (this.checkedAppearance) {
52636 this._streams.push(this.checkedAppearance);
52637 } else {
52638 this._getDefaultCheckedAppearance(params, "disc");
52639 }
52640 if (this.uncheckedAppearance) {
52641 this._streams.push(this.uncheckedAppearance);
52642 }
52643 this._fallbackFontDict = this.fallbackFontDict;
52644 if (this.data.defaultFieldValue === null) {
52645 this.data.defaultFieldValue = "Off";
52646 }
52647 }
52648 _processPushButton(params) {
52649 const {
52650 dict,
52651 annotationGlobals
52652 } = params;
52653 if (!dict.has("A") && !dict.has("AA") && !this.data.alternativeText) {
52654 warn("Push buttons without action dictionaries are not supported");
52655 return;
52656 }
52657 this.data.isTooltipOnly = !dict.has("A") && !dict.has("AA");
52658 Catalog.parseDestDictionary({
52659 destDict: dict,
52660 resultObj: this.data,
52661 docBaseUrl: annotationGlobals.baseUrl,
52662 docAttachments: annotationGlobals.attachments
52663 });
52664 }
52665 getFieldObject() {
52666 let type = "button";
52667 let exportValues;
52668 if (this.data.checkBox) {
52669 type = "checkbox";
52670 exportValues = this.data.exportValue;
52671 } else if (this.data.radioButton) {
52672 type = "radiobutton";
52673 exportValues = this.data.buttonValue;
52674 }
52675 return {
52676 id: this.data.id,
52677 value: this.data.fieldValue || "Off",
52678 defaultValue: this.data.defaultFieldValue,
52679 exportValues,
52680 editable: !this.data.readOnly,
52681 name: this.data.fieldName,
52682 rect: this.data.rect,
52683 hidden: this.data.hidden,
52684 actions: this.data.actions,
52685 page: this.data.pageIndex,
52686 strokeColor: this.data.borderColor,
52687 fillColor: this.data.backgroundColor,
52688 rotation: this.rotation,
52689 type
52690 };
52691 }
52692 get fallbackFontDict() {
52693 const dict = new Dict();
52694 dict.set("BaseFont", Name.get("ZapfDingbats"));
52695 dict.set("Type", Name.get("FallbackType"));
52696 dict.set("Subtype", Name.get("FallbackType"));
52697 dict.set("Encoding", Name.get("ZapfDingbatsEncoding"));
52698 return shadow(this, "fallbackFontDict", dict);
52699 }
52700}
52701class ChoiceWidgetAnnotation extends WidgetAnnotation {
52702 constructor(params) {
52703 super(params);
52704 const {
52705 dict,
52706 xref
52707 } = params;
52708 this.indices = dict.getArray("I");
52709 this.hasIndices = Array.isArray(this.indices) && this.indices.length > 0;
52710 this.data.options = [];
52711 const options = getInheritableProperty({
52712 dict,
52713 key: "Opt"
52714 });
52715 if (Array.isArray(options)) {
52716 for (let i = 0, ii = options.length; i < ii; i++) {
52717 const option = xref.fetchIfRef(options[i]);
52718 const isOptionArray = Array.isArray(option);
52719 this.data.options[i] = {
52720 exportValue: this._decodeFormValue(isOptionArray ? xref.fetchIfRef(option[0]) : option),
52721 displayValue: this._decodeFormValue(isOptionArray ? xref.fetchIfRef(option[1]) : option)
52722 };
52723 }
52724 }
52725 if (!this.hasIndices) {
52726 if (typeof this.data.fieldValue === "string") {
52727 this.data.fieldValue = [this.data.fieldValue];
52728 } else if (!this.data.fieldValue) {
52729 this.data.fieldValue = [];
52730 }
52731 } else {
52732 this.data.fieldValue = [];
52733 const ii = this.data.options.length;
52734 for (const i of this.indices) {
52735 if (Number.isInteger(i) && i >= 0 && i < ii) {
52736 this.data.fieldValue.push(this.data.options[i].exportValue);
52737 }
52738 }
52739 }
52740 this.data.combo = this.hasFieldFlag(AnnotationFieldFlag.COMBO);
52741 this.data.multiSelect = this.hasFieldFlag(AnnotationFieldFlag.MULTISELECT);
52742 this._hasText = true;
52743 }
52744 getFieldObject() {
52745 const type = this.data.combo ? "combobox" : "listbox";
52746 const value = this.data.fieldValue.length > 0 ? this.data.fieldValue[0] : null;
52747 return {
52748 id: this.data.id,
52749 value,
52750 defaultValue: this.data.defaultFieldValue,
52751 editable: !this.data.readOnly,
52752 name: this.data.fieldName,
52753 rect: this.data.rect,
52754 numItems: this.data.fieldValue.length,
52755 multipleSelection: this.data.multiSelect,
52756 hidden: this.data.hidden,
52757 actions: this.data.actions,
52758 items: this.data.options,
52759 page: this.data.pageIndex,
52760 strokeColor: this.data.borderColor,
52761 fillColor: this.data.backgroundColor,
52762 rotation: this.rotation,
52763 type
52764 };
52765 }
52766 amendSavedDict(annotationStorage, dict) {
52767 if (!this.hasIndices) {
52768 return;
52769 }
52770 let values = annotationStorage?.get(this.data.id)?.value;
52771 if (!Array.isArray(values)) {
52772 values = [values];
52773 }
52774 const indices = [];
52775 const {
52776 options
52777 } = this.data;
52778 for (let i = 0, j = 0, ii = options.length; i < ii; i++) {
52779 if (options[i].exportValue === values[j]) {
52780 indices.push(i);
52781 j += 1;
52782 }
52783 }
52784 dict.set("I", indices);
52785 }
52786 async _getAppearance(evaluator, task, intent, annotationStorage) {
52787 if (this.data.combo) {
52788 return super._getAppearance(evaluator, task, intent, annotationStorage);
52789 }
52790 let exportedValue, rotation;
52791 const storageEntry = annotationStorage?.get(this.data.id);
52792 if (storageEntry) {
52793 rotation = storageEntry.rotation;
52794 exportedValue = storageEntry.value;
52795 }
52796 if (rotation === undefined && exportedValue === undefined && !this._needAppearances) {
52797 return null;
52798 }
52799 if (exportedValue === undefined) {
52800 exportedValue = this.data.fieldValue;
52801 } else if (!Array.isArray(exportedValue)) {
52802 exportedValue = [exportedValue];
52803 }
52804 const defaultPadding = 1;
52805 const defaultHPadding = 2;
52806 let totalHeight = this.data.rect[3] - this.data.rect[1];
52807 let totalWidth = this.data.rect[2] - this.data.rect[0];
52808 if (rotation === 90 || rotation === 270) {
52809 [totalWidth, totalHeight] = [totalHeight, totalWidth];
52810 }
52811 const lineCount = this.data.options.length;
52812 const valueIndices = [];
52813 for (let i = 0; i < lineCount; i++) {
52814 const {
52815 exportValue
52816 } = this.data.options[i];
52817 if (exportedValue.includes(exportValue)) {
52818 valueIndices.push(i);
52819 }
52820 }
52821 if (!this._defaultAppearance) {
52822 this.data.defaultAppearanceData = parseDefaultAppearance(this._defaultAppearance = "/Helvetica 0 Tf 0 g");
52823 }
52824 const font = await WidgetAnnotation._getFontData(evaluator, task, this.data.defaultAppearanceData, this._fieldResources.mergedResources);
52825 let defaultAppearance;
52826 let {
52827 fontSize
52828 } = this.data.defaultAppearanceData;
52829 if (!fontSize) {
52830 const lineHeight = (totalHeight - defaultPadding) / lineCount;
52831 let lineWidth = -1;
52832 let value;
52833 for (const {
52834 displayValue
52835 } of this.data.options) {
52836 const width = this._getTextWidth(displayValue, font);
52837 if (width > lineWidth) {
52838 lineWidth = width;
52839 value = displayValue;
52840 }
52841 }
52842 [defaultAppearance, fontSize] = this._computeFontSize(lineHeight, totalWidth - 2 * defaultHPadding, value, font, -1);
52843 } else {
52844 defaultAppearance = this._defaultAppearance;
52845 }
52846 const lineHeight = fontSize * LINE_FACTOR;
52847 const vPadding = (lineHeight - fontSize) / 2;
52848 const numberOfVisibleLines = Math.floor(totalHeight / lineHeight);
52849 let firstIndex = 0;
52850 if (valueIndices.length > 0) {
52851 const minIndex = Math.min(...valueIndices);
52852 const maxIndex = Math.max(...valueIndices);
52853 firstIndex = Math.max(0, maxIndex - numberOfVisibleLines + 1);
52854 if (firstIndex > minIndex) {
52855 firstIndex = minIndex;
52856 }
52857 }
52858 const end = Math.min(firstIndex + numberOfVisibleLines + 1, lineCount);
52859 const buf = ["/Tx BMC q", `1 1 ${totalWidth} ${totalHeight} re W n`];
52860 if (valueIndices.length) {
52861 buf.push("0.600006 0.756866 0.854904 rg");
52862 for (const index of valueIndices) {
52863 if (firstIndex <= index && index < end) {
52864 buf.push(`1 ${totalHeight - (index - firstIndex + 1) * lineHeight} ${totalWidth} ${lineHeight} re f`);
52865 }
52866 }
52867 }
52868 buf.push("BT", defaultAppearance, `1 0 0 1 0 ${totalHeight} Tm`);
52869 const prevInfo = {
52870 shift: 0
52871 };
52872 for (let i = firstIndex; i < end; i++) {
52873 const {
52874 displayValue
52875 } = this.data.options[i];
52876 const vpadding = i === firstIndex ? vPadding : 0;
52877 buf.push(this._renderText(displayValue, font, fontSize, totalWidth, 0, prevInfo, defaultHPadding, -lineHeight + vpadding));
52878 }
52879 buf.push("ET Q EMC");
52880 return buf.join("\n");
52881 }
52882}
52883class SignatureWidgetAnnotation extends WidgetAnnotation {
52884 constructor(params) {
52885 super(params);
52886 this.data.fieldValue = null;
52887 this.data.hasOwnCanvas = this.data.noRotate;
52888 this.data.noHTML = !this.data.hasOwnCanvas;
52889 }
52890 getFieldObject() {
52891 return {
52892 id: this.data.id,
52893 value: null,
52894 page: this.data.pageIndex,
52895 type: "signature"
52896 };
52897 }
52898}
52899class TextAnnotation extends MarkupAnnotation {
52900 constructor(params) {
52901 const DEFAULT_ICON_SIZE = 22;
52902 super(params);
52903 this.data.noRotate = true;
52904 this.data.hasOwnCanvas = this.data.noRotate;
52905 this.data.noHTML = false;
52906 const {
52907 dict
52908 } = params;
52909 this.data.annotationType = AnnotationType.TEXT;
52910 if (this.data.hasAppearance) {
52911 this.data.name = "NoIcon";
52912 } else {
52913 this.data.rect[1] = this.data.rect[3] - DEFAULT_ICON_SIZE;
52914 this.data.rect[2] = this.data.rect[0] + DEFAULT_ICON_SIZE;
52915 this.data.name = dict.has("Name") ? dict.get("Name").name : "Note";
52916 }
52917 if (dict.has("State")) {
52918 this.data.state = dict.get("State") || null;
52919 this.data.stateModel = dict.get("StateModel") || null;
52920 } else {
52921 this.data.state = null;
52922 this.data.stateModel = null;
52923 }
52924 }
52925}
52926class LinkAnnotation extends Annotation {
52927 constructor(params) {
52928 super(params);
52929 const {
52930 dict,
52931 annotationGlobals
52932 } = params;
52933 this.data.annotationType = AnnotationType.LINK;
52934 this.data.noHTML = false;
52935 const quadPoints = getQuadPoints(dict, this.rectangle);
52936 if (quadPoints) {
52937 this.data.quadPoints = quadPoints;
52938 }
52939 this.data.borderColor ||= this.data.color;
52940 Catalog.parseDestDictionary({
52941 destDict: dict,
52942 resultObj: this.data,
52943 docBaseUrl: annotationGlobals.baseUrl,
52944 docAttachments: annotationGlobals.attachments
52945 });
52946 }
52947}
52948class PopupAnnotation extends Annotation {
52949 constructor(params) {
52950 super(params);
52951 const {
52952 dict
52953 } = params;
52954 this.data.annotationType = AnnotationType.POPUP;
52955 this.data.noHTML = false;
52956 if (this.data.rect[0] === this.data.rect[2] || this.data.rect[1] === this.data.rect[3]) {
52957 this.data.rect = null;
52958 }
52959 let parentItem = dict.get("Parent");
52960 if (!parentItem) {
52961 warn("Popup annotation has a missing or invalid parent annotation.");
52962 return;
52963 }
52964 const parentRect = parentItem.getArray("Rect");
52965 this.data.parentRect = Array.isArray(parentRect) && parentRect.length === 4 ? Util.normalizeRect(parentRect) : null;
52966 const rt = parentItem.get("RT");
52967 if (isName(rt, AnnotationReplyType.GROUP)) {
52968 parentItem = parentItem.get("IRT");
52969 }
52970 if (!parentItem.has("M")) {
52971 this.data.modificationDate = null;
52972 } else {
52973 this.setModificationDate(parentItem.get("M"));
52974 this.data.modificationDate = this.modificationDate;
52975 }
52976 if (!parentItem.has("C")) {
52977 this.data.color = null;
52978 } else {
52979 this.setColor(parentItem.getArray("C"));
52980 this.data.color = this.color;
52981 }
52982 if (!this.viewable) {
52983 const parentFlags = parentItem.get("F");
52984 if (this._isViewable(parentFlags)) {
52985 this.setFlags(parentFlags);
52986 }
52987 }
52988 this.setTitle(parentItem.get("T"));
52989 this.data.titleObj = this._title;
52990 this.setContents(parentItem.get("Contents"));
52991 this.data.contentsObj = this._contents;
52992 if (parentItem.has("RC")) {
52993 this.data.richText = XFAFactory.getRichTextAsHtml(parentItem.get("RC"));
52994 }
52995 this.data.open = !!dict.get("Open");
52996 }
52997}
52998class FreeTextAnnotation extends MarkupAnnotation {
52999 constructor(params) {
53000 super(params);
53001 this.data.hasOwnCanvas = !this.data.noHTML;
53002 this.data.noHTML = false;
53003 const {
53004 evaluatorOptions,
53005 xref
53006 } = params;
53007 this.data.annotationType = AnnotationType.FREETEXT;
53008 this.setDefaultAppearance(params);
53009 this._hasAppearance = !!this.appearance;
53010 if (this._hasAppearance) {
53011 const {
53012 fontColor,
53013 fontSize
53014 } = parseAppearanceStream(this.appearance, evaluatorOptions, xref);
53015 this.data.defaultAppearanceData.fontColor = fontColor;
53016 this.data.defaultAppearanceData.fontSize = fontSize || 10;
53017 } else {
53018 this.data.defaultAppearanceData.fontSize ||= 10;
53019 const {
53020 fontColor,
53021 fontSize
53022 } = this.data.defaultAppearanceData;
53023 if (this._contents.str) {
53024 this.data.textContent = this._contents.str.split(/\r\n?|\n/).map(line => line.trimEnd());
53025 const {
53026 coords,
53027 bbox,
53028 matrix
53029 } = FakeUnicodeFont.getFirstPositionInfo(this.rectangle, this.rotation, fontSize);
53030 this.data.textPosition = this._transformPoint(coords, bbox, matrix);
53031 }
53032 if (this._isOffscreenCanvasSupported) {
53033 const strokeAlpha = params.dict.get("CA");
53034 const fakeUnicodeFont = new FakeUnicodeFont(xref, "sans-serif");
53035 this.appearance = fakeUnicodeFont.createAppearance(this._contents.str, this.rectangle, this.rotation, fontSize, fontColor, strokeAlpha);
53036 this._streams.push(this.appearance);
53037 } else {
53038 warn("FreeTextAnnotation: OffscreenCanvas is not supported, annotation may not render correctly.");
53039 }
53040 }
53041 }
53042 get hasTextContent() {
53043 return this._hasAppearance;
53044 }
53045 static createNewDict(annotation, xref, {
53046 apRef,
53047 ap
53048 }) {
53049 const {
53050 color,
53051 fontSize,
53052 rect,
53053 rotation,
53054 user,
53055 value
53056 } = annotation;
53057 const freetext = new Dict(xref);
53058 freetext.set("Type", Name.get("Annot"));
53059 freetext.set("Subtype", Name.get("FreeText"));
53060 freetext.set("CreationDate", `D:${getModificationDate()}`);
53061 freetext.set("Rect", rect);
53062 const da = `/Helv ${fontSize} Tf ${getPdfColor(color, true)}`;
53063 freetext.set("DA", da);
53064 freetext.set("Contents", isAscii(value) ? value : stringToUTF16String(value, true));
53065 freetext.set("F", 4);
53066 freetext.set("Border", [0, 0, 0]);
53067 freetext.set("Rotate", rotation);
53068 if (user) {
53069 freetext.set("T", isAscii(user) ? user : stringToUTF16String(user, true));
53070 }
53071 if (apRef || ap) {
53072 const n = new Dict(xref);
53073 freetext.set("AP", n);
53074 if (apRef) {
53075 n.set("N", apRef);
53076 } else {
53077 n.set("N", ap);
53078 }
53079 }
53080 return freetext;
53081 }
53082 static async createNewAppearanceStream(annotation, xref, params) {
53083 const {
53084 baseFontRef,
53085 evaluator,
53086 task
53087 } = params;
53088 const {
53089 color,
53090 fontSize,
53091 rect,
53092 rotation,
53093 value
53094 } = annotation;
53095 const resources = new Dict(xref);
53096 const font = new Dict(xref);
53097 if (baseFontRef) {
53098 font.set("Helv", baseFontRef);
53099 } else {
53100 const baseFont = new Dict(xref);
53101 baseFont.set("BaseFont", Name.get("Helvetica"));
53102 baseFont.set("Type", Name.get("Font"));
53103 baseFont.set("Subtype", Name.get("Type1"));
53104 baseFont.set("Encoding", Name.get("WinAnsiEncoding"));
53105 font.set("Helv", baseFont);
53106 }
53107 resources.set("Font", font);
53108 const helv = await WidgetAnnotation._getFontData(evaluator, task, {
53109 fontName: "Helv",
53110 fontSize
53111 }, resources);
53112 const [x1, y1, x2, y2] = rect;
53113 let w = x2 - x1;
53114 let h = y2 - y1;
53115 if (rotation % 180 !== 0) {
53116 [w, h] = [h, w];
53117 }
53118 const lines = value.split("\n");
53119 const scale = fontSize / 1000;
53120 let totalWidth = -Infinity;
53121 const encodedLines = [];
53122 for (let line of lines) {
53123 const encoded = helv.encodeString(line);
53124 if (encoded.length > 1) {
53125 return null;
53126 }
53127 line = encoded.join("");
53128 encodedLines.push(line);
53129 let lineWidth = 0;
53130 const glyphs = helv.charsToGlyphs(line);
53131 for (const glyph of glyphs) {
53132 lineWidth += glyph.width * scale;
53133 }
53134 totalWidth = Math.max(totalWidth, lineWidth);
53135 }
53136 let hscale = 1;
53137 if (totalWidth > w) {
53138 hscale = w / totalWidth;
53139 }
53140 let vscale = 1;
53141 const lineHeight = LINE_FACTOR * fontSize;
53142 const lineAscent = (LINE_FACTOR - LINE_DESCENT_FACTOR) * fontSize;
53143 const totalHeight = lineHeight * lines.length;
53144 if (totalHeight > h) {
53145 vscale = h / totalHeight;
53146 }
53147 const fscale = Math.min(hscale, vscale);
53148 const newFontSize = fontSize * fscale;
53149 let firstPoint, clipBox, matrix;
53150 switch (rotation) {
53151 case 0:
53152 matrix = [1, 0, 0, 1];
53153 clipBox = [rect[0], rect[1], w, h];
53154 firstPoint = [rect[0], rect[3] - lineAscent];
53155 break;
53156 case 90:
53157 matrix = [0, 1, -1, 0];
53158 clipBox = [rect[1], -rect[2], w, h];
53159 firstPoint = [rect[1], -rect[0] - lineAscent];
53160 break;
53161 case 180:
53162 matrix = [-1, 0, 0, -1];
53163 clipBox = [-rect[2], -rect[3], w, h];
53164 firstPoint = [-rect[2], -rect[1] - lineAscent];
53165 break;
53166 case 270:
53167 matrix = [0, -1, 1, 0];
53168 clipBox = [-rect[3], rect[0], w, h];
53169 firstPoint = [-rect[3], rect[2] - lineAscent];
53170 break;
53171 }
53172 const buffer = ["q", `${matrix.join(" ")} 0 0 cm`, `${clipBox.join(" ")} re W n`, `BT`, `${getPdfColor(color, true)}`, `0 Tc /Helv ${numberToString(newFontSize)} Tf`];
53173 buffer.push(`${firstPoint.join(" ")} Td (${escapeString(encodedLines[0])}) Tj`);
53174 const vShift = numberToString(lineHeight);
53175 for (let i = 1, ii = encodedLines.length; i < ii; i++) {
53176 const line = encodedLines[i];
53177 buffer.push(`0 -${vShift} Td (${escapeString(line)}) Tj`);
53178 }
53179 buffer.push("ET", "Q");
53180 const appearance = buffer.join("\n");
53181 const appearanceStreamDict = new Dict(xref);
53182 appearanceStreamDict.set("FormType", 1);
53183 appearanceStreamDict.set("Subtype", Name.get("Form"));
53184 appearanceStreamDict.set("Type", Name.get("XObject"));
53185 appearanceStreamDict.set("BBox", rect);
53186 appearanceStreamDict.set("Resources", resources);
53187 appearanceStreamDict.set("Matrix", [1, 0, 0, 1, -rect[0], -rect[1]]);
53188 const ap = new StringStream(appearance);
53189 ap.dict = appearanceStreamDict;
53190 return ap;
53191 }
53192}
53193class LineAnnotation extends MarkupAnnotation {
53194 constructor(params) {
53195 super(params);
53196 const {
53197 dict,
53198 xref
53199 } = params;
53200 this.data.annotationType = AnnotationType.LINE;
53201 this.data.hasOwnCanvas = this.data.noRotate;
53202 this.data.noHTML = false;
53203 const lineCoordinates = dict.getArray("L");
53204 this.data.lineCoordinates = Util.normalizeRect(lineCoordinates);
53205 this.setLineEndings(dict.getArray("LE"));
53206 this.data.lineEndings = this.lineEndings;
53207 if (!this.appearance) {
53208 const strokeColor = this.color ? getPdfColorArray(this.color) : [0, 0, 0];
53209 const strokeAlpha = dict.get("CA");
53210 const interiorColor = getRgbColor(dict.getArray("IC"), null);
53211 const fillColor = interiorColor ? getPdfColorArray(interiorColor) : null;
53212 const fillAlpha = fillColor ? strokeAlpha : null;
53213 const borderWidth = this.borderStyle.width || 1,
53214 borderAdjust = 2 * borderWidth;
53215 const bbox = [this.data.lineCoordinates[0] - borderAdjust, this.data.lineCoordinates[1] - borderAdjust, this.data.lineCoordinates[2] + borderAdjust, this.data.lineCoordinates[3] + borderAdjust];
53216 if (!Util.intersect(this.rectangle, bbox)) {
53217 this.rectangle = bbox;
53218 }
53219 this._setDefaultAppearance({
53220 xref,
53221 extra: `${borderWidth} w`,
53222 strokeColor,
53223 fillColor,
53224 strokeAlpha,
53225 fillAlpha,
53226 pointsCallback: (buffer, points) => {
53227 buffer.push(`${lineCoordinates[0]} ${lineCoordinates[1]} m`, `${lineCoordinates[2]} ${lineCoordinates[3]} l`, "S");
53228 return [points[0].x - borderWidth, points[1].x + borderWidth, points[3].y - borderWidth, points[1].y + borderWidth];
53229 }
53230 });
53231 }
53232 }
53233}
53234class SquareAnnotation extends MarkupAnnotation {
53235 constructor(params) {
53236 super(params);
53237 const {
53238 dict,
53239 xref
53240 } = params;
53241 this.data.annotationType = AnnotationType.SQUARE;
53242 this.data.hasOwnCanvas = this.data.noRotate;
53243 this.data.noHTML = false;
53244 if (!this.appearance) {
53245 const strokeColor = this.color ? getPdfColorArray(this.color) : [0, 0, 0];
53246 const strokeAlpha = dict.get("CA");
53247 const interiorColor = getRgbColor(dict.getArray("IC"), null);
53248 const fillColor = interiorColor ? getPdfColorArray(interiorColor) : null;
53249 const fillAlpha = fillColor ? strokeAlpha : null;
53250 if (this.borderStyle.width === 0 && !fillColor) {
53251 return;
53252 }
53253 this._setDefaultAppearance({
53254 xref,
53255 extra: `${this.borderStyle.width} w`,
53256 strokeColor,
53257 fillColor,
53258 strokeAlpha,
53259 fillAlpha,
53260 pointsCallback: (buffer, points) => {
53261 const x = points[2].x + this.borderStyle.width / 2;
53262 const y = points[2].y + this.borderStyle.width / 2;
53263 const width = points[3].x - points[2].x - this.borderStyle.width;
53264 const height = points[1].y - points[3].y - this.borderStyle.width;
53265 buffer.push(`${x} ${y} ${width} ${height} re`);
53266 if (fillColor) {
53267 buffer.push("B");
53268 } else {
53269 buffer.push("S");
53270 }
53271 return [points[0].x, points[1].x, points[3].y, points[1].y];
53272 }
53273 });
53274 }
53275 }
53276}
53277class CircleAnnotation extends MarkupAnnotation {
53278 constructor(params) {
53279 super(params);
53280 const {
53281 dict,
53282 xref
53283 } = params;
53284 this.data.annotationType = AnnotationType.CIRCLE;
53285 if (!this.appearance) {
53286 const strokeColor = this.color ? getPdfColorArray(this.color) : [0, 0, 0];
53287 const strokeAlpha = dict.get("CA");
53288 const interiorColor = getRgbColor(dict.getArray("IC"), null);
53289 const fillColor = interiorColor ? getPdfColorArray(interiorColor) : null;
53290 const fillAlpha = fillColor ? strokeAlpha : null;
53291 if (this.borderStyle.width === 0 && !fillColor) {
53292 return;
53293 }
53294 const controlPointsDistance = 4 / 3 * Math.tan(Math.PI / (2 * 4));
53295 this._setDefaultAppearance({
53296 xref,
53297 extra: `${this.borderStyle.width} w`,
53298 strokeColor,
53299 fillColor,
53300 strokeAlpha,
53301 fillAlpha,
53302 pointsCallback: (buffer, points) => {
53303 const x0 = points[0].x + this.borderStyle.width / 2;
53304 const y0 = points[0].y - this.borderStyle.width / 2;
53305 const x1 = points[3].x - this.borderStyle.width / 2;
53306 const y1 = points[3].y + this.borderStyle.width / 2;
53307 const xMid = x0 + (x1 - x0) / 2;
53308 const yMid = y0 + (y1 - y0) / 2;
53309 const xOffset = (x1 - x0) / 2 * controlPointsDistance;
53310 const yOffset = (y1 - y0) / 2 * controlPointsDistance;
53311 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");
53312 if (fillColor) {
53313 buffer.push("B");
53314 } else {
53315 buffer.push("S");
53316 }
53317 return [points[0].x, points[1].x, points[3].y, points[1].y];
53318 }
53319 });
53320 }
53321 }
53322}
53323class PolylineAnnotation extends MarkupAnnotation {
53324 constructor(params) {
53325 super(params);
53326 const {
53327 dict,
53328 xref
53329 } = params;
53330 this.data.annotationType = AnnotationType.POLYLINE;
53331 this.data.hasOwnCanvas = this.data.noRotate;
53332 this.data.noHTML = false;
53333 this.data.vertices = [];
53334 if (!(this instanceof PolygonAnnotation)) {
53335 this.setLineEndings(dict.getArray("LE"));
53336 this.data.lineEndings = this.lineEndings;
53337 }
53338 const rawVertices = dict.getArray("Vertices");
53339 if (!Array.isArray(rawVertices)) {
53340 return;
53341 }
53342 for (let i = 0, ii = rawVertices.length; i < ii; i += 2) {
53343 this.data.vertices.push({
53344 x: rawVertices[i],
53345 y: rawVertices[i + 1]
53346 });
53347 }
53348 if (!this.appearance) {
53349 const strokeColor = this.color ? getPdfColorArray(this.color) : [0, 0, 0];
53350 const strokeAlpha = dict.get("CA");
53351 const borderWidth = this.borderStyle.width || 1,
53352 borderAdjust = 2 * borderWidth;
53353 const bbox = [Infinity, Infinity, -Infinity, -Infinity];
53354 for (const vertex of this.data.vertices) {
53355 bbox[0] = Math.min(bbox[0], vertex.x - borderAdjust);
53356 bbox[1] = Math.min(bbox[1], vertex.y - borderAdjust);
53357 bbox[2] = Math.max(bbox[2], vertex.x + borderAdjust);
53358 bbox[3] = Math.max(bbox[3], vertex.y + borderAdjust);
53359 }
53360 if (!Util.intersect(this.rectangle, bbox)) {
53361 this.rectangle = bbox;
53362 }
53363 this._setDefaultAppearance({
53364 xref,
53365 extra: `${borderWidth} w`,
53366 strokeColor,
53367 strokeAlpha,
53368 pointsCallback: (buffer, points) => {
53369 const vertices = this.data.vertices;
53370 for (let i = 0, ii = vertices.length; i < ii; i++) {
53371 buffer.push(`${vertices[i].x} ${vertices[i].y} ${i === 0 ? "m" : "l"}`);
53372 }
53373 buffer.push("S");
53374 return [points[0].x, points[1].x, points[3].y, points[1].y];
53375 }
53376 });
53377 }
53378 }
53379}
53380class PolygonAnnotation extends PolylineAnnotation {
53381 constructor(params) {
53382 super(params);
53383 this.data.annotationType = AnnotationType.POLYGON;
53384 }
53385}
53386class CaretAnnotation extends MarkupAnnotation {
53387 constructor(params) {
53388 super(params);
53389 this.data.annotationType = AnnotationType.CARET;
53390 }
53391}
53392class InkAnnotation extends MarkupAnnotation {
53393 constructor(params) {
53394 super(params);
53395 this.data.hasOwnCanvas = this.data.noRotate;
53396 this.data.noHTML = false;
53397 const {
53398 dict,
53399 xref
53400 } = params;
53401 this.data.annotationType = AnnotationType.INK;
53402 this.data.inkLists = [];
53403 const rawInkLists = dict.getArray("InkList");
53404 if (!Array.isArray(rawInkLists)) {
53405 return;
53406 }
53407 for (let i = 0, ii = rawInkLists.length; i < ii; ++i) {
53408 this.data.inkLists.push([]);
53409 for (let j = 0, jj = rawInkLists[i].length; j < jj; j += 2) {
53410 this.data.inkLists[i].push({
53411 x: xref.fetchIfRef(rawInkLists[i][j]),
53412 y: xref.fetchIfRef(rawInkLists[i][j + 1])
53413 });
53414 }
53415 }
53416 if (!this.appearance) {
53417 const strokeColor = this.color ? getPdfColorArray(this.color) : [0, 0, 0];
53418 const strokeAlpha = dict.get("CA");
53419 const borderWidth = this.borderStyle.width || 1,
53420 borderAdjust = 2 * borderWidth;
53421 const bbox = [Infinity, Infinity, -Infinity, -Infinity];
53422 for (const inkLists of this.data.inkLists) {
53423 for (const vertex of inkLists) {
53424 bbox[0] = Math.min(bbox[0], vertex.x - borderAdjust);
53425 bbox[1] = Math.min(bbox[1], vertex.y - borderAdjust);
53426 bbox[2] = Math.max(bbox[2], vertex.x + borderAdjust);
53427 bbox[3] = Math.max(bbox[3], vertex.y + borderAdjust);
53428 }
53429 }
53430 if (!Util.intersect(this.rectangle, bbox)) {
53431 this.rectangle = bbox;
53432 }
53433 this._setDefaultAppearance({
53434 xref,
53435 extra: `${borderWidth} w`,
53436 strokeColor,
53437 strokeAlpha,
53438 pointsCallback: (buffer, points) => {
53439 for (const inkList of this.data.inkLists) {
53440 for (let i = 0, ii = inkList.length; i < ii; i++) {
53441 buffer.push(`${inkList[i].x} ${inkList[i].y} ${i === 0 ? "m" : "l"}`);
53442 }
53443 buffer.push("S");
53444 }
53445 return [points[0].x, points[1].x, points[3].y, points[1].y];
53446 }
53447 });
53448 }
53449 }
53450 static createNewDict(annotation, xref, {
53451 apRef,
53452 ap
53453 }) {
53454 const {
53455 color,
53456 opacity,
53457 paths,
53458 outlines,
53459 rect,
53460 rotation,
53461 thickness
53462 } = annotation;
53463 const ink = new Dict(xref);
53464 ink.set("Type", Name.get("Annot"));
53465 ink.set("Subtype", Name.get("Ink"));
53466 ink.set("CreationDate", `D:${getModificationDate()}`);
53467 ink.set("Rect", rect);
53468 ink.set("InkList", outlines?.points || paths.map(p => p.points));
53469 ink.set("F", 4);
53470 ink.set("Rotate", rotation);
53471 if (outlines) {
53472 ink.set("IT", Name.get("InkHighlight"));
53473 }
53474 const bs = new Dict(xref);
53475 ink.set("BS", bs);
53476 bs.set("W", thickness);
53477 ink.set("C", Array.from(color, c => c / 255));
53478 ink.set("CA", opacity);
53479 const n = new Dict(xref);
53480 ink.set("AP", n);
53481 if (apRef) {
53482 n.set("N", apRef);
53483 } else {
53484 n.set("N", ap);
53485 }
53486 return ink;
53487 }
53488 static async createNewAppearanceStream(annotation, xref, params) {
53489 if (annotation.outlines) {
53490 return this.createNewAppearanceStreamForHighlight(annotation, xref, params);
53491 }
53492 const {
53493 color,
53494 rect,
53495 paths,
53496 thickness,
53497 opacity
53498 } = annotation;
53499 const appearanceBuffer = [`${thickness} w 1 J 1 j`, `${getPdfColor(color, false)}`];
53500 if (opacity !== 1) {
53501 appearanceBuffer.push("/R0 gs");
53502 }
53503 const buffer = [];
53504 for (const {
53505 bezier
53506 } of paths) {
53507 buffer.length = 0;
53508 buffer.push(`${numberToString(bezier[0])} ${numberToString(bezier[1])} m`);
53509 if (bezier.length === 2) {
53510 buffer.push(`${numberToString(bezier[0])} ${numberToString(bezier[1])} l S`);
53511 } else {
53512 for (let i = 2, ii = bezier.length; i < ii; i += 6) {
53513 const curve = bezier.slice(i, i + 6).map(numberToString).join(" ");
53514 buffer.push(`${curve} c`);
53515 }
53516 buffer.push("S");
53517 }
53518 appearanceBuffer.push(buffer.join("\n"));
53519 }
53520 const appearance = appearanceBuffer.join("\n");
53521 const appearanceStreamDict = new Dict(xref);
53522 appearanceStreamDict.set("FormType", 1);
53523 appearanceStreamDict.set("Subtype", Name.get("Form"));
53524 appearanceStreamDict.set("Type", Name.get("XObject"));
53525 appearanceStreamDict.set("BBox", rect);
53526 appearanceStreamDict.set("Length", appearance.length);
53527 if (opacity !== 1) {
53528 const resources = new Dict(xref);
53529 const extGState = new Dict(xref);
53530 const r0 = new Dict(xref);
53531 r0.set("CA", opacity);
53532 r0.set("Type", Name.get("ExtGState"));
53533 extGState.set("R0", r0);
53534 resources.set("ExtGState", extGState);
53535 appearanceStreamDict.set("Resources", resources);
53536 }
53537 const ap = new StringStream(appearance);
53538 ap.dict = appearanceStreamDict;
53539 return ap;
53540 }
53541 static async createNewAppearanceStreamForHighlight(annotation, xref, params) {
53542 const {
53543 color,
53544 rect,
53545 outlines: {
53546 outline
53547 },
53548 opacity
53549 } = annotation;
53550 const appearanceBuffer = [`${getPdfColor(color, true)}`, "/R0 gs"];
53551 appearanceBuffer.push(`${numberToString(outline[4])} ${numberToString(outline[5])} m`);
53552 for (let i = 6, ii = outline.length; i < ii; i += 6) {
53553 if (isNaN(outline[i]) || outline[i] === null) {
53554 appearanceBuffer.push(`${numberToString(outline[i + 4])} ${numberToString(outline[i + 5])} l`);
53555 } else {
53556 const curve = outline.slice(i, i + 6).map(numberToString).join(" ");
53557 appearanceBuffer.push(`${curve} c`);
53558 }
53559 }
53560 appearanceBuffer.push("h f");
53561 const appearance = appearanceBuffer.join("\n");
53562 const appearanceStreamDict = new Dict(xref);
53563 appearanceStreamDict.set("FormType", 1);
53564 appearanceStreamDict.set("Subtype", Name.get("Form"));
53565 appearanceStreamDict.set("Type", Name.get("XObject"));
53566 appearanceStreamDict.set("BBox", rect);
53567 appearanceStreamDict.set("Length", appearance.length);
53568 const resources = new Dict(xref);
53569 const extGState = new Dict(xref);
53570 resources.set("ExtGState", extGState);
53571 appearanceStreamDict.set("Resources", resources);
53572 const r0 = new Dict(xref);
53573 extGState.set("R0", r0);
53574 r0.set("BM", Name.get("Multiply"));
53575 if (opacity !== 1) {
53576 r0.set("ca", opacity);
53577 r0.set("Type", Name.get("ExtGState"));
53578 }
53579 const ap = new StringStream(appearance);
53580 ap.dict = appearanceStreamDict;
53581 return ap;
53582 }
53583}
53584class HighlightAnnotation extends MarkupAnnotation {
53585 constructor(params) {
53586 super(params);
53587 const {
53588 dict,
53589 xref
53590 } = params;
53591 this.data.annotationType = AnnotationType.HIGHLIGHT;
53592 const quadPoints = this.data.quadPoints = getQuadPoints(dict, null);
53593 if (quadPoints) {
53594 const resources = this.appearance?.dict.get("Resources");
53595 if (!this.appearance || !resources?.has("ExtGState")) {
53596 if (this.appearance) {
53597 warn("HighlightAnnotation - ignoring built-in appearance stream.");
53598 }
53599 const fillColor = this.color ? getPdfColorArray(this.color) : [1, 1, 0];
53600 const fillAlpha = dict.get("CA");
53601 this._setDefaultAppearance({
53602 xref,
53603 fillColor,
53604 blendMode: "Multiply",
53605 fillAlpha,
53606 pointsCallback: (buffer, points) => {
53607 buffer.push(`${points[0].x} ${points[0].y} m`, `${points[1].x} ${points[1].y} l`, `${points[3].x} ${points[3].y} l`, `${points[2].x} ${points[2].y} l`, "f");
53608 return [points[0].x, points[1].x, points[3].y, points[1].y];
53609 }
53610 });
53611 }
53612 } else {
53613 this.data.popupRef = null;
53614 }
53615 }
53616 static createNewDict(annotation, xref, {
53617 apRef,
53618 ap
53619 }) {
53620 const {
53621 color,
53622 opacity,
53623 rect,
53624 rotation,
53625 user,
53626 quadPoints
53627 } = annotation;
53628 const highlight = new Dict(xref);
53629 highlight.set("Type", Name.get("Annot"));
53630 highlight.set("Subtype", Name.get("Highlight"));
53631 highlight.set("CreationDate", `D:${getModificationDate()}`);
53632 highlight.set("Rect", rect);
53633 highlight.set("F", 4);
53634 highlight.set("Border", [0, 0, 0]);
53635 highlight.set("Rotate", rotation);
53636 highlight.set("QuadPoints", quadPoints);
53637 highlight.set("C", Array.from(color, c => c / 255));
53638 highlight.set("CA", opacity);
53639 if (user) {
53640 highlight.set("T", isAscii(user) ? user : stringToUTF16String(user, true));
53641 }
53642 if (apRef || ap) {
53643 const n = new Dict(xref);
53644 highlight.set("AP", n);
53645 n.set("N", apRef || ap);
53646 }
53647 return highlight;
53648 }
53649 static async createNewAppearanceStream(annotation, xref, params) {
53650 const {
53651 color,
53652 rect,
53653 outlines,
53654 opacity
53655 } = annotation;
53656 const appearanceBuffer = [`${getPdfColor(color, true)}`, "/R0 gs"];
53657 const buffer = [];
53658 for (const outline of outlines) {
53659 buffer.length = 0;
53660 buffer.push(`${numberToString(outline[0])} ${numberToString(outline[1])} m`);
53661 for (let i = 2, ii = outline.length; i < ii; i += 2) {
53662 buffer.push(`${numberToString(outline[i])} ${numberToString(outline[i + 1])} l`);
53663 }
53664 buffer.push("h");
53665 appearanceBuffer.push(buffer.join("\n"));
53666 }
53667 appearanceBuffer.push("f*");
53668 const appearance = appearanceBuffer.join("\n");
53669 const appearanceStreamDict = new Dict(xref);
53670 appearanceStreamDict.set("FormType", 1);
53671 appearanceStreamDict.set("Subtype", Name.get("Form"));
53672 appearanceStreamDict.set("Type", Name.get("XObject"));
53673 appearanceStreamDict.set("BBox", rect);
53674 appearanceStreamDict.set("Length", appearance.length);
53675 const resources = new Dict(xref);
53676 const extGState = new Dict(xref);
53677 resources.set("ExtGState", extGState);
53678 appearanceStreamDict.set("Resources", resources);
53679 const r0 = new Dict(xref);
53680 extGState.set("R0", r0);
53681 r0.set("BM", Name.get("Multiply"));
53682 if (opacity !== 1) {
53683 r0.set("ca", opacity);
53684 r0.set("Type", Name.get("ExtGState"));
53685 }
53686 const ap = new StringStream(appearance);
53687 ap.dict = appearanceStreamDict;
53688 return ap;
53689 }
53690}
53691class UnderlineAnnotation extends MarkupAnnotation {
53692 constructor(params) {
53693 super(params);
53694 const {
53695 dict,
53696 xref
53697 } = params;
53698 this.data.annotationType = AnnotationType.UNDERLINE;
53699 const quadPoints = this.data.quadPoints = getQuadPoints(dict, null);
53700 if (quadPoints) {
53701 if (!this.appearance) {
53702 const strokeColor = this.color ? getPdfColorArray(this.color) : [0, 0, 0];
53703 const strokeAlpha = dict.get("CA");
53704 this._setDefaultAppearance({
53705 xref,
53706 extra: "[] 0 d 0.571 w",
53707 strokeColor,
53708 strokeAlpha,
53709 pointsCallback: (buffer, points) => {
53710 buffer.push(`${points[2].x} ${points[2].y + 1.3} m`, `${points[3].x} ${points[3].y + 1.3} l`, "S");
53711 return [points[0].x, points[1].x, points[3].y, points[1].y];
53712 }
53713 });
53714 }
53715 } else {
53716 this.data.popupRef = null;
53717 }
53718 }
53719}
53720class SquigglyAnnotation extends MarkupAnnotation {
53721 constructor(params) {
53722 super(params);
53723 const {
53724 dict,
53725 xref
53726 } = params;
53727 this.data.annotationType = AnnotationType.SQUIGGLY;
53728 const quadPoints = this.data.quadPoints = getQuadPoints(dict, null);
53729 if (quadPoints) {
53730 if (!this.appearance) {
53731 const strokeColor = this.color ? getPdfColorArray(this.color) : [0, 0, 0];
53732 const strokeAlpha = dict.get("CA");
53733 this._setDefaultAppearance({
53734 xref,
53735 extra: "[] 0 d 1 w",
53736 strokeColor,
53737 strokeAlpha,
53738 pointsCallback: (buffer, points) => {
53739 const dy = (points[0].y - points[2].y) / 6;
53740 let shift = dy;
53741 let x = points[2].x;
53742 const y = points[2].y;
53743 const xEnd = points[3].x;
53744 buffer.push(`${x} ${y + shift} m`);
53745 do {
53746 x += 2;
53747 shift = shift === 0 ? dy : 0;
53748 buffer.push(`${x} ${y + shift} l`);
53749 } while (x < xEnd);
53750 buffer.push("S");
53751 return [points[2].x, xEnd, y - 2 * dy, y + 2 * dy];
53752 }
53753 });
53754 }
53755 } else {
53756 this.data.popupRef = null;
53757 }
53758 }
53759}
53760class StrikeOutAnnotation extends MarkupAnnotation {
53761 constructor(params) {
53762 super(params);
53763 const {
53764 dict,
53765 xref
53766 } = params;
53767 this.data.annotationType = AnnotationType.STRIKEOUT;
53768 const quadPoints = this.data.quadPoints = getQuadPoints(dict, null);
53769 if (quadPoints) {
53770 if (!this.appearance) {
53771 const strokeColor = this.color ? getPdfColorArray(this.color) : [0, 0, 0];
53772 const strokeAlpha = dict.get("CA");
53773 this._setDefaultAppearance({
53774 xref,
53775 extra: "[] 0 d 1 w",
53776 strokeColor,
53777 strokeAlpha,
53778 pointsCallback: (buffer, points) => {
53779 buffer.push(`${(points[0].x + points[2].x) / 2} ` + `${(points[0].y + points[2].y) / 2} m`, `${(points[1].x + points[3].x) / 2} ` + `${(points[1].y + points[3].y) / 2} l`, "S");
53780 return [points[0].x, points[1].x, points[3].y, points[1].y];
53781 }
53782 });
53783 }
53784 } else {
53785 this.data.popupRef = null;
53786 }
53787 }
53788}
53789class StampAnnotation extends MarkupAnnotation {
53790 constructor(params) {
53791 super(params);
53792 this.data.annotationType = AnnotationType.STAMP;
53793 this.data.hasOwnCanvas = this.data.noRotate;
53794 this.data.noHTML = false;
53795 }
53796 static async createImage(bitmap, xref) {
53797 const {
53798 width,
53799 height
53800 } = bitmap;
53801 const canvas = new OffscreenCanvas(width, height);
53802 const ctx = canvas.getContext("2d", {
53803 alpha: true
53804 });
53805 ctx.drawImage(bitmap, 0, 0);
53806 const data = ctx.getImageData(0, 0, width, height).data;
53807 const buf32 = new Uint32Array(data.buffer);
53808 const hasAlpha = buf32.some(FeatureTest.isLittleEndian ? x => x >>> 24 !== 0xff : x => (x & 0xff) !== 0xff);
53809 if (hasAlpha) {
53810 ctx.fillStyle = "white";
53811 ctx.fillRect(0, 0, width, height);
53812 ctx.drawImage(bitmap, 0, 0);
53813 }
53814 const jpegBufferPromise = canvas.convertToBlob({
53815 type: "image/jpeg",
53816 quality: 1
53817 }).then(blob => blob.arrayBuffer());
53818 const xobjectName = Name.get("XObject");
53819 const imageName = Name.get("Image");
53820 const image = new Dict(xref);
53821 image.set("Type", xobjectName);
53822 image.set("Subtype", imageName);
53823 image.set("BitsPerComponent", 8);
53824 image.set("ColorSpace", Name.get("DeviceRGB"));
53825 image.set("Filter", Name.get("DCTDecode"));
53826 image.set("BBox", [0, 0, width, height]);
53827 image.set("Width", width);
53828 image.set("Height", height);
53829 let smaskStream = null;
53830 if (hasAlpha) {
53831 const alphaBuffer = new Uint8Array(buf32.length);
53832 if (FeatureTest.isLittleEndian) {
53833 for (let i = 0, ii = buf32.length; i < ii; i++) {
53834 alphaBuffer[i] = buf32[i] >>> 24;
53835 }
53836 } else {
53837 for (let i = 0, ii = buf32.length; i < ii; i++) {
53838 alphaBuffer[i] = buf32[i] & 0xff;
53839 }
53840 }
53841 const smask = new Dict(xref);
53842 smask.set("Type", xobjectName);
53843 smask.set("Subtype", imageName);
53844 smask.set("BitsPerComponent", 8);
53845 smask.set("ColorSpace", Name.get("DeviceGray"));
53846 smask.set("Width", width);
53847 smask.set("Height", height);
53848 smaskStream = new Stream(alphaBuffer, 0, 0, smask);
53849 }
53850 const imageStream = new Stream(await jpegBufferPromise, 0, 0, image);
53851 return {
53852 imageStream,
53853 smaskStream,
53854 width,
53855 height
53856 };
53857 }
53858 static createNewDict(annotation, xref, {
53859 apRef,
53860 ap
53861 }) {
53862 const {
53863 rect,
53864 rotation,
53865 user
53866 } = annotation;
53867 const stamp = new Dict(xref);
53868 stamp.set("Type", Name.get("Annot"));
53869 stamp.set("Subtype", Name.get("Stamp"));
53870 stamp.set("CreationDate", `D:${getModificationDate()}`);
53871 stamp.set("Rect", rect);
53872 stamp.set("F", 4);
53873 stamp.set("Border", [0, 0, 0]);
53874 stamp.set("Rotate", rotation);
53875 if (user) {
53876 stamp.set("T", isAscii(user) ? user : stringToUTF16String(user, true));
53877 }
53878 if (apRef || ap) {
53879 const n = new Dict(xref);
53880 stamp.set("AP", n);
53881 if (apRef) {
53882 n.set("N", apRef);
53883 } else {
53884 n.set("N", ap);
53885 }
53886 }
53887 return stamp;
53888 }
53889 static async createNewAppearanceStream(annotation, xref, params) {
53890 const {
53891 rotation
53892 } = annotation;
53893 const {
53894 imageRef,
53895 width,
53896 height
53897 } = params.image;
53898 const resources = new Dict(xref);
53899 const xobject = new Dict(xref);
53900 resources.set("XObject", xobject);
53901 xobject.set("Im0", imageRef);
53902 const appearance = `q ${width} 0 0 ${height} 0 0 cm /Im0 Do Q`;
53903 const appearanceStreamDict = new Dict(xref);
53904 appearanceStreamDict.set("FormType", 1);
53905 appearanceStreamDict.set("Subtype", Name.get("Form"));
53906 appearanceStreamDict.set("Type", Name.get("XObject"));
53907 appearanceStreamDict.set("BBox", [0, 0, width, height]);
53908 appearanceStreamDict.set("Resources", resources);
53909 if (rotation) {
53910 const matrix = getRotationMatrix(rotation, width, height);
53911 appearanceStreamDict.set("Matrix", matrix);
53912 }
53913 const ap = new StringStream(appearance);
53914 ap.dict = appearanceStreamDict;
53915 return ap;
53916 }
53917}
53918class FileAttachmentAnnotation extends MarkupAnnotation {
53919 constructor(params) {
53920 super(params);
53921 const {
53922 dict,
53923 xref
53924 } = params;
53925 const file = new FileSpec(dict.get("FS"), xref);
53926 this.data.annotationType = AnnotationType.FILEATTACHMENT;
53927 this.data.hasOwnCanvas = this.data.noRotate;
53928 this.data.noHTML = false;
53929 this.data.file = file.serializable;
53930 const name = dict.get("Name");
53931 this.data.name = name instanceof Name ? stringToPDFString(name.name) : "PushPin";
53932 const fillAlpha = dict.get("ca");
53933 this.data.fillAlpha = typeof fillAlpha === "number" && fillAlpha >= 0 && fillAlpha <= 1 ? fillAlpha : null;
53934 }
53935}
53936
53937;// CONCATENATED MODULE: ./src/core/dataset_reader.js
53938
53939
53940
53941function decodeString(str) {
53942 try {
53943 return stringToUTF8String(str);
53944 } catch (ex) {
53945 warn(`UTF-8 decoding failed: "${ex}".`);
53946 return str;
53947 }
53948}
53949class DatasetXMLParser extends SimpleXMLParser {
53950 constructor(options) {
53951 super(options);
53952 this.node = null;
53953 }
53954 onEndElement(name) {
53955 const node = super.onEndElement(name);
53956 if (node && name === "xfa:datasets") {
53957 this.node = node;
53958 throw new Error("Aborting DatasetXMLParser.");
53959 }
53960 }
53961}
53962class DatasetReader {
53963 constructor(data) {
53964 if (data.datasets) {
53965 this.node = new SimpleXMLParser({
53966 hasAttributes: true
53967 }).parseFromString(data.datasets).documentElement;
53968 } else {
53969 const parser = new DatasetXMLParser({
53970 hasAttributes: true
53971 });
53972 try {
53973 parser.parseFromString(data["xdp:xdp"]);
53974 } catch {}
53975 this.node = parser.node;
53976 }
53977 }
53978 getValue(path) {
53979 if (!this.node || !path) {
53980 return "";
53981 }
53982 const node = this.node.searchNode(parseXFAPath(path), 0);
53983 if (!node) {
53984 return "";
53985 }
53986 const first = node.firstChild;
53987 if (first?.nodeName === "value") {
53988 return node.children.map(child => decodeString(child.textContent));
53989 }
53990 return decodeString(node.textContent);
53991 }
53992}
53993
53994;// CONCATENATED MODULE: ./src/core/xref.js
53995
53996
53997
53998
53999
54000
54001class XRef {
54002 #firstXRefStmPos = null;
54003 constructor(stream, pdfManager) {
54004 this.stream = stream;
54005 this.pdfManager = pdfManager;
54006 this.entries = [];
54007 this._xrefStms = new Set();
54008 this._cacheMap = new Map();
54009 this._pendingRefs = new RefSet();
54010 this._newPersistentRefNum = null;
54011 this._newTemporaryRefNum = null;
54012 this._persistentRefsCache = null;
54013 }
54014 getNewPersistentRef(obj) {
54015 if (this._newPersistentRefNum === null) {
54016 this._newPersistentRefNum = this.entries.length || 1;
54017 }
54018 const num = this._newPersistentRefNum++;
54019 this._cacheMap.set(num, obj);
54020 return Ref.get(num, 0);
54021 }
54022 getNewTemporaryRef() {
54023 if (this._newTemporaryRefNum === null) {
54024 this._newTemporaryRefNum = this.entries.length || 1;
54025 if (this._newPersistentRefNum) {
54026 this._persistentRefsCache = new Map();
54027 for (let i = this._newTemporaryRefNum; i < this._newPersistentRefNum; i++) {
54028 this._persistentRefsCache.set(i, this._cacheMap.get(i));
54029 this._cacheMap.delete(i);
54030 }
54031 }
54032 }
54033 return Ref.get(this._newTemporaryRefNum++, 0);
54034 }
54035 resetNewTemporaryRef() {
54036 this._newTemporaryRefNum = null;
54037 if (this._persistentRefsCache) {
54038 for (const [num, obj] of this._persistentRefsCache) {
54039 this._cacheMap.set(num, obj);
54040 }
54041 }
54042 this._persistentRefsCache = null;
54043 }
54044 setStartXRef(startXRef) {
54045 this.startXRefQueue = [startXRef];
54046 }
54047 parse(recoveryMode = false) {
54048 let trailerDict;
54049 if (!recoveryMode) {
54050 trailerDict = this.readXRef();
54051 } else {
54052 warn("Indexing all PDF objects");
54053 trailerDict = this.indexObjects();
54054 }
54055 trailerDict.assignXref(this);
54056 this.trailer = trailerDict;
54057 let encrypt;
54058 try {
54059 encrypt = trailerDict.get("Encrypt");
54060 } catch (ex) {
54061 if (ex instanceof MissingDataException) {
54062 throw ex;
54063 }
54064 warn(`XRef.parse - Invalid "Encrypt" reference: "${ex}".`);
54065 }
54066 if (encrypt instanceof Dict) {
54067 const ids = trailerDict.get("ID");
54068 const fileId = ids?.length ? ids[0] : "";
54069 encrypt.suppressEncryption = true;
54070 this.encrypt = new CipherTransformFactory(encrypt, fileId, this.pdfManager.password);
54071 }
54072 let root;
54073 try {
54074 root = trailerDict.get("Root");
54075 } catch (ex) {
54076 if (ex instanceof MissingDataException) {
54077 throw ex;
54078 }
54079 warn(`XRef.parse - Invalid "Root" reference: "${ex}".`);
54080 }
54081 if (root instanceof Dict) {
54082 try {
54083 const pages = root.get("Pages");
54084 if (pages instanceof Dict) {
54085 this.root = root;
54086 return;
54087 }
54088 } catch (ex) {
54089 if (ex instanceof MissingDataException) {
54090 throw ex;
54091 }
54092 warn(`XRef.parse - Invalid "Pages" reference: "${ex}".`);
54093 }
54094 }
54095 if (!recoveryMode) {
54096 throw new XRefParseException();
54097 }
54098 throw new InvalidPDFException("Invalid Root reference.");
54099 }
54100 processXRefTable(parser) {
54101 if (!("tableState" in this)) {
54102 this.tableState = {
54103 entryNum: 0,
54104 streamPos: parser.lexer.stream.pos,
54105 parserBuf1: parser.buf1,
54106 parserBuf2: parser.buf2
54107 };
54108 }
54109 const obj = this.readXRefTable(parser);
54110 if (!isCmd(obj, "trailer")) {
54111 throw new FormatError("Invalid XRef table: could not find trailer dictionary");
54112 }
54113 let dict = parser.getObj();
54114 if (!(dict instanceof Dict) && dict.dict) {
54115 dict = dict.dict;
54116 }
54117 if (!(dict instanceof Dict)) {
54118 throw new FormatError("Invalid XRef table: could not parse trailer dictionary");
54119 }
54120 delete this.tableState;
54121 return dict;
54122 }
54123 readXRefTable(parser) {
54124 const stream = parser.lexer.stream;
54125 const tableState = this.tableState;
54126 stream.pos = tableState.streamPos;
54127 parser.buf1 = tableState.parserBuf1;
54128 parser.buf2 = tableState.parserBuf2;
54129 let obj;
54130 while (true) {
54131 if (!("firstEntryNum" in tableState) || !("entryCount" in tableState)) {
54132 if (isCmd(obj = parser.getObj(), "trailer")) {
54133 break;
54134 }
54135 tableState.firstEntryNum = obj;
54136 tableState.entryCount = parser.getObj();
54137 }
54138 let first = tableState.firstEntryNum;
54139 const count = tableState.entryCount;
54140 if (!Number.isInteger(first) || !Number.isInteger(count)) {
54141 throw new FormatError("Invalid XRef table: wrong types in subsection header");
54142 }
54143 for (let i = tableState.entryNum; i < count; i++) {
54144 tableState.streamPos = stream.pos;
54145 tableState.entryNum = i;
54146 tableState.parserBuf1 = parser.buf1;
54147 tableState.parserBuf2 = parser.buf2;
54148 const entry = {};
54149 entry.offset = parser.getObj();
54150 entry.gen = parser.getObj();
54151 const type = parser.getObj();
54152 if (type instanceof Cmd) {
54153 switch (type.cmd) {
54154 case "f":
54155 entry.free = true;
54156 break;
54157 case "n":
54158 entry.uncompressed = true;
54159 break;
54160 }
54161 }
54162 if (!Number.isInteger(entry.offset) || !Number.isInteger(entry.gen) || !(entry.free || entry.uncompressed)) {
54163 throw new FormatError(`Invalid entry in XRef subsection: ${first}, ${count}`);
54164 }
54165 if (i === 0 && entry.free && first === 1) {
54166 first = 0;
54167 }
54168 if (!this.entries[i + first]) {
54169 this.entries[i + first] = entry;
54170 }
54171 }
54172 tableState.entryNum = 0;
54173 tableState.streamPos = stream.pos;
54174 tableState.parserBuf1 = parser.buf1;
54175 tableState.parserBuf2 = parser.buf2;
54176 delete tableState.firstEntryNum;
54177 delete tableState.entryCount;
54178 }
54179 if (this.entries[0] && !this.entries[0].free) {
54180 throw new FormatError("Invalid XRef table: unexpected first object");
54181 }
54182 return obj;
54183 }
54184 processXRefStream(stream) {
54185 if (!("streamState" in this)) {
54186 const streamParameters = stream.dict;
54187 const byteWidths = streamParameters.get("W");
54188 let range = streamParameters.get("Index");
54189 if (!range) {
54190 range = [0, streamParameters.get("Size")];
54191 }
54192 this.streamState = {
54193 entryRanges: range,
54194 byteWidths,
54195 entryNum: 0,
54196 streamPos: stream.pos
54197 };
54198 }
54199 this.readXRefStream(stream);
54200 delete this.streamState;
54201 return stream.dict;
54202 }
54203 readXRefStream(stream) {
54204 const streamState = this.streamState;
54205 stream.pos = streamState.streamPos;
54206 const [typeFieldWidth, offsetFieldWidth, generationFieldWidth] = streamState.byteWidths;
54207 const entryRanges = streamState.entryRanges;
54208 while (entryRanges.length > 0) {
54209 const [first, n] = entryRanges;
54210 if (!Number.isInteger(first) || !Number.isInteger(n)) {
54211 throw new FormatError(`Invalid XRef range fields: ${first}, ${n}`);
54212 }
54213 if (!Number.isInteger(typeFieldWidth) || !Number.isInteger(offsetFieldWidth) || !Number.isInteger(generationFieldWidth)) {
54214 throw new FormatError(`Invalid XRef entry fields length: ${first}, ${n}`);
54215 }
54216 for (let i = streamState.entryNum; i < n; ++i) {
54217 streamState.entryNum = i;
54218 streamState.streamPos = stream.pos;
54219 let type = 0,
54220 offset = 0,
54221 generation = 0;
54222 for (let j = 0; j < typeFieldWidth; ++j) {
54223 const typeByte = stream.getByte();
54224 if (typeByte === -1) {
54225 throw new FormatError("Invalid XRef byteWidths 'type'.");
54226 }
54227 type = type << 8 | typeByte;
54228 }
54229 if (typeFieldWidth === 0) {
54230 type = 1;
54231 }
54232 for (let j = 0; j < offsetFieldWidth; ++j) {
54233 const offsetByte = stream.getByte();
54234 if (offsetByte === -1) {
54235 throw new FormatError("Invalid XRef byteWidths 'offset'.");
54236 }
54237 offset = offset << 8 | offsetByte;
54238 }
54239 for (let j = 0; j < generationFieldWidth; ++j) {
54240 const generationByte = stream.getByte();
54241 if (generationByte === -1) {
54242 throw new FormatError("Invalid XRef byteWidths 'generation'.");
54243 }
54244 generation = generation << 8 | generationByte;
54245 }
54246 const entry = {};
54247 entry.offset = offset;
54248 entry.gen = generation;
54249 switch (type) {
54250 case 0:
54251 entry.free = true;
54252 break;
54253 case 1:
54254 entry.uncompressed = true;
54255 break;
54256 case 2:
54257 break;
54258 default:
54259 throw new FormatError(`Invalid XRef entry type: ${type}`);
54260 }
54261 if (!this.entries[first + i]) {
54262 this.entries[first + i] = entry;
54263 }
54264 }
54265 streamState.entryNum = 0;
54266 streamState.streamPos = stream.pos;
54267 entryRanges.splice(0, 2);
54268 }
54269 }
54270 indexObjects() {
54271 const TAB = 0x9,
54272 LF = 0xa,
54273 CR = 0xd,
54274 SPACE = 0x20;
54275 const PERCENT = 0x25,
54276 LT = 0x3c;
54277 function readToken(data, offset) {
54278 let token = "",
54279 ch = data[offset];
54280 while (ch !== LF && ch !== CR && ch !== LT) {
54281 if (++offset >= data.length) {
54282 break;
54283 }
54284 token += String.fromCharCode(ch);
54285 ch = data[offset];
54286 }
54287 return token;
54288 }
54289 function skipUntil(data, offset, what) {
54290 const length = what.length,
54291 dataLength = data.length;
54292 let skipped = 0;
54293 while (offset < dataLength) {
54294 let i = 0;
54295 while (i < length && data[offset + i] === what[i]) {
54296 ++i;
54297 }
54298 if (i >= length) {
54299 break;
54300 }
54301 offset++;
54302 skipped++;
54303 }
54304 return skipped;
54305 }
54306 const gEndobjRegExp = /\b(endobj|\d+\s+\d+\s+obj|xref|trailer\s*<<)\b/g;
54307 const gStartxrefRegExp = /\b(startxref|\d+\s+\d+\s+obj)\b/g;
54308 const objRegExp = /^(\d+)\s+(\d+)\s+obj\b/;
54309 const trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
54310 const startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114, 101, 102]);
54311 const xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
54312 this.entries.length = 0;
54313 this._cacheMap.clear();
54314 const stream = this.stream;
54315 stream.pos = 0;
54316 const buffer = stream.getBytes(),
54317 bufferStr = bytesToString(buffer),
54318 length = buffer.length;
54319 let position = stream.start;
54320 const trailers = [],
54321 xrefStms = [];
54322 while (position < length) {
54323 let ch = buffer[position];
54324 if (ch === TAB || ch === LF || ch === CR || ch === SPACE) {
54325 ++position;
54326 continue;
54327 }
54328 if (ch === PERCENT) {
54329 do {
54330 ++position;
54331 if (position >= length) {
54332 break;
54333 }
54334 ch = buffer[position];
54335 } while (ch !== LF && ch !== CR);
54336 continue;
54337 }
54338 const token = readToken(buffer, position);
54339 let m;
54340 if (token.startsWith("xref") && (token.length === 4 || /\s/.test(token[4]))) {
54341 position += skipUntil(buffer, position, trailerBytes);
54342 trailers.push(position);
54343 position += skipUntil(buffer, position, startxrefBytes);
54344 } else if (m = objRegExp.exec(token)) {
54345 const num = m[1] | 0,
54346 gen = m[2] | 0;
54347 const startPos = position + token.length;
54348 let contentLength,
54349 updateEntries = false;
54350 if (!this.entries[num]) {
54351 updateEntries = true;
54352 } else if (this.entries[num].gen === gen) {
54353 try {
54354 const parser = new Parser({
54355 lexer: new Lexer(stream.makeSubStream(startPos))
54356 });
54357 parser.getObj();
54358 updateEntries = true;
54359 } catch (ex) {
54360 if (ex instanceof ParserEOFException) {
54361 warn(`indexObjects -- checking object (${token}): "${ex}".`);
54362 } else {
54363 updateEntries = true;
54364 }
54365 }
54366 }
54367 if (updateEntries) {
54368 this.entries[num] = {
54369 offset: position - stream.start,
54370 gen,
54371 uncompressed: true
54372 };
54373 }
54374 gEndobjRegExp.lastIndex = startPos;
54375 const match = gEndobjRegExp.exec(bufferStr);
54376 if (match) {
54377 const endPos = gEndobjRegExp.lastIndex + 1;
54378 contentLength = endPos - position;
54379 if (match[1] !== "endobj") {
54380 warn(`indexObjects: Found "${match[1]}" inside of another "obj", ` + 'caused by missing "endobj" -- trying to recover.');
54381 contentLength -= match[1].length + 1;
54382 }
54383 } else {
54384 contentLength = length - position;
54385 }
54386 const content = buffer.subarray(position, position + contentLength);
54387 const xrefTagOffset = skipUntil(content, 0, xrefBytes);
54388 if (xrefTagOffset < contentLength && content[xrefTagOffset + 5] < 64) {
54389 xrefStms.push(position - stream.start);
54390 this._xrefStms.add(position - stream.start);
54391 }
54392 position += contentLength;
54393 } else if (token.startsWith("trailer") && (token.length === 7 || /\s/.test(token[7]))) {
54394 trailers.push(position);
54395 const startPos = position + token.length;
54396 let contentLength;
54397 gStartxrefRegExp.lastIndex = startPos;
54398 const match = gStartxrefRegExp.exec(bufferStr);
54399 if (match) {
54400 const endPos = gStartxrefRegExp.lastIndex + 1;
54401 contentLength = endPos - position;
54402 if (match[1] !== "startxref") {
54403 warn(`indexObjects: Found "${match[1]}" after "trailer", ` + 'caused by missing "startxref" -- trying to recover.');
54404 contentLength -= match[1].length + 1;
54405 }
54406 } else {
54407 contentLength = length - position;
54408 }
54409 position += contentLength;
54410 } else {
54411 position += token.length + 1;
54412 }
54413 }
54414 for (const xrefStm of xrefStms) {
54415 this.startXRefQueue.push(xrefStm);
54416 this.readXRef(true);
54417 }
54418 const trailerDicts = [];
54419 let isEncrypted = false;
54420 for (const trailer of trailers) {
54421 stream.pos = trailer;
54422 const parser = new Parser({
54423 lexer: new Lexer(stream),
54424 xref: this,
54425 allowStreams: true,
54426 recoveryMode: true
54427 });
54428 const obj = parser.getObj();
54429 if (!isCmd(obj, "trailer")) {
54430 continue;
54431 }
54432 const dict = parser.getObj();
54433 if (!(dict instanceof Dict)) {
54434 continue;
54435 }
54436 trailerDicts.push(dict);
54437 if (dict.has("Encrypt")) {
54438 isEncrypted = true;
54439 }
54440 }
54441 let trailerDict, trailerError;
54442 for (const dict of [...trailerDicts, "genFallback", ...trailerDicts]) {
54443 if (dict === "genFallback") {
54444 if (!trailerError) {
54445 break;
54446 }
54447 this._generationFallback = true;
54448 continue;
54449 }
54450 let validPagesDict = false;
54451 try {
54452 const rootDict = dict.get("Root");
54453 if (!(rootDict instanceof Dict)) {
54454 continue;
54455 }
54456 const pagesDict = rootDict.get("Pages");
54457 if (!(pagesDict instanceof Dict)) {
54458 continue;
54459 }
54460 const pagesCount = pagesDict.get("Count");
54461 if (Number.isInteger(pagesCount)) {
54462 validPagesDict = true;
54463 }
54464 } catch (ex) {
54465 trailerError = ex;
54466 continue;
54467 }
54468 if (validPagesDict && (!isEncrypted || dict.has("Encrypt")) && dict.has("ID")) {
54469 return dict;
54470 }
54471 trailerDict = dict;
54472 }
54473 if (trailerDict) {
54474 return trailerDict;
54475 }
54476 if (this.topDict) {
54477 return this.topDict;
54478 }
54479 throw new InvalidPDFException("Invalid PDF structure.");
54480 }
54481 readXRef(recoveryMode = false) {
54482 const stream = this.stream;
54483 const startXRefParsedCache = new Set();
54484 while (this.startXRefQueue.length) {
54485 try {
54486 const startXRef = this.startXRefQueue[0];
54487 if (startXRefParsedCache.has(startXRef)) {
54488 warn("readXRef - skipping XRef table since it was already parsed.");
54489 this.startXRefQueue.shift();
54490 continue;
54491 }
54492 startXRefParsedCache.add(startXRef);
54493 stream.pos = startXRef + stream.start;
54494 const parser = new Parser({
54495 lexer: new Lexer(stream),
54496 xref: this,
54497 allowStreams: true
54498 });
54499 let obj = parser.getObj();
54500 let dict;
54501 if (isCmd(obj, "xref")) {
54502 dict = this.processXRefTable(parser);
54503 if (!this.topDict) {
54504 this.topDict = dict;
54505 }
54506 obj = dict.get("XRefStm");
54507 if (Number.isInteger(obj) && !this._xrefStms.has(obj)) {
54508 this._xrefStms.add(obj);
54509 this.startXRefQueue.push(obj);
54510 this.#firstXRefStmPos ??= obj;
54511 }
54512 } else if (Number.isInteger(obj)) {
54513 if (!Number.isInteger(parser.getObj()) || !isCmd(parser.getObj(), "obj") || !((obj = parser.getObj()) instanceof BaseStream)) {
54514 throw new FormatError("Invalid XRef stream");
54515 }
54516 dict = this.processXRefStream(obj);
54517 if (!this.topDict) {
54518 this.topDict = dict;
54519 }
54520 if (!dict) {
54521 throw new FormatError("Failed to read XRef stream");
54522 }
54523 } else {
54524 throw new FormatError("Invalid XRef stream header");
54525 }
54526 obj = dict.get("Prev");
54527 if (Number.isInteger(obj)) {
54528 this.startXRefQueue.push(obj);
54529 } else if (obj instanceof Ref) {
54530 this.startXRefQueue.push(obj.num);
54531 }
54532 } catch (e) {
54533 if (e instanceof MissingDataException) {
54534 throw e;
54535 }
54536 info("(while reading XRef): " + e);
54537 }
54538 this.startXRefQueue.shift();
54539 }
54540 if (this.topDict) {
54541 return this.topDict;
54542 }
54543 if (recoveryMode) {
54544 return undefined;
54545 }
54546 throw new XRefParseException();
54547 }
54548 get lastXRefStreamPos() {
54549 return this.#firstXRefStmPos ?? (this._xrefStms.size > 0 ? Math.max(...this._xrefStms) : null);
54550 }
54551 getEntry(i) {
54552 const xrefEntry = this.entries[i];
54553 if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
54554 return xrefEntry;
54555 }
54556 return null;
54557 }
54558 fetchIfRef(obj, suppressEncryption = false) {
54559 if (obj instanceof Ref) {
54560 return this.fetch(obj, suppressEncryption);
54561 }
54562 return obj;
54563 }
54564 fetch(ref, suppressEncryption = false) {
54565 if (!(ref instanceof Ref)) {
54566 throw new Error("ref object is not a reference");
54567 }
54568 const num = ref.num;
54569 const cacheEntry = this._cacheMap.get(num);
54570 if (cacheEntry !== undefined) {
54571 if (cacheEntry instanceof Dict && !cacheEntry.objId) {
54572 cacheEntry.objId = ref.toString();
54573 }
54574 return cacheEntry;
54575 }
54576 let xrefEntry = this.getEntry(num);
54577 if (xrefEntry === null) {
54578 this._cacheMap.set(num, xrefEntry);
54579 return xrefEntry;
54580 }
54581 if (this._pendingRefs.has(ref)) {
54582 this._pendingRefs.remove(ref);
54583 warn(`Ignoring circular reference: ${ref}.`);
54584 return CIRCULAR_REF;
54585 }
54586 this._pendingRefs.put(ref);
54587 try {
54588 xrefEntry = xrefEntry.uncompressed ? this.fetchUncompressed(ref, xrefEntry, suppressEncryption) : this.fetchCompressed(ref, xrefEntry, suppressEncryption);
54589 this._pendingRefs.remove(ref);
54590 } catch (ex) {
54591 this._pendingRefs.remove(ref);
54592 throw ex;
54593 }
54594 if (xrefEntry instanceof Dict) {
54595 xrefEntry.objId = ref.toString();
54596 } else if (xrefEntry instanceof BaseStream) {
54597 xrefEntry.dict.objId = ref.toString();
54598 }
54599 return xrefEntry;
54600 }
54601 fetchUncompressed(ref, xrefEntry, suppressEncryption = false) {
54602 const gen = ref.gen;
54603 let num = ref.num;
54604 if (xrefEntry.gen !== gen) {
54605 const msg = `Inconsistent generation in XRef: ${ref}`;
54606 if (this._generationFallback && xrefEntry.gen < gen) {
54607 warn(msg);
54608 return this.fetchUncompressed(Ref.get(num, xrefEntry.gen), xrefEntry, suppressEncryption);
54609 }
54610 throw new XRefEntryException(msg);
54611 }
54612 const stream = this.stream.makeSubStream(xrefEntry.offset + this.stream.start);
54613 const parser = new Parser({
54614 lexer: new Lexer(stream),
54615 xref: this,
54616 allowStreams: true
54617 });
54618 const obj1 = parser.getObj();
54619 const obj2 = parser.getObj();
54620 const obj3 = parser.getObj();
54621 if (obj1 !== num || obj2 !== gen || !(obj3 instanceof Cmd)) {
54622 throw new XRefEntryException(`Bad (uncompressed) XRef entry: ${ref}`);
54623 }
54624 if (obj3.cmd !== "obj") {
54625 if (obj3.cmd.startsWith("obj")) {
54626 num = parseInt(obj3.cmd.substring(3), 10);
54627 if (!Number.isNaN(num)) {
54628 return num;
54629 }
54630 }
54631 throw new XRefEntryException(`Bad (uncompressed) XRef entry: ${ref}`);
54632 }
54633 xrefEntry = this.encrypt && !suppressEncryption ? parser.getObj(this.encrypt.createCipherTransform(num, gen)) : parser.getObj();
54634 if (!(xrefEntry instanceof BaseStream)) {
54635 this._cacheMap.set(num, xrefEntry);
54636 }
54637 return xrefEntry;
54638 }
54639 fetchCompressed(ref, xrefEntry, suppressEncryption = false) {
54640 const tableOffset = xrefEntry.offset;
54641 const stream = this.fetch(Ref.get(tableOffset, 0));
54642 if (!(stream instanceof BaseStream)) {
54643 throw new FormatError("bad ObjStm stream");
54644 }
54645 const first = stream.dict.get("First");
54646 const n = stream.dict.get("N");
54647 if (!Number.isInteger(first) || !Number.isInteger(n)) {
54648 throw new FormatError("invalid first and n parameters for ObjStm stream");
54649 }
54650 let parser = new Parser({
54651 lexer: new Lexer(stream),
54652 xref: this,
54653 allowStreams: true
54654 });
54655 const nums = new Array(n);
54656 const offsets = new Array(n);
54657 for (let i = 0; i < n; ++i) {
54658 const num = parser.getObj();
54659 if (!Number.isInteger(num)) {
54660 throw new FormatError(`invalid object number in the ObjStm stream: ${num}`);
54661 }
54662 const offset = parser.getObj();
54663 if (!Number.isInteger(offset)) {
54664 throw new FormatError(`invalid object offset in the ObjStm stream: ${offset}`);
54665 }
54666 nums[i] = num;
54667 offsets[i] = offset;
54668 }
54669 const start = (stream.start || 0) + first;
54670 const entries = new Array(n);
54671 for (let i = 0; i < n; ++i) {
54672 const length = i < n - 1 ? offsets[i + 1] - offsets[i] : undefined;
54673 if (length < 0) {
54674 throw new FormatError("Invalid offset in the ObjStm stream.");
54675 }
54676 parser = new Parser({
54677 lexer: new Lexer(stream.makeSubStream(start + offsets[i], length, stream.dict)),
54678 xref: this,
54679 allowStreams: true
54680 });
54681 const obj = parser.getObj();
54682 entries[i] = obj;
54683 if (obj instanceof BaseStream) {
54684 continue;
54685 }
54686 const num = nums[i],
54687 entry = this.entries[num];
54688 if (entry && entry.offset === tableOffset && entry.gen === i) {
54689 this._cacheMap.set(num, obj);
54690 }
54691 }
54692 xrefEntry = entries[xrefEntry.gen];
54693 if (xrefEntry === undefined) {
54694 throw new XRefEntryException(`Bad (compressed) XRef entry: ${ref}`);
54695 }
54696 return xrefEntry;
54697 }
54698 async fetchIfRefAsync(obj, suppressEncryption) {
54699 if (obj instanceof Ref) {
54700 return this.fetchAsync(obj, suppressEncryption);
54701 }
54702 return obj;
54703 }
54704 async fetchAsync(ref, suppressEncryption) {
54705 try {
54706 return this.fetch(ref, suppressEncryption);
54707 } catch (ex) {
54708 if (!(ex instanceof MissingDataException)) {
54709 throw ex;
54710 }
54711 await this.pdfManager.requestRange(ex.begin, ex.end);
54712 return this.fetchAsync(ref, suppressEncryption);
54713 }
54714 }
54715 getCatalogObj() {
54716 return this.root;
54717 }
54718}
54719
54720;// CONCATENATED MODULE: ./src/core/document.js
54721
54722
54723
54724
54725
54726
54727
54728
54729
54730
54731
54732
54733
54734
54735
54736
54737
54738
54739
54740
54741const DEFAULT_USER_UNIT = 1.0;
54742const LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
54743class Page {
54744 constructor({
54745 pdfManager,
54746 xref,
54747 pageIndex,
54748 pageDict,
54749 ref,
54750 globalIdFactory,
54751 fontCache,
54752 builtInCMapCache,
54753 standardFontDataCache,
54754 globalImageCache,
54755 systemFontCache,
54756 nonBlendModesSet,
54757 xfaFactory
54758 }) {
54759 this.pdfManager = pdfManager;
54760 this.pageIndex = pageIndex;
54761 this.pageDict = pageDict;
54762 this.xref = xref;
54763 this.ref = ref;
54764 this.fontCache = fontCache;
54765 this.builtInCMapCache = builtInCMapCache;
54766 this.standardFontDataCache = standardFontDataCache;
54767 this.globalImageCache = globalImageCache;
54768 this.systemFontCache = systemFontCache;
54769 this.nonBlendModesSet = nonBlendModesSet;
54770 this.evaluatorOptions = pdfManager.evaluatorOptions;
54771 this.resourcesPromise = null;
54772 this.xfaFactory = xfaFactory;
54773 const idCounters = {
54774 obj: 0
54775 };
54776 this._localIdFactory = class extends globalIdFactory {
54777 static createObjId() {
54778 return `p${pageIndex}_${++idCounters.obj}`;
54779 }
54780 static getPageObjId() {
54781 return `p${ref.toString()}`;
54782 }
54783 };
54784 }
54785 _getInheritableProperty(key, getArray = false) {
54786 const value = getInheritableProperty({
54787 dict: this.pageDict,
54788 key,
54789 getArray,
54790 stopWhenFound: false
54791 });
54792 if (!Array.isArray(value)) {
54793 return value;
54794 }
54795 if (value.length === 1 || !(value[0] instanceof Dict)) {
54796 return value[0];
54797 }
54798 return Dict.merge({
54799 xref: this.xref,
54800 dictArray: value
54801 });
54802 }
54803 get content() {
54804 return this.pageDict.getArray("Contents");
54805 }
54806 get resources() {
54807 const resources = this._getInheritableProperty("Resources");
54808 return shadow(this, "resources", resources instanceof Dict ? resources : Dict.empty);
54809 }
54810 _getBoundingBox(name) {
54811 if (this.xfaData) {
54812 return this.xfaData.bbox;
54813 }
54814 let box = this._getInheritableProperty(name, true);
54815 if (Array.isArray(box) && box.length === 4) {
54816 box = Util.normalizeRect(box);
54817 if (box[2] - box[0] > 0 && box[3] - box[1] > 0) {
54818 return box;
54819 }
54820 warn(`Empty, or invalid, /${name} entry.`);
54821 }
54822 return null;
54823 }
54824 get mediaBox() {
54825 return shadow(this, "mediaBox", this._getBoundingBox("MediaBox") || LETTER_SIZE_MEDIABOX);
54826 }
54827 get cropBox() {
54828 return shadow(this, "cropBox", this._getBoundingBox("CropBox") || this.mediaBox);
54829 }
54830 get userUnit() {
54831 let obj = this.pageDict.get("UserUnit");
54832 if (typeof obj !== "number" || obj <= 0) {
54833 obj = DEFAULT_USER_UNIT;
54834 }
54835 return shadow(this, "userUnit", obj);
54836 }
54837 get view() {
54838 const {
54839 cropBox,
54840 mediaBox
54841 } = this;
54842 if (cropBox !== mediaBox && !isArrayEqual(cropBox, mediaBox)) {
54843 const box = Util.intersect(cropBox, mediaBox);
54844 if (box && box[2] - box[0] > 0 && box[3] - box[1] > 0) {
54845 return shadow(this, "view", box);
54846 }
54847 warn("Empty /CropBox and /MediaBox intersection.");
54848 }
54849 return shadow(this, "view", mediaBox);
54850 }
54851 get rotate() {
54852 let rotate = this._getInheritableProperty("Rotate") || 0;
54853 if (rotate % 90 !== 0) {
54854 rotate = 0;
54855 } else if (rotate >= 360) {
54856 rotate %= 360;
54857 } else if (rotate < 0) {
54858 rotate = (rotate % 360 + 360) % 360;
54859 }
54860 return shadow(this, "rotate", rotate);
54861 }
54862 _onSubStreamError(reason, objId) {
54863 if (this.evaluatorOptions.ignoreErrors) {
54864 warn(`getContentStream - ignoring sub-stream (${objId}): "${reason}".`);
54865 return;
54866 }
54867 throw reason;
54868 }
54869 getContentStream() {
54870 return this.pdfManager.ensure(this, "content").then(content => {
54871 if (content instanceof BaseStream) {
54872 return content;
54873 }
54874 if (Array.isArray(content)) {
54875 return new StreamsSequenceStream(content, this._onSubStreamError.bind(this));
54876 }
54877 return new NullStream();
54878 });
54879 }
54880 get xfaData() {
54881 return shadow(this, "xfaData", this.xfaFactory ? {
54882 bbox: this.xfaFactory.getBoundingBox(this.pageIndex)
54883 } : null);
54884 }
54885 #replaceIdByRef(annotations, deletedAnnotations, existingAnnotations) {
54886 for (const annotation of annotations) {
54887 if (annotation.id) {
54888 const ref = Ref.fromString(annotation.id);
54889 if (!ref) {
54890 warn(`A non-linked annotation cannot be modified: ${annotation.id}`);
54891 continue;
54892 }
54893 if (annotation.deleted) {
54894 deletedAnnotations.put(ref);
54895 continue;
54896 }
54897 existingAnnotations?.put(ref);
54898 annotation.ref = ref;
54899 delete annotation.id;
54900 }
54901 }
54902 }
54903 async saveNewAnnotations(handler, task, annotations, imagePromises) {
54904 if (this.xfaFactory) {
54905 throw new Error("XFA: Cannot save new annotations.");
54906 }
54907 const partialEvaluator = new PartialEvaluator({
54908 xref: this.xref,
54909 handler,
54910 pageIndex: this.pageIndex,
54911 idFactory: this._localIdFactory,
54912 fontCache: this.fontCache,
54913 builtInCMapCache: this.builtInCMapCache,
54914 standardFontDataCache: this.standardFontDataCache,
54915 globalImageCache: this.globalImageCache,
54916 systemFontCache: this.systemFontCache,
54917 options: this.evaluatorOptions
54918 });
54919 const deletedAnnotations = new RefSet();
54920 const existingAnnotations = new RefSet();
54921 this.#replaceIdByRef(annotations, deletedAnnotations, existingAnnotations);
54922 const pageDict = this.pageDict;
54923 const annotationsArray = this.annotations.filter(a => !(a instanceof Ref && deletedAnnotations.has(a)));
54924 const newData = await AnnotationFactory.saveNewAnnotations(partialEvaluator, task, annotations, imagePromises);
54925 for (const {
54926 ref
54927 } of newData.annotations) {
54928 if (ref instanceof Ref && !existingAnnotations.has(ref)) {
54929 annotationsArray.push(ref);
54930 }
54931 }
54932 const savedDict = pageDict.get("Annots");
54933 pageDict.set("Annots", annotationsArray);
54934 const buffer = [];
54935 await writeObject(this.ref, pageDict, buffer, this.xref);
54936 if (savedDict) {
54937 pageDict.set("Annots", savedDict);
54938 }
54939 const objects = newData.dependencies;
54940 objects.push({
54941 ref: this.ref,
54942 data: buffer.join("")
54943 }, ...newData.annotations);
54944 return objects;
54945 }
54946 save(handler, task, annotationStorage) {
54947 const partialEvaluator = new PartialEvaluator({
54948 xref: this.xref,
54949 handler,
54950 pageIndex: this.pageIndex,
54951 idFactory: this._localIdFactory,
54952 fontCache: this.fontCache,
54953 builtInCMapCache: this.builtInCMapCache,
54954 standardFontDataCache: this.standardFontDataCache,
54955 globalImageCache: this.globalImageCache,
54956 systemFontCache: this.systemFontCache,
54957 options: this.evaluatorOptions
54958 });
54959 return this._parsedAnnotations.then(function (annotations) {
54960 const newRefsPromises = [];
54961 for (const annotation of annotations) {
54962 if (!annotation.mustBePrinted(annotationStorage)) {
54963 continue;
54964 }
54965 newRefsPromises.push(annotation.save(partialEvaluator, task, annotationStorage).catch(function (reason) {
54966 warn("save - ignoring annotation data during " + `"${task.name}" task: "${reason}".`);
54967 return null;
54968 }));
54969 }
54970 return Promise.all(newRefsPromises).then(function (newRefs) {
54971 return newRefs.filter(newRef => !!newRef);
54972 });
54973 });
54974 }
54975 loadResources(keys) {
54976 if (!this.resourcesPromise) {
54977 this.resourcesPromise = this.pdfManager.ensure(this, "resources");
54978 }
54979 return this.resourcesPromise.then(() => {
54980 const objectLoader = new ObjectLoader(this.resources, keys, this.xref);
54981 return objectLoader.load();
54982 });
54983 }
54984 getOperatorList({
54985 handler,
54986 sink,
54987 task,
54988 intent,
54989 cacheKey,
54990 annotationStorage = null
54991 }) {
54992 const contentStreamPromise = this.getContentStream();
54993 const resourcesPromise = this.loadResources(["ColorSpace", "ExtGState", "Font", "Pattern", "Properties", "Shading", "XObject"]);
54994 const partialEvaluator = new PartialEvaluator({
54995 xref: this.xref,
54996 handler,
54997 pageIndex: this.pageIndex,
54998 idFactory: this._localIdFactory,
54999 fontCache: this.fontCache,
55000 builtInCMapCache: this.builtInCMapCache,
55001 standardFontDataCache: this.standardFontDataCache,
55002 globalImageCache: this.globalImageCache,
55003 systemFontCache: this.systemFontCache,
55004 options: this.evaluatorOptions
55005 });
55006 const newAnnotationsByPage = !this.xfaFactory ? getNewAnnotationsMap(annotationStorage) : null;
55007 let deletedAnnotations = null;
55008 let newAnnotationsPromise = Promise.resolve(null);
55009 if (newAnnotationsByPage) {
55010 const newAnnotations = newAnnotationsByPage.get(this.pageIndex);
55011 if (newAnnotations) {
55012 const annotationGlobalsPromise = this.pdfManager.ensureDoc("annotationGlobals");
55013 let imagePromises;
55014 const missingBitmaps = new Set();
55015 for (const {
55016 bitmapId,
55017 bitmap
55018 } of newAnnotations) {
55019 if (bitmapId && !bitmap && !missingBitmaps.has(bitmapId)) {
55020 missingBitmaps.add(bitmapId);
55021 }
55022 }
55023 const {
55024 isOffscreenCanvasSupported
55025 } = this.evaluatorOptions;
55026 if (missingBitmaps.size > 0) {
55027 const annotationWithBitmaps = newAnnotations.slice();
55028 for (const [key, annotation] of annotationStorage) {
55029 if (!key.startsWith(AnnotationEditorPrefix)) {
55030 continue;
55031 }
55032 if (annotation.bitmap && missingBitmaps.has(annotation.bitmapId)) {
55033 annotationWithBitmaps.push(annotation);
55034 }
55035 }
55036 imagePromises = AnnotationFactory.generateImages(annotationWithBitmaps, this.xref, isOffscreenCanvasSupported);
55037 } else {
55038 imagePromises = AnnotationFactory.generateImages(newAnnotations, this.xref, isOffscreenCanvasSupported);
55039 }
55040 deletedAnnotations = new RefSet();
55041 this.#replaceIdByRef(newAnnotations, deletedAnnotations, null);
55042 newAnnotationsPromise = annotationGlobalsPromise.then(annotationGlobals => {
55043 if (!annotationGlobals) {
55044 return null;
55045 }
55046 return AnnotationFactory.printNewAnnotations(annotationGlobals, partialEvaluator, task, newAnnotations, imagePromises);
55047 });
55048 }
55049 }
55050 const dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
55051 const pageListPromise = dataPromises.then(([contentStream]) => {
55052 const opList = new OperatorList(intent, sink);
55053 handler.send("StartRenderPage", {
55054 transparency: partialEvaluator.hasBlendModes(this.resources, this.nonBlendModesSet),
55055 pageIndex: this.pageIndex,
55056 cacheKey
55057 });
55058 return partialEvaluator.getOperatorList({
55059 stream: contentStream,
55060 task,
55061 resources: this.resources,
55062 operatorList: opList
55063 }).then(function () {
55064 return opList;
55065 });
55066 });
55067 return Promise.all([pageListPromise, this._parsedAnnotations, newAnnotationsPromise]).then(function ([pageOpList, annotations, newAnnotations]) {
55068 if (newAnnotations) {
55069 annotations = annotations.filter(a => !(a.ref && deletedAnnotations.has(a.ref)));
55070 for (let i = 0, ii = newAnnotations.length; i < ii; i++) {
55071 const newAnnotation = newAnnotations[i];
55072 if (newAnnotation.refToReplace) {
55073 const j = annotations.findIndex(a => a.ref && isRefsEqual(a.ref, newAnnotation.refToReplace));
55074 if (j >= 0) {
55075 annotations.splice(j, 1, newAnnotation);
55076 newAnnotations.splice(i--, 1);
55077 ii--;
55078 }
55079 }
55080 }
55081 annotations = annotations.concat(newAnnotations);
55082 }
55083 if (annotations.length === 0 || intent & RenderingIntentFlag.ANNOTATIONS_DISABLE) {
55084 pageOpList.flush(true);
55085 return {
55086 length: pageOpList.totalLength
55087 };
55088 }
55089 const renderForms = !!(intent & RenderingIntentFlag.ANNOTATIONS_FORMS),
55090 intentAny = !!(intent & RenderingIntentFlag.ANY),
55091 intentDisplay = !!(intent & RenderingIntentFlag.DISPLAY),
55092 intentPrint = !!(intent & RenderingIntentFlag.PRINT);
55093 const opListPromises = [];
55094 for (const annotation of annotations) {
55095 if (intentAny || intentDisplay && annotation.mustBeViewed(annotationStorage, renderForms) || intentPrint && annotation.mustBePrinted(annotationStorage)) {
55096 opListPromises.push(annotation.getOperatorList(partialEvaluator, task, intent, renderForms, annotationStorage).catch(function (reason) {
55097 warn("getOperatorList - ignoring annotation data during " + `"${task.name}" task: "${reason}".`);
55098 return {
55099 opList: null,
55100 separateForm: false,
55101 separateCanvas: false
55102 };
55103 }));
55104 }
55105 }
55106 return Promise.all(opListPromises).then(function (opLists) {
55107 let form = false,
55108 canvas = false;
55109 for (const {
55110 opList,
55111 separateForm,
55112 separateCanvas
55113 } of opLists) {
55114 pageOpList.addOpList(opList);
55115 form ||= separateForm;
55116 canvas ||= separateCanvas;
55117 }
55118 pageOpList.flush(true, {
55119 form,
55120 canvas
55121 });
55122 return {
55123 length: pageOpList.totalLength
55124 };
55125 });
55126 });
55127 }
55128 extractTextContent({
55129 handler,
55130 task,
55131 includeMarkedContent,
55132 disableNormalization,
55133 sink
55134 }) {
55135 const contentStreamPromise = this.getContentStream();
55136 const resourcesPromise = this.loadResources(["ExtGState", "Font", "Properties", "XObject"]);
55137 const dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
55138 return dataPromises.then(([contentStream]) => {
55139 const partialEvaluator = new PartialEvaluator({
55140 xref: this.xref,
55141 handler,
55142 pageIndex: this.pageIndex,
55143 idFactory: this._localIdFactory,
55144 fontCache: this.fontCache,
55145 builtInCMapCache: this.builtInCMapCache,
55146 standardFontDataCache: this.standardFontDataCache,
55147 globalImageCache: this.globalImageCache,
55148 systemFontCache: this.systemFontCache,
55149 options: this.evaluatorOptions
55150 });
55151 return partialEvaluator.getTextContent({
55152 stream: contentStream,
55153 task,
55154 resources: this.resources,
55155 includeMarkedContent,
55156 disableNormalization,
55157 sink,
55158 viewBox: this.view
55159 });
55160 });
55161 }
55162 async getStructTree() {
55163 const structTreeRoot = await this.pdfManager.ensureCatalog("structTreeRoot");
55164 if (!structTreeRoot) {
55165 return null;
55166 }
55167 await this._parsedAnnotations;
55168 const structTree = await this.pdfManager.ensure(this, "_parseStructTree", [structTreeRoot]);
55169 return structTree.serializable;
55170 }
55171 _parseStructTree(structTreeRoot) {
55172 const tree = new StructTreePage(structTreeRoot, this.pageDict);
55173 tree.parse(this.ref);
55174 return tree;
55175 }
55176 async getAnnotationsData(handler, task, intent) {
55177 const annotations = await this._parsedAnnotations;
55178 if (annotations.length === 0) {
55179 return annotations;
55180 }
55181 const annotationsData = [],
55182 textContentPromises = [];
55183 let partialEvaluator;
55184 const intentAny = !!(intent & RenderingIntentFlag.ANY),
55185 intentDisplay = !!(intent & RenderingIntentFlag.DISPLAY),
55186 intentPrint = !!(intent & RenderingIntentFlag.PRINT);
55187 for (const annotation of annotations) {
55188 const isVisible = intentAny || intentDisplay && annotation.viewable;
55189 if (isVisible || intentPrint && annotation.printable) {
55190 annotationsData.push(annotation.data);
55191 }
55192 if (annotation.hasTextContent && isVisible) {
55193 partialEvaluator ||= new PartialEvaluator({
55194 xref: this.xref,
55195 handler,
55196 pageIndex: this.pageIndex,
55197 idFactory: this._localIdFactory,
55198 fontCache: this.fontCache,
55199 builtInCMapCache: this.builtInCMapCache,
55200 standardFontDataCache: this.standardFontDataCache,
55201 globalImageCache: this.globalImageCache,
55202 systemFontCache: this.systemFontCache,
55203 options: this.evaluatorOptions
55204 });
55205 textContentPromises.push(annotation.extractTextContent(partialEvaluator, task, [-Infinity, -Infinity, Infinity, Infinity]).catch(function (reason) {
55206 warn(`getAnnotationsData - ignoring textContent during "${task.name}" task: "${reason}".`);
55207 }));
55208 }
55209 }
55210 await Promise.all(textContentPromises);
55211 return annotationsData;
55212 }
55213 get annotations() {
55214 const annots = this._getInheritableProperty("Annots");
55215 return shadow(this, "annotations", Array.isArray(annots) ? annots : []);
55216 }
55217 get _parsedAnnotations() {
55218 const promise = this.pdfManager.ensure(this, "annotations").then(async annots => {
55219 if (annots.length === 0) {
55220 return annots;
55221 }
55222 const annotationGlobals = await this.pdfManager.ensureDoc("annotationGlobals");
55223 if (!annotationGlobals) {
55224 return [];
55225 }
55226 const annotationPromises = [];
55227 for (const annotationRef of annots) {
55228 annotationPromises.push(AnnotationFactory.create(this.xref, annotationRef, annotationGlobals, this._localIdFactory, false, this.ref).catch(function (reason) {
55229 warn(`_parsedAnnotations: "${reason}".`);
55230 return null;
55231 }));
55232 }
55233 const sortedAnnotations = [];
55234 let popupAnnotations, widgetAnnotations;
55235 for (const annotation of await Promise.all(annotationPromises)) {
55236 if (!annotation) {
55237 continue;
55238 }
55239 if (annotation instanceof WidgetAnnotation) {
55240 (widgetAnnotations ||= []).push(annotation);
55241 continue;
55242 }
55243 if (annotation instanceof PopupAnnotation) {
55244 (popupAnnotations ||= []).push(annotation);
55245 continue;
55246 }
55247 sortedAnnotations.push(annotation);
55248 }
55249 if (widgetAnnotations) {
55250 sortedAnnotations.push(...widgetAnnotations);
55251 }
55252 if (popupAnnotations) {
55253 sortedAnnotations.push(...popupAnnotations);
55254 }
55255 return sortedAnnotations;
55256 });
55257 return shadow(this, "_parsedAnnotations", promise);
55258 }
55259 get jsActions() {
55260 const actions = collectActions(this.xref, this.pageDict, PageActionEventType);
55261 return shadow(this, "jsActions", actions);
55262 }
55263}
55264const PDF_HEADER_SIGNATURE = new Uint8Array([0x25, 0x50, 0x44, 0x46, 0x2d]);
55265const STARTXREF_SIGNATURE = new Uint8Array([0x73, 0x74, 0x61, 0x72, 0x74, 0x78, 0x72, 0x65, 0x66]);
55266const ENDOBJ_SIGNATURE = new Uint8Array([0x65, 0x6e, 0x64, 0x6f, 0x62, 0x6a]);
55267const FINGERPRINT_FIRST_BYTES = 1024;
55268const EMPTY_FINGERPRINT = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
55269function find(stream, signature, limit = 1024, backwards = false) {
55270 const signatureLength = signature.length;
55271 const scanBytes = stream.peekBytes(limit);
55272 const scanLength = scanBytes.length - signatureLength;
55273 if (scanLength <= 0) {
55274 return false;
55275 }
55276 if (backwards) {
55277 const signatureEnd = signatureLength - 1;
55278 let pos = scanBytes.length - 1;
55279 while (pos >= signatureEnd) {
55280 let j = 0;
55281 while (j < signatureLength && scanBytes[pos - j] === signature[signatureEnd - j]) {
55282 j++;
55283 }
55284 if (j >= signatureLength) {
55285 stream.pos += pos - signatureEnd;
55286 return true;
55287 }
55288 pos--;
55289 }
55290 } else {
55291 let pos = 0;
55292 while (pos <= scanLength) {
55293 let j = 0;
55294 while (j < signatureLength && scanBytes[pos + j] === signature[j]) {
55295 j++;
55296 }
55297 if (j >= signatureLength) {
55298 stream.pos += pos;
55299 return true;
55300 }
55301 pos++;
55302 }
55303 }
55304 return false;
55305}
55306class PDFDocument {
55307 constructor(pdfManager, stream) {
55308 if (stream.length <= 0) {
55309 throw new InvalidPDFException("The PDF file is empty, i.e. its size is zero bytes.");
55310 }
55311 this.pdfManager = pdfManager;
55312 this.stream = stream;
55313 this.xref = new XRef(stream, pdfManager);
55314 this._pagePromises = new Map();
55315 this._version = null;
55316 const idCounters = {
55317 font: 0
55318 };
55319 this._globalIdFactory = class {
55320 static getDocId() {
55321 return `g_${pdfManager.docId}`;
55322 }
55323 static createFontId() {
55324 return `f${++idCounters.font}`;
55325 }
55326 static createObjId() {
55327 unreachable("Abstract method `createObjId` called.");
55328 }
55329 static getPageObjId() {
55330 unreachable("Abstract method `getPageObjId` called.");
55331 }
55332 };
55333 }
55334 parse(recoveryMode) {
55335 this.xref.parse(recoveryMode);
55336 this.catalog = new Catalog(this.pdfManager, this.xref);
55337 }
55338 get linearization() {
55339 let linearization = null;
55340 try {
55341 linearization = Linearization.create(this.stream);
55342 } catch (err) {
55343 if (err instanceof MissingDataException) {
55344 throw err;
55345 }
55346 info(err);
55347 }
55348 return shadow(this, "linearization", linearization);
55349 }
55350 get startXRef() {
55351 const stream = this.stream;
55352 let startXRef = 0;
55353 if (this.linearization) {
55354 stream.reset();
55355 if (find(stream, ENDOBJ_SIGNATURE)) {
55356 stream.skip(6);
55357 let ch = stream.peekByte();
55358 while (isWhiteSpace(ch)) {
55359 stream.pos++;
55360 ch = stream.peekByte();
55361 }
55362 startXRef = stream.pos - stream.start;
55363 }
55364 } else {
55365 const step = 1024;
55366 const startXRefLength = STARTXREF_SIGNATURE.length;
55367 let found = false,
55368 pos = stream.end;
55369 while (!found && pos > 0) {
55370 pos -= step - startXRefLength;
55371 if (pos < 0) {
55372 pos = 0;
55373 }
55374 stream.pos = pos;
55375 found = find(stream, STARTXREF_SIGNATURE, step, true);
55376 }
55377 if (found) {
55378 stream.skip(9);
55379 let ch;
55380 do {
55381 ch = stream.getByte();
55382 } while (isWhiteSpace(ch));
55383 let str = "";
55384 while (ch >= 0x20 && ch <= 0x39) {
55385 str += String.fromCharCode(ch);
55386 ch = stream.getByte();
55387 }
55388 startXRef = parseInt(str, 10);
55389 if (isNaN(startXRef)) {
55390 startXRef = 0;
55391 }
55392 }
55393 }
55394 return shadow(this, "startXRef", startXRef);
55395 }
55396 checkHeader() {
55397 const stream = this.stream;
55398 stream.reset();
55399 if (!find(stream, PDF_HEADER_SIGNATURE)) {
55400 return;
55401 }
55402 stream.moveStart();
55403 stream.skip(PDF_HEADER_SIGNATURE.length);
55404 let version = "",
55405 ch;
55406 while ((ch = stream.getByte()) > 0x20 && version.length < 7) {
55407 version += String.fromCharCode(ch);
55408 }
55409 if (PDF_VERSION_REGEXP.test(version)) {
55410 this._version = version;
55411 } else {
55412 warn(`Invalid PDF header version: ${version}`);
55413 }
55414 }
55415 parseStartXRef() {
55416 this.xref.setStartXRef(this.startXRef);
55417 }
55418 get numPages() {
55419 let num = 0;
55420 if (this.catalog.hasActualNumPages) {
55421 num = this.catalog.numPages;
55422 } else if (this.xfaFactory) {
55423 num = this.xfaFactory.getNumPages();
55424 } else if (this.linearization) {
55425 num = this.linearization.numPages;
55426 } else {
55427 num = this.catalog.numPages;
55428 }
55429 return shadow(this, "numPages", num);
55430 }
55431 _hasOnlyDocumentSignatures(fields, recursionDepth = 0) {
55432 const RECURSION_LIMIT = 10;
55433 if (!Array.isArray(fields)) {
55434 return false;
55435 }
55436 return fields.every(field => {
55437 field = this.xref.fetchIfRef(field);
55438 if (!(field instanceof Dict)) {
55439 return false;
55440 }
55441 if (field.has("Kids")) {
55442 if (++recursionDepth > RECURSION_LIMIT) {
55443 warn("_hasOnlyDocumentSignatures: maximum recursion depth reached");
55444 return false;
55445 }
55446 return this._hasOnlyDocumentSignatures(field.get("Kids"), recursionDepth);
55447 }
55448 const isSignature = isName(field.get("FT"), "Sig");
55449 const rectangle = field.get("Rect");
55450 const isInvisible = Array.isArray(rectangle) && rectangle.every(value => value === 0);
55451 return isSignature && isInvisible;
55452 });
55453 }
55454 get _xfaStreams() {
55455 const acroForm = this.catalog.acroForm;
55456 if (!acroForm) {
55457 return null;
55458 }
55459 const xfa = acroForm.get("XFA");
55460 const entries = {
55461 "xdp:xdp": "",
55462 template: "",
55463 datasets: "",
55464 config: "",
55465 connectionSet: "",
55466 localeSet: "",
55467 stylesheet: "",
55468 "/xdp:xdp": ""
55469 };
55470 if (xfa instanceof BaseStream && !xfa.isEmpty) {
55471 entries["xdp:xdp"] = xfa;
55472 return entries;
55473 }
55474 if (!Array.isArray(xfa) || xfa.length === 0) {
55475 return null;
55476 }
55477 for (let i = 0, ii = xfa.length; i < ii; i += 2) {
55478 let name;
55479 if (i === 0) {
55480 name = "xdp:xdp";
55481 } else if (i === ii - 2) {
55482 name = "/xdp:xdp";
55483 } else {
55484 name = xfa[i];
55485 }
55486 if (!entries.hasOwnProperty(name)) {
55487 continue;
55488 }
55489 const data = this.xref.fetchIfRef(xfa[i + 1]);
55490 if (!(data instanceof BaseStream) || data.isEmpty) {
55491 continue;
55492 }
55493 entries[name] = data;
55494 }
55495 return entries;
55496 }
55497 get xfaDatasets() {
55498 const streams = this._xfaStreams;
55499 if (!streams) {
55500 return shadow(this, "xfaDatasets", null);
55501 }
55502 for (const key of ["datasets", "xdp:xdp"]) {
55503 const stream = streams[key];
55504 if (!stream) {
55505 continue;
55506 }
55507 try {
55508 const str = stringToUTF8String(stream.getString());
55509 const data = {
55510 [key]: str
55511 };
55512 return shadow(this, "xfaDatasets", new DatasetReader(data));
55513 } catch {
55514 warn("XFA - Invalid utf-8 string.");
55515 break;
55516 }
55517 }
55518 return shadow(this, "xfaDatasets", null);
55519 }
55520 get xfaData() {
55521 const streams = this._xfaStreams;
55522 if (!streams) {
55523 return null;
55524 }
55525 const data = Object.create(null);
55526 for (const [key, stream] of Object.entries(streams)) {
55527 if (!stream) {
55528 continue;
55529 }
55530 try {
55531 data[key] = stringToUTF8String(stream.getString());
55532 } catch {
55533 warn("XFA - Invalid utf-8 string.");
55534 return null;
55535 }
55536 }
55537 return data;
55538 }
55539 get xfaFactory() {
55540 let data;
55541 if (this.pdfManager.enableXfa && this.catalog.needsRendering && this.formInfo.hasXfa && !this.formInfo.hasAcroForm) {
55542 data = this.xfaData;
55543 }
55544 return shadow(this, "xfaFactory", data ? new XFAFactory(data) : null);
55545 }
55546 get isPureXfa() {
55547 return this.xfaFactory ? this.xfaFactory.isValid() : false;
55548 }
55549 get htmlForXfa() {
55550 return this.xfaFactory ? this.xfaFactory.getPages() : null;
55551 }
55552 async loadXfaImages() {
55553 const xfaImagesDict = await this.pdfManager.ensureCatalog("xfaImages");
55554 if (!xfaImagesDict) {
55555 return;
55556 }
55557 const keys = xfaImagesDict.getKeys();
55558 const objectLoader = new ObjectLoader(xfaImagesDict, keys, this.xref);
55559 await objectLoader.load();
55560 const xfaImages = new Map();
55561 for (const key of keys) {
55562 const stream = xfaImagesDict.get(key);
55563 if (stream instanceof BaseStream) {
55564 xfaImages.set(key, stream.getBytes());
55565 }
55566 }
55567 this.xfaFactory.setImages(xfaImages);
55568 }
55569 async loadXfaFonts(handler, task) {
55570 const acroForm = await this.pdfManager.ensureCatalog("acroForm");
55571 if (!acroForm) {
55572 return;
55573 }
55574 const resources = await acroForm.getAsync("DR");
55575 if (!(resources instanceof Dict)) {
55576 return;
55577 }
55578 const objectLoader = new ObjectLoader(resources, ["Font"], this.xref);
55579 await objectLoader.load();
55580 const fontRes = resources.get("Font");
55581 if (!(fontRes instanceof Dict)) {
55582 return;
55583 }
55584 const options = Object.assign(Object.create(null), this.pdfManager.evaluatorOptions);
55585 options.useSystemFonts = false;
55586 const partialEvaluator = new PartialEvaluator({
55587 xref: this.xref,
55588 handler,
55589 pageIndex: -1,
55590 idFactory: this._globalIdFactory,
55591 fontCache: this.catalog.fontCache,
55592 builtInCMapCache: this.catalog.builtInCMapCache,
55593 standardFontDataCache: this.catalog.standardFontDataCache,
55594 options
55595 });
55596 const operatorList = new OperatorList();
55597 const pdfFonts = [];
55598 const initialState = {
55599 get font() {
55600 return pdfFonts.at(-1);
55601 },
55602 set font(font) {
55603 pdfFonts.push(font);
55604 },
55605 clone() {
55606 return this;
55607 }
55608 };
55609 const fonts = new Map();
55610 fontRes.forEach((fontName, font) => {
55611 fonts.set(fontName, font);
55612 });
55613 const promises = [];
55614 for (const [fontName, font] of fonts) {
55615 const descriptor = font.get("FontDescriptor");
55616 if (!(descriptor instanceof Dict)) {
55617 continue;
55618 }
55619 let fontFamily = descriptor.get("FontFamily");
55620 fontFamily = fontFamily.replaceAll(/[ ]+(\d)/g, "$1");
55621 const fontWeight = descriptor.get("FontWeight");
55622 const italicAngle = -descriptor.get("ItalicAngle");
55623 const cssFontInfo = {
55624 fontFamily,
55625 fontWeight,
55626 italicAngle
55627 };
55628 if (!validateCSSFont(cssFontInfo)) {
55629 continue;
55630 }
55631 promises.push(partialEvaluator.handleSetFont(resources, [Name.get(fontName), 1], null, operatorList, task, initialState, null, cssFontInfo).catch(function (reason) {
55632 warn(`loadXfaFonts: "${reason}".`);
55633 return null;
55634 }));
55635 }
55636 await Promise.all(promises);
55637 const missingFonts = this.xfaFactory.setFonts(pdfFonts);
55638 if (!missingFonts) {
55639 return;
55640 }
55641 options.ignoreErrors = true;
55642 promises.length = 0;
55643 pdfFonts.length = 0;
55644 const reallyMissingFonts = new Set();
55645 for (const missing of missingFonts) {
55646 if (!getXfaFontName(`${missing}-Regular`)) {
55647 reallyMissingFonts.add(missing);
55648 }
55649 }
55650 if (reallyMissingFonts.size) {
55651 missingFonts.push("PdfJS-Fallback");
55652 }
55653 for (const missing of missingFonts) {
55654 if (reallyMissingFonts.has(missing)) {
55655 continue;
55656 }
55657 for (const fontInfo of [{
55658 name: "Regular",
55659 fontWeight: 400,
55660 italicAngle: 0
55661 }, {
55662 name: "Bold",
55663 fontWeight: 700,
55664 italicAngle: 0
55665 }, {
55666 name: "Italic",
55667 fontWeight: 400,
55668 italicAngle: 12
55669 }, {
55670 name: "BoldItalic",
55671 fontWeight: 700,
55672 italicAngle: 12
55673 }]) {
55674 const name = `${missing}-${fontInfo.name}`;
55675 const dict = getXfaFontDict(name);
55676 promises.push(partialEvaluator.handleSetFont(resources, [Name.get(name), 1], null, operatorList, task, initialState, dict, {
55677 fontFamily: missing,
55678 fontWeight: fontInfo.fontWeight,
55679 italicAngle: fontInfo.italicAngle
55680 }).catch(function (reason) {
55681 warn(`loadXfaFonts: "${reason}".`);
55682 return null;
55683 }));
55684 }
55685 }
55686 await Promise.all(promises);
55687 this.xfaFactory.appendFonts(pdfFonts, reallyMissingFonts);
55688 }
55689 async serializeXfaData(annotationStorage) {
55690 return this.xfaFactory ? this.xfaFactory.serializeData(annotationStorage) : null;
55691 }
55692 get version() {
55693 return this.catalog.version || this._version;
55694 }
55695 get formInfo() {
55696 const formInfo = {
55697 hasFields: false,
55698 hasAcroForm: false,
55699 hasXfa: false,
55700 hasSignatures: false
55701 };
55702 const acroForm = this.catalog.acroForm;
55703 if (!acroForm) {
55704 return shadow(this, "formInfo", formInfo);
55705 }
55706 try {
55707 const fields = acroForm.get("Fields");
55708 const hasFields = Array.isArray(fields) && fields.length > 0;
55709 formInfo.hasFields = hasFields;
55710 const xfa = acroForm.get("XFA");
55711 formInfo.hasXfa = Array.isArray(xfa) && xfa.length > 0 || xfa instanceof BaseStream && !xfa.isEmpty;
55712 const sigFlags = acroForm.get("SigFlags");
55713 const hasSignatures = !!(sigFlags & 0x1);
55714 const hasOnlyDocumentSignatures = hasSignatures && this._hasOnlyDocumentSignatures(fields);
55715 formInfo.hasAcroForm = hasFields && !hasOnlyDocumentSignatures;
55716 formInfo.hasSignatures = hasSignatures;
55717 } catch (ex) {
55718 if (ex instanceof MissingDataException) {
55719 throw ex;
55720 }
55721 warn(`Cannot fetch form information: "${ex}".`);
55722 }
55723 return shadow(this, "formInfo", formInfo);
55724 }
55725 get documentInfo() {
55726 const docInfo = {
55727 PDFFormatVersion: this.version,
55728 Language: this.catalog.lang,
55729 EncryptFilterName: this.xref.encrypt ? this.xref.encrypt.filterName : null,
55730 IsLinearized: !!this.linearization,
55731 IsAcroFormPresent: this.formInfo.hasAcroForm,
55732 IsXFAPresent: this.formInfo.hasXfa,
55733 IsCollectionPresent: !!this.catalog.collection,
55734 IsSignaturesPresent: this.formInfo.hasSignatures
55735 };
55736 let infoDict;
55737 try {
55738 infoDict = this.xref.trailer.get("Info");
55739 } catch (err) {
55740 if (err instanceof MissingDataException) {
55741 throw err;
55742 }
55743 info("The document information dictionary is invalid.");
55744 }
55745 if (!(infoDict instanceof Dict)) {
55746 return shadow(this, "documentInfo", docInfo);
55747 }
55748 for (const key of infoDict.getKeys()) {
55749 const value = infoDict.get(key);
55750 switch (key) {
55751 case "Title":
55752 case "Author":
55753 case "Subject":
55754 case "Keywords":
55755 case "Creator":
55756 case "Producer":
55757 case "CreationDate":
55758 case "ModDate":
55759 if (typeof value === "string") {
55760 docInfo[key] = stringToPDFString(value);
55761 continue;
55762 }
55763 break;
55764 case "Trapped":
55765 if (value instanceof Name) {
55766 docInfo[key] = value;
55767 continue;
55768 }
55769 break;
55770 default:
55771 let customValue;
55772 switch (typeof value) {
55773 case "string":
55774 customValue = stringToPDFString(value);
55775 break;
55776 case "number":
55777 case "boolean":
55778 customValue = value;
55779 break;
55780 default:
55781 if (value instanceof Name) {
55782 customValue = value;
55783 }
55784 break;
55785 }
55786 if (customValue === undefined) {
55787 warn(`Bad value, for custom key "${key}", in Info: ${value}.`);
55788 continue;
55789 }
55790 if (!docInfo.Custom) {
55791 docInfo.Custom = Object.create(null);
55792 }
55793 docInfo.Custom[key] = customValue;
55794 continue;
55795 }
55796 warn(`Bad value, for key "${key}", in Info: ${value}.`);
55797 }
55798 return shadow(this, "documentInfo", docInfo);
55799 }
55800 get fingerprints() {
55801 function validate(data) {
55802 return typeof data === "string" && data.length > 0 && data !== EMPTY_FINGERPRINT;
55803 }
55804 function hexString(hash) {
55805 const buf = [];
55806 for (const num of hash) {
55807 const hex = num.toString(16);
55808 buf.push(hex.padStart(2, "0"));
55809 }
55810 return buf.join("");
55811 }
55812 const idArray = this.xref.trailer.get("ID");
55813 let hashOriginal, hashModified;
55814 if (Array.isArray(idArray) && validate(idArray[0])) {
55815 hashOriginal = stringToBytes(idArray[0]);
55816 if (idArray[1] !== idArray[0] && validate(idArray[1])) {
55817 hashModified = stringToBytes(idArray[1]);
55818 }
55819 } else {
55820 hashOriginal = calculateMD5(this.stream.getByteRange(0, FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
55821 }
55822 return shadow(this, "fingerprints", [hexString(hashOriginal), hashModified ? hexString(hashModified) : null]);
55823 }
55824 async _getLinearizationPage(pageIndex) {
55825 const {
55826 catalog,
55827 linearization,
55828 xref
55829 } = this;
55830 const ref = Ref.get(linearization.objectNumberFirst, 0);
55831 try {
55832 const obj = await xref.fetchAsync(ref);
55833 if (obj instanceof Dict) {
55834 let type = obj.getRaw("Type");
55835 if (type instanceof Ref) {
55836 type = await xref.fetchAsync(type);
55837 }
55838 if (isName(type, "Page") || !obj.has("Type") && !obj.has("Kids")) {
55839 if (!catalog.pageKidsCountCache.has(ref)) {
55840 catalog.pageKidsCountCache.put(ref, 1);
55841 }
55842 if (!catalog.pageIndexCache.has(ref)) {
55843 catalog.pageIndexCache.put(ref, 0);
55844 }
55845 return [obj, ref];
55846 }
55847 }
55848 throw new FormatError("The Linearization dictionary doesn't point to a valid Page dictionary.");
55849 } catch (reason) {
55850 warn(`_getLinearizationPage: "${reason.message}".`);
55851 return catalog.getPageDict(pageIndex);
55852 }
55853 }
55854 getPage(pageIndex) {
55855 const cachedPromise = this._pagePromises.get(pageIndex);
55856 if (cachedPromise) {
55857 return cachedPromise;
55858 }
55859 const {
55860 catalog,
55861 linearization,
55862 xfaFactory
55863 } = this;
55864 let promise;
55865 if (xfaFactory) {
55866 promise = Promise.resolve([Dict.empty, null]);
55867 } else if (linearization?.pageFirst === pageIndex) {
55868 promise = this._getLinearizationPage(pageIndex);
55869 } else {
55870 promise = catalog.getPageDict(pageIndex);
55871 }
55872 promise = promise.then(([pageDict, ref]) => {
55873 return new Page({
55874 pdfManager: this.pdfManager,
55875 xref: this.xref,
55876 pageIndex,
55877 pageDict,
55878 ref,
55879 globalIdFactory: this._globalIdFactory,
55880 fontCache: catalog.fontCache,
55881 builtInCMapCache: catalog.builtInCMapCache,
55882 standardFontDataCache: catalog.standardFontDataCache,
55883 globalImageCache: catalog.globalImageCache,
55884 systemFontCache: catalog.systemFontCache,
55885 nonBlendModesSet: catalog.nonBlendModesSet,
55886 xfaFactory
55887 });
55888 });
55889 this._pagePromises.set(pageIndex, promise);
55890 return promise;
55891 }
55892 async checkFirstPage(recoveryMode = false) {
55893 if (recoveryMode) {
55894 return;
55895 }
55896 try {
55897 await this.getPage(0);
55898 } catch (reason) {
55899 if (reason instanceof XRefEntryException) {
55900 this._pagePromises.delete(0);
55901 await this.cleanup();
55902 throw new XRefParseException();
55903 }
55904 }
55905 }
55906 async checkLastPage(recoveryMode = false) {
55907 const {
55908 catalog,
55909 pdfManager
55910 } = this;
55911 catalog.setActualNumPages();
55912 let numPages;
55913 try {
55914 await Promise.all([pdfManager.ensureDoc("xfaFactory"), pdfManager.ensureDoc("linearization"), pdfManager.ensureCatalog("numPages")]);
55915 if (this.xfaFactory) {
55916 return;
55917 } else if (this.linearization) {
55918 numPages = this.linearization.numPages;
55919 } else {
55920 numPages = catalog.numPages;
55921 }
55922 if (!Number.isInteger(numPages)) {
55923 throw new FormatError("Page count is not an integer.");
55924 } else if (numPages <= 1) {
55925 return;
55926 }
55927 await this.getPage(numPages - 1);
55928 } catch (reason) {
55929 this._pagePromises.delete(numPages - 1);
55930 await this.cleanup();
55931 if (reason instanceof XRefEntryException && !recoveryMode) {
55932 throw new XRefParseException();
55933 }
55934 warn(`checkLastPage - invalid /Pages tree /Count: ${numPages}.`);
55935 let pagesTree;
55936 try {
55937 pagesTree = await catalog.getAllPageDicts(recoveryMode);
55938 } catch (reasonAll) {
55939 if (reasonAll instanceof XRefEntryException && !recoveryMode) {
55940 throw new XRefParseException();
55941 }
55942 catalog.setActualNumPages(1);
55943 return;
55944 }
55945 for (const [pageIndex, [pageDict, ref]] of pagesTree) {
55946 let promise;
55947 if (pageDict instanceof Error) {
55948 promise = Promise.reject(pageDict);
55949 promise.catch(() => {});
55950 } else {
55951 promise = Promise.resolve(new Page({
55952 pdfManager,
55953 xref: this.xref,
55954 pageIndex,
55955 pageDict,
55956 ref,
55957 globalIdFactory: this._globalIdFactory,
55958 fontCache: catalog.fontCache,
55959 builtInCMapCache: catalog.builtInCMapCache,
55960 standardFontDataCache: catalog.standardFontDataCache,
55961 globalImageCache: catalog.globalImageCache,
55962 systemFontCache: catalog.systemFontCache,
55963 nonBlendModesSet: catalog.nonBlendModesSet,
55964 xfaFactory: null
55965 }));
55966 }
55967 this._pagePromises.set(pageIndex, promise);
55968 }
55969 catalog.setActualNumPages(pagesTree.size);
55970 }
55971 }
55972 fontFallback(id, handler) {
55973 return this.catalog.fontFallback(id, handler);
55974 }
55975 async cleanup(manuallyTriggered = false) {
55976 return this.catalog ? this.catalog.cleanup(manuallyTriggered) : clearGlobalCaches();
55977 }
55978 async #collectFieldObjects(name, fieldRef, promises, annotationGlobals, visitedRefs) {
55979 const {
55980 xref
55981 } = this;
55982 if (!(fieldRef instanceof Ref) || visitedRefs.has(fieldRef)) {
55983 return;
55984 }
55985 visitedRefs.put(fieldRef);
55986 const field = await xref.fetchAsync(fieldRef);
55987 if (!(field instanceof Dict)) {
55988 return;
55989 }
55990 if (field.has("T")) {
55991 const partName = stringToPDFString(await field.getAsync("T"));
55992 name = name === "" ? partName : `${name}.${partName}`;
55993 } else {
55994 let obj = field;
55995 while (true) {
55996 obj = obj.getRaw("Parent");
55997 if (obj instanceof Ref) {
55998 if (visitedRefs.has(obj)) {
55999 break;
56000 }
56001 obj = await xref.fetchAsync(obj);
56002 }
56003 if (!(obj instanceof Dict)) {
56004 break;
56005 }
56006 if (obj.has("T")) {
56007 const partName = stringToPDFString(await obj.getAsync("T"));
56008 name = name === "" ? partName : `${name}.${partName}`;
56009 break;
56010 }
56011 }
56012 }
56013 if (!promises.has(name)) {
56014 promises.set(name, []);
56015 }
56016 promises.get(name).push(AnnotationFactory.create(xref, fieldRef, annotationGlobals, null, true, null).then(annotation => annotation?.getFieldObject()).catch(function (reason) {
56017 warn(`#collectFieldObjects: "${reason}".`);
56018 return null;
56019 }));
56020 if (!field.has("Kids")) {
56021 return;
56022 }
56023 const kids = await field.getAsync("Kids");
56024 if (Array.isArray(kids)) {
56025 for (const kid of kids) {
56026 await this.#collectFieldObjects(name, kid, promises, annotationGlobals, visitedRefs);
56027 }
56028 }
56029 }
56030 get fieldObjects() {
56031 if (!this.formInfo.hasFields) {
56032 return shadow(this, "fieldObjects", Promise.resolve(null));
56033 }
56034 const promise = Promise.all([this.pdfManager.ensureDoc("annotationGlobals"), this.pdfManager.ensureCatalog("acroForm")]).then(async ([annotationGlobals, acroForm]) => {
56035 if (!annotationGlobals) {
56036 return null;
56037 }
56038 const visitedRefs = new RefSet();
56039 const allFields = Object.create(null);
56040 const fieldPromises = new Map();
56041 for (const fieldRef of await acroForm.getAsync("Fields")) {
56042 await this.#collectFieldObjects("", fieldRef, fieldPromises, annotationGlobals, visitedRefs);
56043 }
56044 const allPromises = [];
56045 for (const [name, promises] of fieldPromises) {
56046 allPromises.push(Promise.all(promises).then(fields => {
56047 fields = fields.filter(field => !!field);
56048 if (fields.length > 0) {
56049 allFields[name] = fields;
56050 }
56051 }));
56052 }
56053 await Promise.all(allPromises);
56054 return allFields;
56055 });
56056 return shadow(this, "fieldObjects", promise);
56057 }
56058 get hasJSActions() {
56059 const promise = this.pdfManager.ensureDoc("_parseHasJSActions");
56060 return shadow(this, "hasJSActions", promise);
56061 }
56062 async _parseHasJSActions() {
56063 const [catalogJsActions, fieldObjects] = await Promise.all([this.pdfManager.ensureCatalog("jsActions"), this.pdfManager.ensureDoc("fieldObjects")]);
56064 if (catalogJsActions) {
56065 return true;
56066 }
56067 if (fieldObjects) {
56068 return Object.values(fieldObjects).some(fieldObject => fieldObject.some(object => object.actions !== null));
56069 }
56070 return false;
56071 }
56072 get calculationOrderIds() {
56073 const acroForm = this.catalog.acroForm;
56074 if (!acroForm?.has("CO")) {
56075 return shadow(this, "calculationOrderIds", null);
56076 }
56077 const calculationOrder = acroForm.get("CO");
56078 if (!Array.isArray(calculationOrder) || calculationOrder.length === 0) {
56079 return shadow(this, "calculationOrderIds", null);
56080 }
56081 const ids = [];
56082 for (const id of calculationOrder) {
56083 if (id instanceof Ref) {
56084 ids.push(id.toString());
56085 }
56086 }
56087 if (ids.length === 0) {
56088 return shadow(this, "calculationOrderIds", null);
56089 }
56090 return shadow(this, "calculationOrderIds", ids);
56091 }
56092 get annotationGlobals() {
56093 return shadow(this, "annotationGlobals", AnnotationFactory.createGlobals(this.pdfManager));
56094 }
56095}
56096
56097;// CONCATENATED MODULE: ./src/core/pdf_manager.js
56098
56099
56100
56101
56102
56103function parseDocBaseUrl(url) {
56104 if (url) {
56105 const absoluteUrl = createValidAbsoluteUrl(url);
56106 if (absoluteUrl) {
56107 return absoluteUrl.href;
56108 }
56109 warn(`Invalid absolute docBaseUrl: "${url}".`);
56110 }
56111 return null;
56112}
56113class BasePdfManager {
56114 constructor(args) {
56115 if (this.constructor === BasePdfManager) {
56116 unreachable("Cannot initialize BasePdfManager.");
56117 }
56118 this._docBaseUrl = parseDocBaseUrl(args.docBaseUrl);
56119 this._docId = args.docId;
56120 this._password = args.password;
56121 this.enableXfa = args.enableXfa;
56122 args.evaluatorOptions.isOffscreenCanvasSupported &&= FeatureTest.isOffscreenCanvasSupported;
56123 this.evaluatorOptions = args.evaluatorOptions;
56124 }
56125 get docId() {
56126 return this._docId;
56127 }
56128 get password() {
56129 return this._password;
56130 }
56131 get docBaseUrl() {
56132 return this._docBaseUrl;
56133 }
56134 get catalog() {
56135 return this.pdfDocument.catalog;
56136 }
56137 ensureDoc(prop, args) {
56138 return this.ensure(this.pdfDocument, prop, args);
56139 }
56140 ensureXRef(prop, args) {
56141 return this.ensure(this.pdfDocument.xref, prop, args);
56142 }
56143 ensureCatalog(prop, args) {
56144 return this.ensure(this.pdfDocument.catalog, prop, args);
56145 }
56146 getPage(pageIndex) {
56147 return this.pdfDocument.getPage(pageIndex);
56148 }
56149 fontFallback(id, handler) {
56150 return this.pdfDocument.fontFallback(id, handler);
56151 }
56152 loadXfaFonts(handler, task) {
56153 return this.pdfDocument.loadXfaFonts(handler, task);
56154 }
56155 loadXfaImages() {
56156 return this.pdfDocument.loadXfaImages();
56157 }
56158 serializeXfaData(annotationStorage) {
56159 return this.pdfDocument.serializeXfaData(annotationStorage);
56160 }
56161 cleanup(manuallyTriggered = false) {
56162 return this.pdfDocument.cleanup(manuallyTriggered);
56163 }
56164 async ensure(obj, prop, args) {
56165 unreachable("Abstract method `ensure` called");
56166 }
56167 requestRange(begin, end) {
56168 unreachable("Abstract method `requestRange` called");
56169 }
56170 requestLoadedStream(noFetch = false) {
56171 unreachable("Abstract method `requestLoadedStream` called");
56172 }
56173 sendProgressiveData(chunk) {
56174 unreachable("Abstract method `sendProgressiveData` called");
56175 }
56176 updatePassword(password) {
56177 this._password = password;
56178 }
56179 terminate(reason) {
56180 unreachable("Abstract method `terminate` called");
56181 }
56182}
56183class LocalPdfManager extends BasePdfManager {
56184 constructor(args) {
56185 super(args);
56186 const stream = new Stream(args.source);
56187 this.pdfDocument = new PDFDocument(this, stream);
56188 this._loadedStreamPromise = Promise.resolve(stream);
56189 }
56190 async ensure(obj, prop, args) {
56191 const value = obj[prop];
56192 if (typeof value === "function") {
56193 return value.apply(obj, args);
56194 }
56195 return value;
56196 }
56197 requestRange(begin, end) {
56198 return Promise.resolve();
56199 }
56200 requestLoadedStream(noFetch = false) {
56201 return this._loadedStreamPromise;
56202 }
56203 terminate(reason) {}
56204}
56205class NetworkPdfManager extends BasePdfManager {
56206 constructor(args) {
56207 super(args);
56208 this.streamManager = new ChunkedStreamManager(args.source, {
56209 msgHandler: args.handler,
56210 length: args.length,
56211 disableAutoFetch: args.disableAutoFetch,
56212 rangeChunkSize: args.rangeChunkSize
56213 });
56214 this.pdfDocument = new PDFDocument(this, this.streamManager.getStream());
56215 }
56216 async ensure(obj, prop, args) {
56217 try {
56218 const value = obj[prop];
56219 if (typeof value === "function") {
56220 return value.apply(obj, args);
56221 }
56222 return value;
56223 } catch (ex) {
56224 if (!(ex instanceof MissingDataException)) {
56225 throw ex;
56226 }
56227 await this.requestRange(ex.begin, ex.end);
56228 return this.ensure(obj, prop, args);
56229 }
56230 }
56231 requestRange(begin, end) {
56232 return this.streamManager.requestRange(begin, end);
56233 }
56234 requestLoadedStream(noFetch = false) {
56235 return this.streamManager.requestAllChunks(noFetch);
56236 }
56237 sendProgressiveData(chunk) {
56238 this.streamManager.onReceiveData({
56239 chunk
56240 });
56241 }
56242 terminate(reason) {
56243 this.streamManager.abort(reason);
56244 }
56245}
56246
56247;// CONCATENATED MODULE: ./src/shared/message_handler.js
56248
56249const CallbackKind = {
56250 UNKNOWN: 0,
56251 DATA: 1,
56252 ERROR: 2
56253};
56254const StreamKind = {
56255 UNKNOWN: 0,
56256 CANCEL: 1,
56257 CANCEL_COMPLETE: 2,
56258 CLOSE: 3,
56259 ENQUEUE: 4,
56260 ERROR: 5,
56261 PULL: 6,
56262 PULL_COMPLETE: 7,
56263 START_COMPLETE: 8
56264};
56265function wrapReason(reason) {
56266 if (!(reason instanceof Error || typeof reason === "object" && reason !== null)) {
56267 unreachable('wrapReason: Expected "reason" to be a (possibly cloned) Error.');
56268 }
56269 switch (reason.name) {
56270 case "AbortException":
56271 return new AbortException(reason.message);
56272 case "MissingPDFException":
56273 return new MissingPDFException(reason.message);
56274 case "PasswordException":
56275 return new PasswordException(reason.message, reason.code);
56276 case "UnexpectedResponseException":
56277 return new UnexpectedResponseException(reason.message, reason.status);
56278 case "UnknownErrorException":
56279 return new UnknownErrorException(reason.message, reason.details);
56280 default:
56281 return new UnknownErrorException(reason.message, reason.toString());
56282 }
56283}
56284class MessageHandler {
56285 constructor(sourceName, targetName, comObj) {
56286 this.sourceName = sourceName;
56287 this.targetName = targetName;
56288 this.comObj = comObj;
56289 this.callbackId = 1;
56290 this.streamId = 1;
56291 this.streamSinks = Object.create(null);
56292 this.streamControllers = Object.create(null);
56293 this.callbackCapabilities = Object.create(null);
56294 this.actionHandler = Object.create(null);
56295 this._onComObjOnMessage = event => {
56296 const data = event.data;
56297 if (data.targetName !== this.sourceName) {
56298 return;
56299 }
56300 if (data.stream) {
56301 this.#processStreamMessage(data);
56302 return;
56303 }
56304 if (data.callback) {
56305 const callbackId = data.callbackId;
56306 const capability = this.callbackCapabilities[callbackId];
56307 if (!capability) {
56308 throw new Error(`Cannot resolve callback ${callbackId}`);
56309 }
56310 delete this.callbackCapabilities[callbackId];
56311 if (data.callback === CallbackKind.DATA) {
56312 capability.resolve(data.data);
56313 } else if (data.callback === CallbackKind.ERROR) {
56314 capability.reject(wrapReason(data.reason));
56315 } else {
56316 throw new Error("Unexpected callback case");
56317 }
56318 return;
56319 }
56320 const action = this.actionHandler[data.action];
56321 if (!action) {
56322 throw new Error(`Unknown action from worker: ${data.action}`);
56323 }
56324 if (data.callbackId) {
56325 const cbSourceName = this.sourceName;
56326 const cbTargetName = data.sourceName;
56327 new Promise(function (resolve) {
56328 resolve(action(data.data));
56329 }).then(function (result) {
56330 comObj.postMessage({
56331 sourceName: cbSourceName,
56332 targetName: cbTargetName,
56333 callback: CallbackKind.DATA,
56334 callbackId: data.callbackId,
56335 data: result
56336 });
56337 }, function (reason) {
56338 comObj.postMessage({
56339 sourceName: cbSourceName,
56340 targetName: cbTargetName,
56341 callback: CallbackKind.ERROR,
56342 callbackId: data.callbackId,
56343 reason: wrapReason(reason)
56344 });
56345 });
56346 return;
56347 }
56348 if (data.streamId) {
56349 this.#createStreamSink(data);
56350 return;
56351 }
56352 action(data.data);
56353 };
56354 comObj.addEventListener("message", this._onComObjOnMessage);
56355 }
56356 on(actionName, handler) {
56357 const ah = this.actionHandler;
56358 if (ah[actionName]) {
56359 throw new Error(`There is already an actionName called "${actionName}"`);
56360 }
56361 ah[actionName] = handler;
56362 }
56363 send(actionName, data, transfers) {
56364 this.comObj.postMessage({
56365 sourceName: this.sourceName,
56366 targetName: this.targetName,
56367 action: actionName,
56368 data
56369 }, transfers);
56370 }
56371 sendWithPromise(actionName, data, transfers) {
56372 const callbackId = this.callbackId++;
56373 const capability = Promise.withResolvers();
56374 this.callbackCapabilities[callbackId] = capability;
56375 try {
56376 this.comObj.postMessage({
56377 sourceName: this.sourceName,
56378 targetName: this.targetName,
56379 action: actionName,
56380 callbackId,
56381 data
56382 }, transfers);
56383 } catch (ex) {
56384 capability.reject(ex);
56385 }
56386 return capability.promise;
56387 }
56388 sendWithStream(actionName, data, queueingStrategy, transfers) {
56389 const streamId = this.streamId++,
56390 sourceName = this.sourceName,
56391 targetName = this.targetName,
56392 comObj = this.comObj;
56393 return new ReadableStream({
56394 start: controller => {
56395 const startCapability = Promise.withResolvers();
56396 this.streamControllers[streamId] = {
56397 controller,
56398 startCall: startCapability,
56399 pullCall: null,
56400 cancelCall: null,
56401 isClosed: false
56402 };
56403 comObj.postMessage({
56404 sourceName,
56405 targetName,
56406 action: actionName,
56407 streamId,
56408 data,
56409 desiredSize: controller.desiredSize
56410 }, transfers);
56411 return startCapability.promise;
56412 },
56413 pull: controller => {
56414 const pullCapability = Promise.withResolvers();
56415 this.streamControllers[streamId].pullCall = pullCapability;
56416 comObj.postMessage({
56417 sourceName,
56418 targetName,
56419 stream: StreamKind.PULL,
56420 streamId,
56421 desiredSize: controller.desiredSize
56422 });
56423 return pullCapability.promise;
56424 },
56425 cancel: reason => {
56426 assert(reason instanceof Error, "cancel must have a valid reason");
56427 const cancelCapability = Promise.withResolvers();
56428 this.streamControllers[streamId].cancelCall = cancelCapability;
56429 this.streamControllers[streamId].isClosed = true;
56430 comObj.postMessage({
56431 sourceName,
56432 targetName,
56433 stream: StreamKind.CANCEL,
56434 streamId,
56435 reason: wrapReason(reason)
56436 });
56437 return cancelCapability.promise;
56438 }
56439 }, queueingStrategy);
56440 }
56441 #createStreamSink(data) {
56442 const streamId = data.streamId,
56443 sourceName = this.sourceName,
56444 targetName = data.sourceName,
56445 comObj = this.comObj;
56446 const self = this,
56447 action = this.actionHandler[data.action];
56448 const streamSink = {
56449 enqueue(chunk, size = 1, transfers) {
56450 if (this.isCancelled) {
56451 return;
56452 }
56453 const lastDesiredSize = this.desiredSize;
56454 this.desiredSize -= size;
56455 if (lastDesiredSize > 0 && this.desiredSize <= 0) {
56456 this.sinkCapability = Promise.withResolvers();
56457 this.ready = this.sinkCapability.promise;
56458 }
56459 comObj.postMessage({
56460 sourceName,
56461 targetName,
56462 stream: StreamKind.ENQUEUE,
56463 streamId,
56464 chunk
56465 }, transfers);
56466 },
56467 close() {
56468 if (this.isCancelled) {
56469 return;
56470 }
56471 this.isCancelled = true;
56472 comObj.postMessage({
56473 sourceName,
56474 targetName,
56475 stream: StreamKind.CLOSE,
56476 streamId
56477 });
56478 delete self.streamSinks[streamId];
56479 },
56480 error(reason) {
56481 assert(reason instanceof Error, "error must have a valid reason");
56482 if (this.isCancelled) {
56483 return;
56484 }
56485 this.isCancelled = true;
56486 comObj.postMessage({
56487 sourceName,
56488 targetName,
56489 stream: StreamKind.ERROR,
56490 streamId,
56491 reason: wrapReason(reason)
56492 });
56493 },
56494 sinkCapability: Promise.withResolvers(),
56495 onPull: null,
56496 onCancel: null,
56497 isCancelled: false,
56498 desiredSize: data.desiredSize,
56499 ready: null
56500 };
56501 streamSink.sinkCapability.resolve();
56502 streamSink.ready = streamSink.sinkCapability.promise;
56503 this.streamSinks[streamId] = streamSink;
56504 new Promise(function (resolve) {
56505 resolve(action(data.data, streamSink));
56506 }).then(function () {
56507 comObj.postMessage({
56508 sourceName,
56509 targetName,
56510 stream: StreamKind.START_COMPLETE,
56511 streamId,
56512 success: true
56513 });
56514 }, function (reason) {
56515 comObj.postMessage({
56516 sourceName,
56517 targetName,
56518 stream: StreamKind.START_COMPLETE,
56519 streamId,
56520 reason: wrapReason(reason)
56521 });
56522 });
56523 }
56524 #processStreamMessage(data) {
56525 const streamId = data.streamId,
56526 sourceName = this.sourceName,
56527 targetName = data.sourceName,
56528 comObj = this.comObj;
56529 const streamController = this.streamControllers[streamId],
56530 streamSink = this.streamSinks[streamId];
56531 switch (data.stream) {
56532 case StreamKind.START_COMPLETE:
56533 if (data.success) {
56534 streamController.startCall.resolve();
56535 } else {
56536 streamController.startCall.reject(wrapReason(data.reason));
56537 }
56538 break;
56539 case StreamKind.PULL_COMPLETE:
56540 if (data.success) {
56541 streamController.pullCall.resolve();
56542 } else {
56543 streamController.pullCall.reject(wrapReason(data.reason));
56544 }
56545 break;
56546 case StreamKind.PULL:
56547 if (!streamSink) {
56548 comObj.postMessage({
56549 sourceName,
56550 targetName,
56551 stream: StreamKind.PULL_COMPLETE,
56552 streamId,
56553 success: true
56554 });
56555 break;
56556 }
56557 if (streamSink.desiredSize <= 0 && data.desiredSize > 0) {
56558 streamSink.sinkCapability.resolve();
56559 }
56560 streamSink.desiredSize = data.desiredSize;
56561 new Promise(function (resolve) {
56562 resolve(streamSink.onPull?.());
56563 }).then(function () {
56564 comObj.postMessage({
56565 sourceName,
56566 targetName,
56567 stream: StreamKind.PULL_COMPLETE,
56568 streamId,
56569 success: true
56570 });
56571 }, function (reason) {
56572 comObj.postMessage({
56573 sourceName,
56574 targetName,
56575 stream: StreamKind.PULL_COMPLETE,
56576 streamId,
56577 reason: wrapReason(reason)
56578 });
56579 });
56580 break;
56581 case StreamKind.ENQUEUE:
56582 assert(streamController, "enqueue should have stream controller");
56583 if (streamController.isClosed) {
56584 break;
56585 }
56586 streamController.controller.enqueue(data.chunk);
56587 break;
56588 case StreamKind.CLOSE:
56589 assert(streamController, "close should have stream controller");
56590 if (streamController.isClosed) {
56591 break;
56592 }
56593 streamController.isClosed = true;
56594 streamController.controller.close();
56595 this.#deleteStreamController(streamController, streamId);
56596 break;
56597 case StreamKind.ERROR:
56598 assert(streamController, "error should have stream controller");
56599 streamController.controller.error(wrapReason(data.reason));
56600 this.#deleteStreamController(streamController, streamId);
56601 break;
56602 case StreamKind.CANCEL_COMPLETE:
56603 if (data.success) {
56604 streamController.cancelCall.resolve();
56605 } else {
56606 streamController.cancelCall.reject(wrapReason(data.reason));
56607 }
56608 this.#deleteStreamController(streamController, streamId);
56609 break;
56610 case StreamKind.CANCEL:
56611 if (!streamSink) {
56612 break;
56613 }
56614 new Promise(function (resolve) {
56615 resolve(streamSink.onCancel?.(wrapReason(data.reason)));
56616 }).then(function () {
56617 comObj.postMessage({
56618 sourceName,
56619 targetName,
56620 stream: StreamKind.CANCEL_COMPLETE,
56621 streamId,
56622 success: true
56623 });
56624 }, function (reason) {
56625 comObj.postMessage({
56626 sourceName,
56627 targetName,
56628 stream: StreamKind.CANCEL_COMPLETE,
56629 streamId,
56630 reason: wrapReason(reason)
56631 });
56632 });
56633 streamSink.sinkCapability.reject(wrapReason(data.reason));
56634 streamSink.isCancelled = true;
56635 delete this.streamSinks[streamId];
56636 break;
56637 default:
56638 throw new Error("Unexpected stream case");
56639 }
56640 }
56641 async #deleteStreamController(streamController, streamId) {
56642 await Promise.allSettled([streamController.startCall?.promise, streamController.pullCall?.promise, streamController.cancelCall?.promise]);
56643 delete this.streamControllers[streamId];
56644 }
56645 destroy() {
56646 this.comObj.removeEventListener("message", this._onComObjOnMessage);
56647 }
56648}
56649
56650;// CONCATENATED MODULE: ./src/core/worker_stream.js
56651
56652class PDFWorkerStream {
56653 constructor(msgHandler) {
56654 this._msgHandler = msgHandler;
56655 this._contentLength = null;
56656 this._fullRequestReader = null;
56657 this._rangeRequestReaders = [];
56658 }
56659 getFullReader() {
56660 assert(!this._fullRequestReader, "PDFWorkerStream.getFullReader can only be called once.");
56661 this._fullRequestReader = new PDFWorkerStreamReader(this._msgHandler);
56662 return this._fullRequestReader;
56663 }
56664 getRangeReader(begin, end) {
56665 const reader = new PDFWorkerStreamRangeReader(begin, end, this._msgHandler);
56666 this._rangeRequestReaders.push(reader);
56667 return reader;
56668 }
56669 cancelAllRequests(reason) {
56670 this._fullRequestReader?.cancel(reason);
56671 for (const reader of this._rangeRequestReaders.slice(0)) {
56672 reader.cancel(reason);
56673 }
56674 }
56675}
56676class PDFWorkerStreamReader {
56677 constructor(msgHandler) {
56678 this._msgHandler = msgHandler;
56679 this.onProgress = null;
56680 this._contentLength = null;
56681 this._isRangeSupported = false;
56682 this._isStreamingSupported = false;
56683 const readableStream = this._msgHandler.sendWithStream("GetReader");
56684 this._reader = readableStream.getReader();
56685 this._headersReady = this._msgHandler.sendWithPromise("ReaderHeadersReady").then(data => {
56686 this._isStreamingSupported = data.isStreamingSupported;
56687 this._isRangeSupported = data.isRangeSupported;
56688 this._contentLength = data.contentLength;
56689 });
56690 }
56691 get headersReady() {
56692 return this._headersReady;
56693 }
56694 get contentLength() {
56695 return this._contentLength;
56696 }
56697 get isStreamingSupported() {
56698 return this._isStreamingSupported;
56699 }
56700 get isRangeSupported() {
56701 return this._isRangeSupported;
56702 }
56703 async read() {
56704 const {
56705 value,
56706 done
56707 } = await this._reader.read();
56708 if (done) {
56709 return {
56710 value: undefined,
56711 done: true
56712 };
56713 }
56714 return {
56715 value: value.buffer,
56716 done: false
56717 };
56718 }
56719 cancel(reason) {
56720 this._reader.cancel(reason);
56721 }
56722}
56723class PDFWorkerStreamRangeReader {
56724 constructor(begin, end, msgHandler) {
56725 this._msgHandler = msgHandler;
56726 this.onProgress = null;
56727 const readableStream = this._msgHandler.sendWithStream("GetRangeReader", {
56728 begin,
56729 end
56730 });
56731 this._reader = readableStream.getReader();
56732 }
56733 get isStreamingSupported() {
56734 return false;
56735 }
56736 async read() {
56737 const {
56738 value,
56739 done
56740 } = await this._reader.read();
56741 if (done) {
56742 return {
56743 value: undefined,
56744 done: true
56745 };
56746 }
56747 return {
56748 value: value.buffer,
56749 done: false
56750 };
56751 }
56752 cancel(reason) {
56753 this._reader.cancel(reason);
56754 }
56755}
56756
56757;// CONCATENATED MODULE: ./src/core/worker.js
56758
56759
56760
56761
56762
56763
56764
56765
56766
56767
56768class WorkerTask {
56769 constructor(name) {
56770 this.name = name;
56771 this.terminated = false;
56772 this._capability = Promise.withResolvers();
56773 }
56774 get finished() {
56775 return this._capability.promise;
56776 }
56777 finish() {
56778 this._capability.resolve();
56779 }
56780 terminate() {
56781 this.terminated = true;
56782 }
56783 ensureNotTerminated() {
56784 if (this.terminated) {
56785 throw new Error("Worker task was terminated");
56786 }
56787 }
56788}
56789class WorkerMessageHandler {
56790 static setup(handler, port) {
56791 let testMessageProcessed = false;
56792 handler.on("test", function (data) {
56793 if (testMessageProcessed) {
56794 return;
56795 }
56796 testMessageProcessed = true;
56797 handler.send("test", data instanceof Uint8Array);
56798 });
56799 handler.on("configure", function (data) {
56800 setVerbosityLevel(data.verbosity);
56801 });
56802 handler.on("GetDocRequest", function (data) {
56803 return WorkerMessageHandler.createDocumentHandler(data, port);
56804 });
56805 }
56806 static createDocumentHandler(docParams, port) {
56807 let pdfManager;
56808 let terminated = false;
56809 let cancelXHRs = null;
56810 const WorkerTasks = new Set();
56811 const verbosity = getVerbosityLevel();
56812 const {
56813 docId,
56814 apiVersion
56815 } = docParams;
56816 const workerVersion = "4.1.392";
56817 if (apiVersion !== workerVersion) {
56818 throw new Error(`The API version "${apiVersion}" does not match ` + `the Worker version "${workerVersion}".`);
56819 }
56820 const enumerableProperties = [];
56821 for (const property in []) {
56822 enumerableProperties.push(property);
56823 }
56824 if (enumerableProperties.length) {
56825 throw new Error("The `Array.prototype` contains unexpected enumerable properties: " + enumerableProperties.join(", ") + "; thus breaking e.g. `for...in` iteration of `Array`s.");
56826 }
56827 const workerHandlerName = docId + "_worker";
56828 let handler = new MessageHandler(workerHandlerName, docId, port);
56829 function ensureNotTerminated() {
56830 if (terminated) {
56831 throw new Error("Worker was terminated");
56832 }
56833 }
56834 function startWorkerTask(task) {
56835 WorkerTasks.add(task);
56836 }
56837 function finishWorkerTask(task) {
56838 task.finish();
56839 WorkerTasks.delete(task);
56840 }
56841 async function loadDocument(recoveryMode) {
56842 await pdfManager.ensureDoc("checkHeader");
56843 await pdfManager.ensureDoc("parseStartXRef");
56844 await pdfManager.ensureDoc("parse", [recoveryMode]);
56845 await pdfManager.ensureDoc("checkFirstPage", [recoveryMode]);
56846 await pdfManager.ensureDoc("checkLastPage", [recoveryMode]);
56847 const isPureXfa = await pdfManager.ensureDoc("isPureXfa");
56848 if (isPureXfa) {
56849 const task = new WorkerTask("loadXfaFonts");
56850 startWorkerTask(task);
56851 await Promise.all([pdfManager.loadXfaFonts(handler, task).catch(reason => {}).then(() => finishWorkerTask(task)), pdfManager.loadXfaImages()]);
56852 }
56853 const [numPages, fingerprints] = await Promise.all([pdfManager.ensureDoc("numPages"), pdfManager.ensureDoc("fingerprints")]);
56854 const htmlForXfa = isPureXfa ? await pdfManager.ensureDoc("htmlForXfa") : null;
56855 return {
56856 numPages,
56857 fingerprints,
56858 htmlForXfa
56859 };
56860 }
56861 function getPdfManager({
56862 data,
56863 password,
56864 disableAutoFetch,
56865 rangeChunkSize,
56866 length,
56867 docBaseUrl,
56868 enableXfa,
56869 evaluatorOptions
56870 }) {
56871 const pdfManagerArgs = {
56872 source: null,
56873 disableAutoFetch,
56874 docBaseUrl,
56875 docId,
56876 enableXfa,
56877 evaluatorOptions,
56878 handler,
56879 length,
56880 password,
56881 rangeChunkSize
56882 };
56883 const pdfManagerCapability = Promise.withResolvers();
56884 let newPdfManager;
56885 if (data) {
56886 try {
56887 pdfManagerArgs.source = data;
56888 newPdfManager = new LocalPdfManager(pdfManagerArgs);
56889 pdfManagerCapability.resolve(newPdfManager);
56890 } catch (ex) {
56891 pdfManagerCapability.reject(ex);
56892 }
56893 return pdfManagerCapability.promise;
56894 }
56895 let pdfStream,
56896 cachedChunks = [];
56897 try {
56898 pdfStream = new PDFWorkerStream(handler);
56899 } catch (ex) {
56900 pdfManagerCapability.reject(ex);
56901 return pdfManagerCapability.promise;
56902 }
56903 const fullRequest = pdfStream.getFullReader();
56904 fullRequest.headersReady.then(function () {
56905 if (!fullRequest.isRangeSupported) {
56906 return;
56907 }
56908 pdfManagerArgs.source = pdfStream;
56909 pdfManagerArgs.length = fullRequest.contentLength;
56910 pdfManagerArgs.disableAutoFetch ||= fullRequest.isStreamingSupported;
56911 newPdfManager = new NetworkPdfManager(pdfManagerArgs);
56912 for (const chunk of cachedChunks) {
56913 newPdfManager.sendProgressiveData(chunk);
56914 }
56915 cachedChunks = [];
56916 pdfManagerCapability.resolve(newPdfManager);
56917 cancelXHRs = null;
56918 }).catch(function (reason) {
56919 pdfManagerCapability.reject(reason);
56920 cancelXHRs = null;
56921 });
56922 let loaded = 0;
56923 const flushChunks = function () {
56924 const pdfFile = arrayBuffersToBytes(cachedChunks);
56925 if (length && pdfFile.length !== length) {
56926 warn("reported HTTP length is different from actual");
56927 }
56928 try {
56929 pdfManagerArgs.source = pdfFile;
56930 newPdfManager = new LocalPdfManager(pdfManagerArgs);
56931 pdfManagerCapability.resolve(newPdfManager);
56932 } catch (ex) {
56933 pdfManagerCapability.reject(ex);
56934 }
56935 cachedChunks = [];
56936 };
56937 new Promise(function (resolve, reject) {
56938 const readChunk = function ({
56939 value,
56940 done
56941 }) {
56942 try {
56943 ensureNotTerminated();
56944 if (done) {
56945 if (!newPdfManager) {
56946 flushChunks();
56947 }
56948 cancelXHRs = null;
56949 return;
56950 }
56951 loaded += value.byteLength;
56952 if (!fullRequest.isStreamingSupported) {
56953 handler.send("DocProgress", {
56954 loaded,
56955 total: Math.max(loaded, fullRequest.contentLength || 0)
56956 });
56957 }
56958 if (newPdfManager) {
56959 newPdfManager.sendProgressiveData(value);
56960 } else {
56961 cachedChunks.push(value);
56962 }
56963 fullRequest.read().then(readChunk, reject);
56964 } catch (e) {
56965 reject(e);
56966 }
56967 };
56968 fullRequest.read().then(readChunk, reject);
56969 }).catch(function (e) {
56970 pdfManagerCapability.reject(e);
56971 cancelXHRs = null;
56972 });
56973 cancelXHRs = function (reason) {
56974 pdfStream.cancelAllRequests(reason);
56975 };
56976 return pdfManagerCapability.promise;
56977 }
56978 function setupDoc(data) {
56979 function onSuccess(doc) {
56980 ensureNotTerminated();
56981 handler.send("GetDoc", {
56982 pdfInfo: doc
56983 });
56984 }
56985 function onFailure(ex) {
56986 ensureNotTerminated();
56987 if (ex instanceof PasswordException) {
56988 const task = new WorkerTask(`PasswordException: response ${ex.code}`);
56989 startWorkerTask(task);
56990 handler.sendWithPromise("PasswordRequest", ex).then(function ({
56991 password
56992 }) {
56993 finishWorkerTask(task);
56994 pdfManager.updatePassword(password);
56995 pdfManagerReady();
56996 }).catch(function () {
56997 finishWorkerTask(task);
56998 handler.send("DocException", ex);
56999 });
57000 } else if (ex instanceof InvalidPDFException || ex instanceof MissingPDFException || ex instanceof UnexpectedResponseException || ex instanceof UnknownErrorException) {
57001 handler.send("DocException", ex);
57002 } else {
57003 handler.send("DocException", new UnknownErrorException(ex.message, ex.toString()));
57004 }
57005 }
57006 function pdfManagerReady() {
57007 ensureNotTerminated();
57008 loadDocument(false).then(onSuccess, function (reason) {
57009 ensureNotTerminated();
57010 if (!(reason instanceof XRefParseException)) {
57011 onFailure(reason);
57012 return;
57013 }
57014 pdfManager.requestLoadedStream().then(function () {
57015 ensureNotTerminated();
57016 loadDocument(true).then(onSuccess, onFailure);
57017 });
57018 });
57019 }
57020 ensureNotTerminated();
57021 getPdfManager(data).then(function (newPdfManager) {
57022 if (terminated) {
57023 newPdfManager.terminate(new AbortException("Worker was terminated."));
57024 throw new Error("Worker was terminated");
57025 }
57026 pdfManager = newPdfManager;
57027 pdfManager.requestLoadedStream(true).then(stream => {
57028 handler.send("DataLoaded", {
57029 length: stream.bytes.byteLength
57030 });
57031 });
57032 }).then(pdfManagerReady, onFailure);
57033 }
57034 handler.on("GetPage", function (data) {
57035 return pdfManager.getPage(data.pageIndex).then(function (page) {
57036 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]) {
57037 return {
57038 rotate,
57039 ref,
57040 userUnit,
57041 view
57042 };
57043 });
57044 });
57045 });
57046 handler.on("GetPageIndex", function (data) {
57047 const pageRef = Ref.get(data.num, data.gen);
57048 return pdfManager.ensureCatalog("getPageIndex", [pageRef]);
57049 });
57050 handler.on("GetDestinations", function (data) {
57051 return pdfManager.ensureCatalog("destinations");
57052 });
57053 handler.on("GetDestination", function (data) {
57054 return pdfManager.ensureCatalog("getDestination", [data.id]);
57055 });
57056 handler.on("GetPageLabels", function (data) {
57057 return pdfManager.ensureCatalog("pageLabels");
57058 });
57059 handler.on("GetPageLayout", function (data) {
57060 return pdfManager.ensureCatalog("pageLayout");
57061 });
57062 handler.on("GetPageMode", function (data) {
57063 return pdfManager.ensureCatalog("pageMode");
57064 });
57065 handler.on("GetViewerPreferences", function (data) {
57066 return pdfManager.ensureCatalog("viewerPreferences");
57067 });
57068 handler.on("GetOpenAction", function (data) {
57069 return pdfManager.ensureCatalog("openAction");
57070 });
57071 handler.on("GetAttachments", function (data) {
57072 return pdfManager.ensureCatalog("attachments");
57073 });
57074 handler.on("GetDocJSActions", function (data) {
57075 return pdfManager.ensureCatalog("jsActions");
57076 });
57077 handler.on("GetPageJSActions", function ({
57078 pageIndex
57079 }) {
57080 return pdfManager.getPage(pageIndex).then(function (page) {
57081 return pdfManager.ensure(page, "jsActions");
57082 });
57083 });
57084 handler.on("GetOutline", function (data) {
57085 return pdfManager.ensureCatalog("documentOutline");
57086 });
57087 handler.on("GetOptionalContentConfig", function (data) {
57088 return pdfManager.ensureCatalog("optionalContentConfig");
57089 });
57090 handler.on("GetPermissions", function (data) {
57091 return pdfManager.ensureCatalog("permissions");
57092 });
57093 handler.on("GetMetadata", function (data) {
57094 return Promise.all([pdfManager.ensureDoc("documentInfo"), pdfManager.ensureCatalog("metadata")]);
57095 });
57096 handler.on("GetMarkInfo", function (data) {
57097 return pdfManager.ensureCatalog("markInfo");
57098 });
57099 handler.on("GetData", function (data) {
57100 return pdfManager.requestLoadedStream().then(function (stream) {
57101 return stream.bytes;
57102 });
57103 });
57104 handler.on("GetAnnotations", function ({
57105 pageIndex,
57106 intent
57107 }) {
57108 return pdfManager.getPage(pageIndex).then(function (page) {
57109 const task = new WorkerTask(`GetAnnotations: page ${pageIndex}`);
57110 startWorkerTask(task);
57111 return page.getAnnotationsData(handler, task, intent).then(data => {
57112 finishWorkerTask(task);
57113 return data;
57114 }, reason => {
57115 finishWorkerTask(task);
57116 throw reason;
57117 });
57118 });
57119 });
57120 handler.on("GetFieldObjects", function (data) {
57121 return pdfManager.ensureDoc("fieldObjects");
57122 });
57123 handler.on("HasJSActions", function (data) {
57124 return pdfManager.ensureDoc("hasJSActions");
57125 });
57126 handler.on("GetCalculationOrderIds", function (data) {
57127 return pdfManager.ensureDoc("calculationOrderIds");
57128 });
57129 handler.on("SaveDocument", async function ({
57130 isPureXfa,
57131 numPages,
57132 annotationStorage,
57133 filename
57134 }) {
57135 const globalPromises = [pdfManager.requestLoadedStream(), pdfManager.ensureCatalog("acroForm"), pdfManager.ensureCatalog("acroFormRef"), pdfManager.ensureDoc("startXRef"), pdfManager.ensureDoc("xref"), pdfManager.ensureDoc("linearization"), pdfManager.ensureCatalog("structTreeRoot")];
57136 const promises = [];
57137 const newAnnotationsByPage = !isPureXfa ? getNewAnnotationsMap(annotationStorage) : null;
57138 const [stream, acroForm, acroFormRef, startXRef, xref, linearization, _structTreeRoot] = await Promise.all(globalPromises);
57139 const catalogRef = xref.trailer.getRaw("Root") || null;
57140 let structTreeRoot;
57141 if (newAnnotationsByPage) {
57142 if (!_structTreeRoot) {
57143 if (await StructTreeRoot.canCreateStructureTree({
57144 catalogRef,
57145 pdfManager,
57146 newAnnotationsByPage
57147 })) {
57148 structTreeRoot = null;
57149 }
57150 } else if (await _structTreeRoot.canUpdateStructTree({
57151 pdfManager,
57152 xref,
57153 newAnnotationsByPage
57154 })) {
57155 structTreeRoot = _structTreeRoot;
57156 }
57157 const imagePromises = AnnotationFactory.generateImages(annotationStorage.values(), xref, pdfManager.evaluatorOptions.isOffscreenCanvasSupported);
57158 const newAnnotationPromises = structTreeRoot === undefined ? promises : [];
57159 for (const [pageIndex, annotations] of newAnnotationsByPage) {
57160 newAnnotationPromises.push(pdfManager.getPage(pageIndex).then(page => {
57161 const task = new WorkerTask(`Save (editor): page ${pageIndex}`);
57162 return page.saveNewAnnotations(handler, task, annotations, imagePromises).finally(function () {
57163 finishWorkerTask(task);
57164 });
57165 }));
57166 }
57167 if (structTreeRoot === null) {
57168 promises.push(Promise.all(newAnnotationPromises).then(async newRefs => {
57169 await StructTreeRoot.createStructureTree({
57170 newAnnotationsByPage,
57171 xref,
57172 catalogRef,
57173 pdfManager,
57174 newRefs
57175 });
57176 return newRefs;
57177 }));
57178 } else if (structTreeRoot) {
57179 promises.push(Promise.all(newAnnotationPromises).then(async newRefs => {
57180 await structTreeRoot.updateStructureTree({
57181 newAnnotationsByPage,
57182 pdfManager,
57183 newRefs
57184 });
57185 return newRefs;
57186 }));
57187 }
57188 }
57189 if (isPureXfa) {
57190 promises.push(pdfManager.serializeXfaData(annotationStorage));
57191 } else {
57192 for (let pageIndex = 0; pageIndex < numPages; pageIndex++) {
57193 promises.push(pdfManager.getPage(pageIndex).then(function (page) {
57194 const task = new WorkerTask(`Save: page ${pageIndex}`);
57195 return page.save(handler, task, annotationStorage).finally(function () {
57196 finishWorkerTask(task);
57197 });
57198 }));
57199 }
57200 }
57201 const refs = await Promise.all(promises);
57202 let newRefs = [];
57203 let xfaData = null;
57204 if (isPureXfa) {
57205 xfaData = refs[0];
57206 if (!xfaData) {
57207 return stream.bytes;
57208 }
57209 } else {
57210 newRefs = refs.flat(2);
57211 if (newRefs.length === 0) {
57212 return stream.bytes;
57213 }
57214 }
57215 const needAppearances = acroFormRef && acroForm instanceof Dict && newRefs.some(ref => ref.needAppearances);
57216 const xfa = acroForm instanceof Dict && acroForm.get("XFA") || null;
57217 let xfaDatasetsRef = null;
57218 let hasXfaDatasetsEntry = false;
57219 if (Array.isArray(xfa)) {
57220 for (let i = 0, ii = xfa.length; i < ii; i += 2) {
57221 if (xfa[i] === "datasets") {
57222 xfaDatasetsRef = xfa[i + 1];
57223 hasXfaDatasetsEntry = true;
57224 }
57225 }
57226 if (xfaDatasetsRef === null) {
57227 xfaDatasetsRef = xref.getNewTemporaryRef();
57228 }
57229 } else if (xfa) {
57230 warn("Unsupported XFA type.");
57231 }
57232 let newXrefInfo = Object.create(null);
57233 if (xref.trailer) {
57234 const infoObj = Object.create(null);
57235 const xrefInfo = xref.trailer.get("Info") || null;
57236 if (xrefInfo instanceof Dict) {
57237 xrefInfo.forEach((key, value) => {
57238 if (typeof value === "string") {
57239 infoObj[key] = stringToPDFString(value);
57240 }
57241 });
57242 }
57243 newXrefInfo = {
57244 rootRef: catalogRef,
57245 encryptRef: xref.trailer.getRaw("Encrypt") || null,
57246 newRef: xref.getNewTemporaryRef(),
57247 infoRef: xref.trailer.getRaw("Info") || null,
57248 info: infoObj,
57249 fileIds: xref.trailer.get("ID") || null,
57250 startXRef: linearization ? startXRef : xref.lastXRefStreamPos ?? startXRef,
57251 filename
57252 };
57253 }
57254 return incrementalUpdate({
57255 originalData: stream.bytes,
57256 xrefInfo: newXrefInfo,
57257 newRefs,
57258 xref,
57259 hasXfa: !!xfa,
57260 xfaDatasetsRef,
57261 hasXfaDatasetsEntry,
57262 needAppearances,
57263 acroFormRef,
57264 acroForm,
57265 xfaData,
57266 useXrefStream: isDict(xref.topDict, "XRef")
57267 }).finally(() => {
57268 xref.resetNewTemporaryRef();
57269 });
57270 });
57271 handler.on("GetOperatorList", function (data, sink) {
57272 const pageIndex = data.pageIndex;
57273 pdfManager.getPage(pageIndex).then(function (page) {
57274 const task = new WorkerTask(`GetOperatorList: page ${pageIndex}`);
57275 startWorkerTask(task);
57276 const start = verbosity >= VerbosityLevel.INFOS ? Date.now() : 0;
57277 page.getOperatorList({
57278 handler,
57279 sink,
57280 task,
57281 intent: data.intent,
57282 cacheKey: data.cacheKey,
57283 annotationStorage: data.annotationStorage
57284 }).then(function (operatorListInfo) {
57285 finishWorkerTask(task);
57286 if (start) {
57287 info(`page=${pageIndex + 1} - getOperatorList: time=` + `${Date.now() - start}ms, len=${operatorListInfo.length}`);
57288 }
57289 sink.close();
57290 }, function (reason) {
57291 finishWorkerTask(task);
57292 if (task.terminated) {
57293 return;
57294 }
57295 sink.error(reason);
57296 });
57297 });
57298 });
57299 handler.on("GetTextContent", function (data, sink) {
57300 const {
57301 pageIndex,
57302 includeMarkedContent,
57303 disableNormalization
57304 } = data;
57305 pdfManager.getPage(pageIndex).then(function (page) {
57306 const task = new WorkerTask("GetTextContent: page " + pageIndex);
57307 startWorkerTask(task);
57308 const start = verbosity >= VerbosityLevel.INFOS ? Date.now() : 0;
57309 page.extractTextContent({
57310 handler,
57311 task,
57312 sink,
57313 includeMarkedContent,
57314 disableNormalization
57315 }).then(function () {
57316 finishWorkerTask(task);
57317 if (start) {
57318 info(`page=${pageIndex + 1} - getTextContent: time=` + `${Date.now() - start}ms`);
57319 }
57320 sink.close();
57321 }, function (reason) {
57322 finishWorkerTask(task);
57323 if (task.terminated) {
57324 return;
57325 }
57326 sink.error(reason);
57327 });
57328 });
57329 });
57330 handler.on("GetStructTree", function (data) {
57331 return pdfManager.getPage(data.pageIndex).then(function (page) {
57332 return pdfManager.ensure(page, "getStructTree");
57333 });
57334 });
57335 handler.on("FontFallback", function (data) {
57336 return pdfManager.fontFallback(data.id, handler);
57337 });
57338 handler.on("Cleanup", function (data) {
57339 return pdfManager.cleanup(true);
57340 });
57341 handler.on("Terminate", function (data) {
57342 terminated = true;
57343 const waitOn = [];
57344 if (pdfManager) {
57345 pdfManager.terminate(new AbortException("Worker was terminated."));
57346 const cleanupPromise = pdfManager.cleanup();
57347 waitOn.push(cleanupPromise);
57348 pdfManager = null;
57349 } else {
57350 clearGlobalCaches();
57351 }
57352 if (cancelXHRs) {
57353 cancelXHRs(new AbortException("Worker was terminated."));
57354 }
57355 for (const task of WorkerTasks) {
57356 waitOn.push(task.finished);
57357 task.terminate();
57358 }
57359 return Promise.all(waitOn).then(function () {
57360 handler.destroy();
57361 handler = null;
57362 });
57363 });
57364 handler.on("Ready", function (data) {
57365 setupDoc(docParams);
57366 docParams = null;
57367 });
57368 return workerHandlerName;
57369 }
57370 static initializeFromPort(port) {
57371 const handler = new MessageHandler("worker", "main", port);
57372 WorkerMessageHandler.setup(handler, port);
57373 handler.send("ready", null);
57374 }
57375}
57376function isMessagePort(maybePort) {
57377 return typeof maybePort.postMessage === "function" && "onmessage" in maybePort;
57378}
57379if (typeof window === "undefined" && !isNodeJS && typeof self !== "undefined" && isMessagePort(self)) {
57380 WorkerMessageHandler.initializeFromPort(self);
57381}
57382
57383;// CONCATENATED MODULE: ./src/pdf.worker.js
57384
57385const pdfjsVersion = "4.1.392";
57386const pdfjsBuild = "fcb76a78d";
57387
57388var __webpack_exports__WorkerMessageHandler = __webpack_exports__.WorkerMessageHandler;
57389export { __webpack_exports__WorkerMessageHandler as WorkerMessageHandler };
57390
57391//# sourceMappingURL=pdf.worker.mjs.map
\No newline at end of file