pdf-codec 1.6.0 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. package/README.md +67 -9
  2. package/dist/cff-bounds.cjs +432 -0
  3. package/dist/cff-bounds.d.cts +9 -0
  4. package/dist/cff-bounds.d.ts +9 -0
  5. package/dist/cff-bounds.js +431 -0
  6. package/dist/cff-probe.cjs +8 -106
  7. package/dist/cff-probe.js +9 -107
  8. package/dist/cff.cjs +158 -0
  9. package/dist/cff.d.cts +17 -0
  10. package/dist/cff.d.ts +17 -0
  11. package/dist/cff.js +150 -0
  12. package/dist/filters.cjs +45 -2
  13. package/dist/filters.d.cts +4 -3
  14. package/dist/filters.d.ts +4 -3
  15. package/dist/filters.js +45 -2
  16. package/dist/formula.d.cts +1 -1
  17. package/dist/formula.d.ts +1 -1
  18. package/dist/glyf.cjs +62 -6
  19. package/dist/glyf.d.cts +2 -0
  20. package/dist/glyf.d.ts +2 -0
  21. package/dist/glyf.js +62 -6
  22. package/dist/glyph-bounds-BV_Z40KS.d.cts +10 -0
  23. package/dist/glyph-bounds-BV_Z40KS.d.ts +10 -0
  24. package/dist/glyph-bounds.cjs +12 -0
  25. package/dist/glyph-bounds.d.cts +2 -0
  26. package/dist/glyph-bounds.d.ts +2 -0
  27. package/dist/glyph-bounds.js +11 -0
  28. package/dist/image/jbig2-arith.cjs +432 -0
  29. package/dist/image/jbig2-arith.d.cts +23 -0
  30. package/dist/image/jbig2-arith.d.ts +23 -0
  31. package/dist/image/jbig2-arith.js +426 -0
  32. package/dist/image/jbig2-bitmap.cjs +80 -0
  33. package/dist/image/jbig2-bitmap.d.cts +20 -0
  34. package/dist/image/jbig2-bitmap.d.ts +20 -0
  35. package/dist/image/jbig2-bitmap.js +72 -0
  36. package/dist/image/jbig2-errors.cjs +17 -0
  37. package/dist/image/jbig2-errors.d.cts +2 -0
  38. package/dist/image/jbig2-errors.d.ts +2 -0
  39. package/dist/image/jbig2-errors.js +15 -0
  40. package/dist/image/jbig2-generic.cjs +242 -0
  41. package/dist/image/jbig2-generic.d.cts +27 -0
  42. package/dist/image/jbig2-generic.d.ts +27 -0
  43. package/dist/image/jbig2-generic.js +237 -0
  44. package/dist/image/jbig2-text.cjs +175 -0
  45. package/dist/image/jbig2-text.d.cts +58 -0
  46. package/dist/image/jbig2-text.d.ts +58 -0
  47. package/dist/image/jbig2-text.js +170 -0
  48. package/dist/image/jbig2.cjs +333 -0
  49. package/dist/image/jbig2.d.cts +15 -0
  50. package/dist/image/jbig2.d.ts +15 -0
  51. package/dist/image/jbig2.js +332 -0
  52. package/dist/image/jp2-boxes.cjs +148 -0
  53. package/dist/image/jp2-boxes.d.cts +26 -0
  54. package/dist/image/jp2-boxes.d.ts +26 -0
  55. package/dist/image/jp2-boxes.js +146 -0
  56. package/dist/image/jpeg2000-codestream.cjs +309 -0
  57. package/dist/image/jpeg2000-codestream.d.cts +78 -0
  58. package/dist/image/jpeg2000-codestream.d.ts +78 -0
  59. package/dist/image/jpeg2000-codestream.js +308 -0
  60. package/dist/image/jpeg2000-dwt.cjs +148 -0
  61. package/dist/image/jpeg2000-dwt.d.cts +34 -0
  62. package/dist/image/jpeg2000-dwt.d.ts +34 -0
  63. package/dist/image/jpeg2000-dwt.js +145 -0
  64. package/dist/image/jpeg2000-errors.cjs +17 -0
  65. package/dist/image/jpeg2000-errors.d.cts +9 -0
  66. package/dist/image/jpeg2000-errors.d.ts +9 -0
  67. package/dist/image/jpeg2000-errors.js +15 -0
  68. package/dist/image/jpeg2000-t1.cjs +254 -0
  69. package/dist/image/jpeg2000-t1.d.cts +18 -0
  70. package/dist/image/jpeg2000-t1.d.ts +18 -0
  71. package/dist/image/jpeg2000-t1.js +253 -0
  72. package/dist/image/jpeg2000-t2.cjs +316 -0
  73. package/dist/image/jpeg2000-t2.d.cts +79 -0
  74. package/dist/image/jpeg2000-t2.d.ts +79 -0
  75. package/dist/image/jpeg2000-t2.js +311 -0
  76. package/dist/image/jpeg2000-tagtree.cjs +105 -0
  77. package/dist/image/jpeg2000-tagtree.d.cts +29 -0
  78. package/dist/image/jpeg2000-tagtree.d.ts +29 -0
  79. package/dist/image/jpeg2000-tagtree.js +103 -0
  80. package/dist/image/jpeg2000.cjs +322 -0
  81. package/dist/image/jpeg2000.d.cts +54 -0
  82. package/dist/image/jpeg2000.d.ts +54 -0
  83. package/dist/image/jpeg2000.js +320 -0
  84. package/dist/images-read.cjs +78 -1
  85. package/dist/images-read.js +78 -1
  86. package/dist/index.cjs +17 -0
  87. package/dist/index.d.cts +11 -2
  88. package/dist/index.d.ts +11 -2
  89. package/dist/index.js +7 -1
  90. package/dist/jbig2-errors-Bj6MPxrx.d.cts +9 -0
  91. package/dist/jbig2-errors-Bj6MPxrx.d.ts +9 -0
  92. package/dist/math-font.cjs +43 -18
  93. package/dist/math-font.d.cts +8 -1
  94. package/dist/math-font.d.ts +8 -1
  95. package/dist/math-font.js +43 -18
  96. package/dist/math-stretch-Bwk_bxh1.d.ts +24 -0
  97. package/dist/math-stretch-DXWjs8gL.d.cts +24 -0
  98. package/dist/math-stretch.cjs +96 -0
  99. package/dist/math-stretch.d.cts +2 -0
  100. package/dist/math-stretch.d.ts +2 -0
  101. package/dist/math-stretch.js +94 -0
  102. package/dist/math-table-DhPrNoPa.d.ts +70 -0
  103. package/dist/math-table-gFNB8DmQ.d.cts +70 -0
  104. package/dist/math-table.cjs +69 -1
  105. package/dist/math-table.d.cts +2 -45
  106. package/dist/math-table.d.ts +2 -45
  107. package/dist/math-table.js +69 -1
  108. package/dist/{math-types-Ba8qAf1p.d.cts → math-types-YSQUTviw.d.cts} +2 -0
  109. package/dist/{math-types-Ba8qAf1p.d.ts → math-types-YSQUTviw.d.ts} +2 -0
  110. package/dist/math-types.d.cts +1 -1
  111. package/dist/math-types.d.ts +1 -1
  112. package/package.json +1 -1
package/dist/cff.cjs ADDED
@@ -0,0 +1,158 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_sfnt = require("./sfnt.cjs");
3
+ //#region src/cff.ts
4
+ const CFF_ESCAPED_OPERATOR_BASE = 1200;
5
+ const CFF_DICT_OP_CHARSET = 15;
6
+ const CFF_DICT_OP_CHARSTRINGS = 17;
7
+ const CFF_DICT_OP_PRIVATE = 18;
8
+ const CFF_DICT_OP_SUBRS = 19;
9
+ const CFF_DICT_OP_ROS = 1230;
10
+ const INDEX_COUNT_SIZE = 2;
11
+ const INDEX_OFF_SIZE_SIZE = 1;
12
+ const MIN_OFF_SIZE = 1;
13
+ const MAX_OFF_SIZE = 4;
14
+ const DICT_OPERATOR_MAX = 21;
15
+ const DICT_OPERATOR_ESCAPE = 12;
16
+ const DICT_OPERAND_INT16 = 28;
17
+ const DICT_OPERAND_INT32 = 29;
18
+ const DICT_OPERAND_REAL = 30;
19
+ const DICT_OPERAND_SMALL_FIRST = 32;
20
+ const DICT_OPERAND_SMALL_LAST = 246;
21
+ const DICT_OPERAND_MEDIUM_FIRST = 247;
22
+ const DICT_OPERAND_MEDIUM_LAST = 250;
23
+ const DICT_OPERAND_NEGATIVE_MEDIUM_FIRST = 251;
24
+ const DICT_OPERAND_NEGATIVE_MEDIUM_LAST = 254;
25
+ const DICT_OPERAND_SMALL_BIAS = 139;
26
+ const DICT_OPERAND_MEDIUM_BIAS = 108;
27
+ const DICT_OPERAND_MEDIUM_FIRST_BYTE_BIAS = 247;
28
+ const DICT_OPERAND_NEGATIVE_MEDIUM_FIRST_BYTE_BIAS = 251;
29
+ const BYTE_RADIX = 256;
30
+ const REAL_NIBBLE_DECIMAL_POINT = 10;
31
+ const REAL_NIBBLE_EXPONENT = 11;
32
+ const REAL_NIBBLE_NEGATIVE_EXPONENT = 12;
33
+ const REAL_NIBBLE_RESERVED = 13;
34
+ const REAL_NIBBLE_MINUS = 14;
35
+ const REAL_NIBBLE_TERMINATOR = 15;
36
+ const NIBBLES_PER_BYTE = 2;
37
+ const HIGH_NIBBLE_SHIFT = 4;
38
+ const LOW_NIBBLE_MASK = 15;
39
+ function readOffsetAt(bytes, offset, offSize) {
40
+ if (offSize === 1) return require_sfnt.u8(bytes, offset);
41
+ if (offSize === 2) return require_sfnt.u16(bytes, offset);
42
+ if (offSize === 3) return require_sfnt.u24(bytes, offset);
43
+ return require_sfnt.u32(bytes, offset);
44
+ }
45
+ function readCffIndex(bytes, offset) {
46
+ if (!require_sfnt.hasBytes(bytes, offset, INDEX_COUNT_SIZE)) return;
47
+ const count = require_sfnt.u16(bytes, offset);
48
+ if (count === 0) return {
49
+ count: 0,
50
+ endOffset: offset + INDEX_COUNT_SIZE,
51
+ entry: () => void 0
52
+ };
53
+ if (!require_sfnt.hasBytes(bytes, offset + INDEX_COUNT_SIZE, INDEX_OFF_SIZE_SIZE)) return;
54
+ const offSize = require_sfnt.u8(bytes, offset + INDEX_COUNT_SIZE);
55
+ if (offSize < MIN_OFF_SIZE || offSize > MAX_OFF_SIZE) return;
56
+ const offsetArrayStart = offset + INDEX_COUNT_SIZE + INDEX_OFF_SIZE_SIZE;
57
+ const offsetArrayLength = (count + 1) * offSize;
58
+ if (!require_sfnt.hasBytes(bytes, offsetArrayStart, offsetArrayLength)) return;
59
+ const offsets = [];
60
+ for (let i = 0; i <= count; i++) offsets.push(readOffsetAt(bytes, offsetArrayStart + i * offSize, offSize));
61
+ if (offsets[0] !== 1) return;
62
+ for (let i = 1; i <= count; i++) if (offsets[i] < offsets[i - 1]) return;
63
+ const dataOrigin = offsetArrayStart + offsetArrayLength - 1;
64
+ const dataLength = offsets[count] - 1;
65
+ if (!require_sfnt.hasBytes(bytes, dataOrigin + 1, dataLength)) return;
66
+ return {
67
+ count,
68
+ endOffset: dataOrigin + 1 + dataLength,
69
+ entry: (index) => index < 0 || index >= count ? void 0 : bytes.subarray(dataOrigin + offsets[index], dataOrigin + offsets[index + 1])
70
+ };
71
+ }
72
+ function readRealOperand(data, start) {
73
+ let text = "";
74
+ for (let i = start; i < data.length; i++) {
75
+ const byte = data[i];
76
+ for (let n = 0; n < NIBBLES_PER_BYTE; n++) {
77
+ const nibble = n === 0 ? byte >> HIGH_NIBBLE_SHIFT : byte & LOW_NIBBLE_MASK;
78
+ if (nibble === REAL_NIBBLE_TERMINATOR) return {
79
+ value: Number(text),
80
+ endOffset: i + 1
81
+ };
82
+ if (nibble === REAL_NIBBLE_RESERVED) return;
83
+ if (nibble <= 9) text += String(nibble);
84
+ else if (nibble === REAL_NIBBLE_DECIMAL_POINT) text += ".";
85
+ else if (nibble === REAL_NIBBLE_EXPONENT) text += "E";
86
+ else if (nibble === REAL_NIBBLE_NEGATIVE_EXPONENT) text += "E-";
87
+ else if (nibble === REAL_NIBBLE_MINUS) text += "-";
88
+ }
89
+ }
90
+ }
91
+ function parseCffDict(data) {
92
+ const dict = /* @__PURE__ */ new Map();
93
+ let operands = [];
94
+ let i = 0;
95
+ while (i < data.length) {
96
+ const b0 = data[i];
97
+ if (b0 <= DICT_OPERATOR_MAX) {
98
+ let operator = b0;
99
+ i += 1;
100
+ if (b0 === DICT_OPERATOR_ESCAPE) {
101
+ if (i >= data.length) return;
102
+ operator = CFF_ESCAPED_OPERATOR_BASE + data[i];
103
+ i += 1;
104
+ }
105
+ dict.set(operator, operands);
106
+ operands = [];
107
+ continue;
108
+ }
109
+ if (b0 === DICT_OPERAND_INT16) {
110
+ if (!require_sfnt.hasBytes(data, i + 1, 2)) return;
111
+ const raw = require_sfnt.u16(data, i + 1);
112
+ operands.push(raw >= 32768 ? raw - 65536 : raw);
113
+ i += 3;
114
+ continue;
115
+ }
116
+ if (b0 === DICT_OPERAND_INT32) {
117
+ if (!require_sfnt.hasBytes(data, i + 1, 4)) return;
118
+ operands.push(require_sfnt.u32(data, i + 1) | 0);
119
+ i += 5;
120
+ continue;
121
+ }
122
+ if (b0 === DICT_OPERAND_REAL) {
123
+ const real = readRealOperand(data, i + 1);
124
+ if (real === void 0) return;
125
+ operands.push(real.value);
126
+ i = real.endOffset;
127
+ continue;
128
+ }
129
+ if (b0 >= DICT_OPERAND_SMALL_FIRST && b0 <= DICT_OPERAND_SMALL_LAST) {
130
+ operands.push(b0 - DICT_OPERAND_SMALL_BIAS);
131
+ i += 1;
132
+ continue;
133
+ }
134
+ if (b0 >= DICT_OPERAND_MEDIUM_FIRST && b0 <= DICT_OPERAND_MEDIUM_LAST) {
135
+ if (!require_sfnt.hasBytes(data, i + 1, 1)) return;
136
+ operands.push((b0 - DICT_OPERAND_MEDIUM_FIRST_BYTE_BIAS) * BYTE_RADIX + require_sfnt.u8(data, i + 1) + DICT_OPERAND_MEDIUM_BIAS);
137
+ i += 2;
138
+ continue;
139
+ }
140
+ if (b0 >= DICT_OPERAND_NEGATIVE_MEDIUM_FIRST && b0 <= DICT_OPERAND_NEGATIVE_MEDIUM_LAST) {
141
+ if (!require_sfnt.hasBytes(data, i + 1, 1)) return;
142
+ operands.push(-(b0 - DICT_OPERAND_NEGATIVE_MEDIUM_FIRST_BYTE_BIAS) * BYTE_RADIX - require_sfnt.u8(data, i + 1) - DICT_OPERAND_MEDIUM_BIAS);
143
+ i += 2;
144
+ continue;
145
+ }
146
+ return;
147
+ }
148
+ return dict;
149
+ }
150
+ //#endregion
151
+ exports.CFF_DICT_OP_CHARSET = CFF_DICT_OP_CHARSET;
152
+ exports.CFF_DICT_OP_CHARSTRINGS = CFF_DICT_OP_CHARSTRINGS;
153
+ exports.CFF_DICT_OP_PRIVATE = CFF_DICT_OP_PRIVATE;
154
+ exports.CFF_DICT_OP_ROS = CFF_DICT_OP_ROS;
155
+ exports.CFF_DICT_OP_SUBRS = CFF_DICT_OP_SUBRS;
156
+ exports.CFF_ESCAPED_OPERATOR_BASE = CFF_ESCAPED_OPERATOR_BASE;
157
+ exports.parseCffDict = parseCffDict;
158
+ exports.readCffIndex = readCffIndex;
package/dist/cff.d.cts ADDED
@@ -0,0 +1,17 @@
1
+ //#region src/cff.d.ts
2
+ interface CffIndex {
3
+ readonly count: number;
4
+ readonly endOffset: number;
5
+ entry(index: number): Uint8Array<ArrayBuffer> | undefined;
6
+ }
7
+ type CffDict = ReadonlyMap<number, readonly number[]>;
8
+ declare const CFF_ESCAPED_OPERATOR_BASE = 1200;
9
+ declare const CFF_DICT_OP_CHARSET = 15;
10
+ declare const CFF_DICT_OP_CHARSTRINGS = 17;
11
+ declare const CFF_DICT_OP_PRIVATE = 18;
12
+ declare const CFF_DICT_OP_SUBRS = 19;
13
+ declare const CFF_DICT_OP_ROS: number;
14
+ declare function readCffIndex(bytes: Uint8Array<ArrayBuffer>, offset: number): CffIndex | undefined;
15
+ declare function parseCffDict(data: Uint8Array<ArrayBuffer>): CffDict | undefined;
16
+ //#endregion
17
+ export { CFF_DICT_OP_CHARSET, CFF_DICT_OP_CHARSTRINGS, CFF_DICT_OP_PRIVATE, CFF_DICT_OP_ROS, CFF_DICT_OP_SUBRS, CFF_ESCAPED_OPERATOR_BASE, CffDict, CffIndex, parseCffDict, readCffIndex };
package/dist/cff.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ //#region src/cff.d.ts
2
+ interface CffIndex {
3
+ readonly count: number;
4
+ readonly endOffset: number;
5
+ entry(index: number): Uint8Array<ArrayBuffer> | undefined;
6
+ }
7
+ type CffDict = ReadonlyMap<number, readonly number[]>;
8
+ declare const CFF_ESCAPED_OPERATOR_BASE = 1200;
9
+ declare const CFF_DICT_OP_CHARSET = 15;
10
+ declare const CFF_DICT_OP_CHARSTRINGS = 17;
11
+ declare const CFF_DICT_OP_PRIVATE = 18;
12
+ declare const CFF_DICT_OP_SUBRS = 19;
13
+ declare const CFF_DICT_OP_ROS: number;
14
+ declare function readCffIndex(bytes: Uint8Array<ArrayBuffer>, offset: number): CffIndex | undefined;
15
+ declare function parseCffDict(data: Uint8Array<ArrayBuffer>): CffDict | undefined;
16
+ //#endregion
17
+ export { CFF_DICT_OP_CHARSET, CFF_DICT_OP_CHARSTRINGS, CFF_DICT_OP_PRIVATE, CFF_DICT_OP_ROS, CFF_DICT_OP_SUBRS, CFF_ESCAPED_OPERATOR_BASE, CffDict, CffIndex, parseCffDict, readCffIndex };
package/dist/cff.js ADDED
@@ -0,0 +1,150 @@
1
+ import { hasBytes, u16, u24, u32, u8 } from "./sfnt.js";
2
+ //#region src/cff.ts
3
+ const CFF_ESCAPED_OPERATOR_BASE = 1200;
4
+ const CFF_DICT_OP_CHARSET = 15;
5
+ const CFF_DICT_OP_CHARSTRINGS = 17;
6
+ const CFF_DICT_OP_PRIVATE = 18;
7
+ const CFF_DICT_OP_SUBRS = 19;
8
+ const CFF_DICT_OP_ROS = 1230;
9
+ const INDEX_COUNT_SIZE = 2;
10
+ const INDEX_OFF_SIZE_SIZE = 1;
11
+ const MIN_OFF_SIZE = 1;
12
+ const MAX_OFF_SIZE = 4;
13
+ const DICT_OPERATOR_MAX = 21;
14
+ const DICT_OPERATOR_ESCAPE = 12;
15
+ const DICT_OPERAND_INT16 = 28;
16
+ const DICT_OPERAND_INT32 = 29;
17
+ const DICT_OPERAND_REAL = 30;
18
+ const DICT_OPERAND_SMALL_FIRST = 32;
19
+ const DICT_OPERAND_SMALL_LAST = 246;
20
+ const DICT_OPERAND_MEDIUM_FIRST = 247;
21
+ const DICT_OPERAND_MEDIUM_LAST = 250;
22
+ const DICT_OPERAND_NEGATIVE_MEDIUM_FIRST = 251;
23
+ const DICT_OPERAND_NEGATIVE_MEDIUM_LAST = 254;
24
+ const DICT_OPERAND_SMALL_BIAS = 139;
25
+ const DICT_OPERAND_MEDIUM_BIAS = 108;
26
+ const DICT_OPERAND_MEDIUM_FIRST_BYTE_BIAS = 247;
27
+ const DICT_OPERAND_NEGATIVE_MEDIUM_FIRST_BYTE_BIAS = 251;
28
+ const BYTE_RADIX = 256;
29
+ const REAL_NIBBLE_DECIMAL_POINT = 10;
30
+ const REAL_NIBBLE_EXPONENT = 11;
31
+ const REAL_NIBBLE_NEGATIVE_EXPONENT = 12;
32
+ const REAL_NIBBLE_RESERVED = 13;
33
+ const REAL_NIBBLE_MINUS = 14;
34
+ const REAL_NIBBLE_TERMINATOR = 15;
35
+ const NIBBLES_PER_BYTE = 2;
36
+ const HIGH_NIBBLE_SHIFT = 4;
37
+ const LOW_NIBBLE_MASK = 15;
38
+ function readOffsetAt(bytes, offset, offSize) {
39
+ if (offSize === 1) return u8(bytes, offset);
40
+ if (offSize === 2) return u16(bytes, offset);
41
+ if (offSize === 3) return u24(bytes, offset);
42
+ return u32(bytes, offset);
43
+ }
44
+ function readCffIndex(bytes, offset) {
45
+ if (!hasBytes(bytes, offset, INDEX_COUNT_SIZE)) return;
46
+ const count = u16(bytes, offset);
47
+ if (count === 0) return {
48
+ count: 0,
49
+ endOffset: offset + INDEX_COUNT_SIZE,
50
+ entry: () => void 0
51
+ };
52
+ if (!hasBytes(bytes, offset + INDEX_COUNT_SIZE, INDEX_OFF_SIZE_SIZE)) return;
53
+ const offSize = u8(bytes, offset + INDEX_COUNT_SIZE);
54
+ if (offSize < MIN_OFF_SIZE || offSize > MAX_OFF_SIZE) return;
55
+ const offsetArrayStart = offset + INDEX_COUNT_SIZE + INDEX_OFF_SIZE_SIZE;
56
+ const offsetArrayLength = (count + 1) * offSize;
57
+ if (!hasBytes(bytes, offsetArrayStart, offsetArrayLength)) return;
58
+ const offsets = [];
59
+ for (let i = 0; i <= count; i++) offsets.push(readOffsetAt(bytes, offsetArrayStart + i * offSize, offSize));
60
+ if (offsets[0] !== 1) return;
61
+ for (let i = 1; i <= count; i++) if (offsets[i] < offsets[i - 1]) return;
62
+ const dataOrigin = offsetArrayStart + offsetArrayLength - 1;
63
+ const dataLength = offsets[count] - 1;
64
+ if (!hasBytes(bytes, dataOrigin + 1, dataLength)) return;
65
+ return {
66
+ count,
67
+ endOffset: dataOrigin + 1 + dataLength,
68
+ entry: (index) => index < 0 || index >= count ? void 0 : bytes.subarray(dataOrigin + offsets[index], dataOrigin + offsets[index + 1])
69
+ };
70
+ }
71
+ function readRealOperand(data, start) {
72
+ let text = "";
73
+ for (let i = start; i < data.length; i++) {
74
+ const byte = data[i];
75
+ for (let n = 0; n < NIBBLES_PER_BYTE; n++) {
76
+ const nibble = n === 0 ? byte >> HIGH_NIBBLE_SHIFT : byte & LOW_NIBBLE_MASK;
77
+ if (nibble === REAL_NIBBLE_TERMINATOR) return {
78
+ value: Number(text),
79
+ endOffset: i + 1
80
+ };
81
+ if (nibble === REAL_NIBBLE_RESERVED) return;
82
+ if (nibble <= 9) text += String(nibble);
83
+ else if (nibble === REAL_NIBBLE_DECIMAL_POINT) text += ".";
84
+ else if (nibble === REAL_NIBBLE_EXPONENT) text += "E";
85
+ else if (nibble === REAL_NIBBLE_NEGATIVE_EXPONENT) text += "E-";
86
+ else if (nibble === REAL_NIBBLE_MINUS) text += "-";
87
+ }
88
+ }
89
+ }
90
+ function parseCffDict(data) {
91
+ const dict = /* @__PURE__ */ new Map();
92
+ let operands = [];
93
+ let i = 0;
94
+ while (i < data.length) {
95
+ const b0 = data[i];
96
+ if (b0 <= DICT_OPERATOR_MAX) {
97
+ let operator = b0;
98
+ i += 1;
99
+ if (b0 === DICT_OPERATOR_ESCAPE) {
100
+ if (i >= data.length) return;
101
+ operator = CFF_ESCAPED_OPERATOR_BASE + data[i];
102
+ i += 1;
103
+ }
104
+ dict.set(operator, operands);
105
+ operands = [];
106
+ continue;
107
+ }
108
+ if (b0 === DICT_OPERAND_INT16) {
109
+ if (!hasBytes(data, i + 1, 2)) return;
110
+ const raw = u16(data, i + 1);
111
+ operands.push(raw >= 32768 ? raw - 65536 : raw);
112
+ i += 3;
113
+ continue;
114
+ }
115
+ if (b0 === DICT_OPERAND_INT32) {
116
+ if (!hasBytes(data, i + 1, 4)) return;
117
+ operands.push(u32(data, i + 1) | 0);
118
+ i += 5;
119
+ continue;
120
+ }
121
+ if (b0 === DICT_OPERAND_REAL) {
122
+ const real = readRealOperand(data, i + 1);
123
+ if (real === void 0) return;
124
+ operands.push(real.value);
125
+ i = real.endOffset;
126
+ continue;
127
+ }
128
+ if (b0 >= DICT_OPERAND_SMALL_FIRST && b0 <= DICT_OPERAND_SMALL_LAST) {
129
+ operands.push(b0 - DICT_OPERAND_SMALL_BIAS);
130
+ i += 1;
131
+ continue;
132
+ }
133
+ if (b0 >= DICT_OPERAND_MEDIUM_FIRST && b0 <= DICT_OPERAND_MEDIUM_LAST) {
134
+ if (!hasBytes(data, i + 1, 1)) return;
135
+ operands.push((b0 - DICT_OPERAND_MEDIUM_FIRST_BYTE_BIAS) * BYTE_RADIX + u8(data, i + 1) + DICT_OPERAND_MEDIUM_BIAS);
136
+ i += 2;
137
+ continue;
138
+ }
139
+ if (b0 >= DICT_OPERAND_NEGATIVE_MEDIUM_FIRST && b0 <= DICT_OPERAND_NEGATIVE_MEDIUM_LAST) {
140
+ if (!hasBytes(data, i + 1, 1)) return;
141
+ operands.push(-(b0 - DICT_OPERAND_NEGATIVE_MEDIUM_FIRST_BYTE_BIAS) * BYTE_RADIX - u8(data, i + 1) - DICT_OPERAND_MEDIUM_BIAS);
142
+ i += 2;
143
+ continue;
144
+ }
145
+ return;
146
+ }
147
+ return dict;
148
+ }
149
+ //#endregion
150
+ export { CFF_DICT_OP_CHARSET, CFF_DICT_OP_CHARSTRINGS, CFF_DICT_OP_PRIVATE, CFF_DICT_OP_ROS, CFF_DICT_OP_SUBRS, CFF_ESCAPED_OPERATOR_BASE, parseCffDict, readCffIndex };
package/dist/filters.cjs CHANGED
@@ -3,9 +3,10 @@ const require_bytes_reader = require("./bytes/reader.cjs");
3
3
  const require_objects = require("./objects.cjs");
4
4
  const require_bytes_flate = require("./bytes/flate.cjs");
5
5
  const require_image_ccitt = require("./image/ccitt.cjs");
6
+ const require_image_jbig2 = require("./image/jbig2.cjs");
6
7
  const require_predictors = require("./predictors.cjs");
7
8
  //#region src/filters.ts
8
- function decodeStream(raw, dict, sink) {
9
+ function decodeStream(raw, dict, sink, resolve) {
9
10
  const filters = filterNames(dict);
10
11
  const parms = decodeParmsList(dict, filters.length);
11
12
  let bytes = raw;
@@ -20,10 +21,21 @@ function decodeStream(raw, dict, sink) {
20
21
  else if (filter === "ASCIIHexDecode" || filter === "AHx") bytes = asciiHexDecode(bytes);
21
22
  else if (filter === "RunLengthDecode" || filter === "RL") bytes = runLengthDecode(bytes);
22
23
  else if (filter === "CCITTFaxDecode" || filter === "CCF") bytes = ccittFaxDecode(bytes, parm, dict, sink);
23
- else if (filter === "DCTDecode" || filter === "DCT") return {
24
+ else if (filter === "JBIG2Decode") {
25
+ const decoded = jbig2Decode(bytes, parm, dict, sink, resolve);
26
+ if (decoded === void 0) return {
27
+ bytes,
28
+ remainingFilter: "JBIG2Decode"
29
+ };
30
+ bytes = decoded;
31
+ } else if (filter === "DCTDecode" || filter === "DCT") return {
24
32
  bytes,
25
33
  remainingFilter: "DCTDecode"
26
34
  };
35
+ else if (filter === "JPXDecode") return {
36
+ bytes,
37
+ remainingFilter: "JPXDecode"
38
+ };
27
39
  else {
28
40
  sink({
29
41
  code: "pdf/unsupported-filter",
@@ -57,6 +69,37 @@ function ccittFaxDecode(data, parm, dict, sink) {
57
69
  })
58
70
  }).bytes;
59
71
  }
72
+ function jbig2Decode(data, parm, dict, sink, resolve) {
73
+ const globalsObj = parm !== void 0 ? require_objects.dictGet(parm, "JBIG2Globals") : void 0;
74
+ const resolvedGlobals = resolve !== void 0 ? resolve(globalsObj) : globalsObj;
75
+ let globals;
76
+ if (resolvedGlobals?.kind === "stream") globals = decodeStream(resolvedGlobals.raw, resolvedGlobals.dict, sink, resolve).bytes;
77
+ else if (globalsObj !== void 0) sink({
78
+ code: "pdf/jbig2-degraded",
79
+ severity: "warning",
80
+ message: "a JBIG2Decode stream declares /JBIG2Globals but it could not be resolved to a stream; decoding without it, which will fail if the page refers to a shared symbol dictionary"
81
+ });
82
+ try {
83
+ const image = require_image_jbig2.decodeJbig2Embedded(data, {
84
+ globals,
85
+ width: require_objects.asNumber(require_objects.dictGet(dict, "Width") ?? require_objects.dictGet(dict, "W")),
86
+ height: require_objects.asNumber(require_objects.dictGet(dict, "Height") ?? require_objects.dictGet(dict, "H")),
87
+ onWarning: (message) => sink({
88
+ code: "pdf/jbig2-degraded",
89
+ severity: "warning",
90
+ message
91
+ })
92
+ });
93
+ return Uint8Array.from(image.bytes, (byte) => byte ^ 255);
94
+ } catch (error) {
95
+ sink({
96
+ code: "pdf/jbig2-undecodable",
97
+ severity: "warning",
98
+ message: `JBIG2Decode stream could not be decoded (${error instanceof Error ? error.message : String(error)}); leaving its bytes undecoded`
99
+ });
100
+ return;
101
+ }
102
+ }
60
103
  function filterNames(dict) {
61
104
  const filterObj = require_objects.dictGet(dict, "Filter") ?? require_objects.dictGet(dict, "F");
62
105
  if (filterObj === void 0) return [];
@@ -1,14 +1,15 @@
1
1
  import { PdfDiagnosticSink } from "./diagnostics.cjs";
2
- import { PdfDict } from "./objects.cjs";
2
+ import { PdfDict, PdfObject } from "./objects.cjs";
3
3
  //#region src/filters.d.ts
4
4
  interface DecodedStream {
5
5
  readonly bytes: Uint8Array<ArrayBuffer>;
6
6
  readonly remainingFilter?: string;
7
7
  }
8
- declare function decodeStream(raw: Uint8Array<ArrayBuffer>, dict: PdfDict, sink: PdfDiagnosticSink): DecodedStream;
8
+ type PdfIndirectResolver = (obj: PdfObject | undefined) => PdfObject | undefined;
9
+ declare function decodeStream(raw: Uint8Array<ArrayBuffer>, dict: PdfDict, sink: PdfDiagnosticSink, resolve?: PdfIndirectResolver): DecodedStream;
9
10
  declare function lzwDecode(data: Uint8Array<ArrayBuffer>, earlyChange: boolean, sink: PdfDiagnosticSink): Uint8Array<ArrayBuffer>;
10
11
  declare function ascii85Decode(data: Uint8Array<ArrayBuffer>): Uint8Array<ArrayBuffer>;
11
12
  declare function asciiHexDecode(data: Uint8Array<ArrayBuffer>): Uint8Array<ArrayBuffer>;
12
13
  declare function runLengthDecode(data: Uint8Array<ArrayBuffer>): Uint8Array<ArrayBuffer>;
13
14
  //#endregion
14
- export { DecodedStream, ascii85Decode, asciiHexDecode, decodeStream, lzwDecode, runLengthDecode };
15
+ export { DecodedStream, PdfIndirectResolver, ascii85Decode, asciiHexDecode, decodeStream, lzwDecode, runLengthDecode };
package/dist/filters.d.ts CHANGED
@@ -1,14 +1,15 @@
1
1
  import { PdfDiagnosticSink } from "./diagnostics.js";
2
- import { PdfDict } from "./objects.js";
2
+ import { PdfDict, PdfObject } from "./objects.js";
3
3
  //#region src/filters.d.ts
4
4
  interface DecodedStream {
5
5
  readonly bytes: Uint8Array<ArrayBuffer>;
6
6
  readonly remainingFilter?: string;
7
7
  }
8
- declare function decodeStream(raw: Uint8Array<ArrayBuffer>, dict: PdfDict, sink: PdfDiagnosticSink): DecodedStream;
8
+ type PdfIndirectResolver = (obj: PdfObject | undefined) => PdfObject | undefined;
9
+ declare function decodeStream(raw: Uint8Array<ArrayBuffer>, dict: PdfDict, sink: PdfDiagnosticSink, resolve?: PdfIndirectResolver): DecodedStream;
9
10
  declare function lzwDecode(data: Uint8Array<ArrayBuffer>, earlyChange: boolean, sink: PdfDiagnosticSink): Uint8Array<ArrayBuffer>;
10
11
  declare function ascii85Decode(data: Uint8Array<ArrayBuffer>): Uint8Array<ArrayBuffer>;
11
12
  declare function asciiHexDecode(data: Uint8Array<ArrayBuffer>): Uint8Array<ArrayBuffer>;
12
13
  declare function runLengthDecode(data: Uint8Array<ArrayBuffer>): Uint8Array<ArrayBuffer>;
13
14
  //#endregion
14
- export { DecodedStream, ascii85Decode, asciiHexDecode, decodeStream, lzwDecode, runLengthDecode };
15
+ export { DecodedStream, PdfIndirectResolver, ascii85Decode, asciiHexDecode, decodeStream, lzwDecode, runLengthDecode };
package/dist/filters.js CHANGED
@@ -2,9 +2,10 @@ import { isAsciiWhitespace } from "./bytes/reader.js";
2
2
  import { asArray, asBool, asDict, asName, asNumber, dictGet } from "./objects.js";
3
3
  import { inflateTolerant } from "./bytes/flate.js";
4
4
  import { decodeCcittFax } from "./image/ccitt.js";
5
+ import { decodeJbig2Embedded } from "./image/jbig2.js";
5
6
  import { applyPredictor, readPredictorParams } from "./predictors.js";
6
7
  //#region src/filters.ts
7
- function decodeStream(raw, dict, sink) {
8
+ function decodeStream(raw, dict, sink, resolve) {
8
9
  const filters = filterNames(dict);
9
10
  const parms = decodeParmsList(dict, filters.length);
10
11
  let bytes = raw;
@@ -19,10 +20,21 @@ function decodeStream(raw, dict, sink) {
19
20
  else if (filter === "ASCIIHexDecode" || filter === "AHx") bytes = asciiHexDecode(bytes);
20
21
  else if (filter === "RunLengthDecode" || filter === "RL") bytes = runLengthDecode(bytes);
21
22
  else if (filter === "CCITTFaxDecode" || filter === "CCF") bytes = ccittFaxDecode(bytes, parm, dict, sink);
22
- else if (filter === "DCTDecode" || filter === "DCT") return {
23
+ else if (filter === "JBIG2Decode") {
24
+ const decoded = jbig2Decode(bytes, parm, dict, sink, resolve);
25
+ if (decoded === void 0) return {
26
+ bytes,
27
+ remainingFilter: "JBIG2Decode"
28
+ };
29
+ bytes = decoded;
30
+ } else if (filter === "DCTDecode" || filter === "DCT") return {
23
31
  bytes,
24
32
  remainingFilter: "DCTDecode"
25
33
  };
34
+ else if (filter === "JPXDecode") return {
35
+ bytes,
36
+ remainingFilter: "JPXDecode"
37
+ };
26
38
  else {
27
39
  sink({
28
40
  code: "pdf/unsupported-filter",
@@ -56,6 +68,37 @@ function ccittFaxDecode(data, parm, dict, sink) {
56
68
  })
57
69
  }).bytes;
58
70
  }
71
+ function jbig2Decode(data, parm, dict, sink, resolve) {
72
+ const globalsObj = parm !== void 0 ? dictGet(parm, "JBIG2Globals") : void 0;
73
+ const resolvedGlobals = resolve !== void 0 ? resolve(globalsObj) : globalsObj;
74
+ let globals;
75
+ if (resolvedGlobals?.kind === "stream") globals = decodeStream(resolvedGlobals.raw, resolvedGlobals.dict, sink, resolve).bytes;
76
+ else if (globalsObj !== void 0) sink({
77
+ code: "pdf/jbig2-degraded",
78
+ severity: "warning",
79
+ message: "a JBIG2Decode stream declares /JBIG2Globals but it could not be resolved to a stream; decoding without it, which will fail if the page refers to a shared symbol dictionary"
80
+ });
81
+ try {
82
+ const image = decodeJbig2Embedded(data, {
83
+ globals,
84
+ width: asNumber(dictGet(dict, "Width") ?? dictGet(dict, "W")),
85
+ height: asNumber(dictGet(dict, "Height") ?? dictGet(dict, "H")),
86
+ onWarning: (message) => sink({
87
+ code: "pdf/jbig2-degraded",
88
+ severity: "warning",
89
+ message
90
+ })
91
+ });
92
+ return Uint8Array.from(image.bytes, (byte) => byte ^ 255);
93
+ } catch (error) {
94
+ sink({
95
+ code: "pdf/jbig2-undecodable",
96
+ severity: "warning",
97
+ message: `JBIG2Decode stream could not be decoded (${error instanceof Error ? error.message : String(error)}); leaving its bytes undecoded`
98
+ });
99
+ return;
100
+ }
101
+ }
59
102
  function filterNames(dict) {
60
103
  const filterObj = dictGet(dict, "Filter") ?? dictGet(dict, "F");
61
104
  if (filterObj === void 0) return [];
@@ -1,4 +1,4 @@
1
- import { t as MathBox } from "./math-types-Ba8qAf1p.cjs";
1
+ import { t as MathBox } from "./math-types-YSQUTviw.cjs";
2
2
  //#region src/formula.d.ts
3
3
  interface PositionedFormula {
4
4
  readonly pageIndex: number;
package/dist/formula.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { t as MathBox } from "./math-types-Ba8qAf1p.js";
1
+ import { t as MathBox } from "./math-types-YSQUTviw.js";
2
2
  //#region src/formula.d.ts
3
3
  interface PositionedFormula {
4
4
  readonly pageIndex: number;
package/dist/glyf.cjs CHANGED
@@ -1,5 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_sfnt = require("./sfnt.cjs");
3
+ const require_glyph_bounds = require("./glyph-bounds.cjs");
3
4
  //#region src/glyf.ts
4
5
  const LOCA_SHORT_ENTRY_SIZE = 2;
5
6
  const LOCA_LONG_ENTRY_SIZE = 4;
@@ -21,6 +22,9 @@ const WE_HAVE_A_SCALE = 8;
21
22
  const MORE_COMPONENTS = 32;
22
23
  const WE_HAVE_AN_X_AND_Y_SCALE = 64;
23
24
  const WE_HAVE_A_TWO_BY_TWO = 128;
25
+ const SCALED_COMPONENT_OFFSET = 2048;
26
+ const UNSCALED_COMPONENT_OFFSET = 4096;
27
+ const MAX_COMPOSITE_DEPTH = 5;
24
28
  const COMPONENT_RECORD_HEADER_SIZE = 4;
25
29
  function signedByte(value) {
26
30
  return value >= 128 ? value - 256 : value;
@@ -88,6 +92,31 @@ function readComponents(glyph) {
88
92
  if ((flags & MORE_COMPONENTS) === 0) return components;
89
93
  }
90
94
  }
95
+ function placeComponentBounds(bounds, component) {
96
+ const [a, b, c, d] = component.transform ?? [
97
+ 1,
98
+ 0,
99
+ 0,
100
+ 1
101
+ ];
102
+ const corners = [
103
+ [bounds.xMin, bounds.yMin],
104
+ [bounds.xMax, bounds.yMin],
105
+ [bounds.xMin, bounds.yMax],
106
+ [bounds.xMax, bounds.yMax]
107
+ ];
108
+ const xs = corners.map(([x, y]) => a * x + c * y);
109
+ const ys = corners.map(([x, y]) => b * x + d * y);
110
+ const scaledOffset = (component.flags & SCALED_COMPONENT_OFFSET) !== 0 && (component.flags & UNSCALED_COMPONENT_OFFSET) === 0;
111
+ const dx = scaledOffset ? a * component.argument1 + c * component.argument2 : component.argument1;
112
+ const dy = scaledOffset ? b * component.argument1 + d * component.argument2 : component.argument2;
113
+ return {
114
+ xMin: Math.min(...xs) + dx,
115
+ yMin: Math.min(...ys) + dy,
116
+ xMax: Math.max(...xs) + dx,
117
+ yMax: Math.max(...ys) + dy
118
+ };
119
+ }
91
120
  function parseGlyf(font, options) {
92
121
  const glyfBytes = require_sfnt.sfntTableBytes(font, "glyf");
93
122
  const loca = parseLoca(font, options);
@@ -110,16 +139,43 @@ function parseGlyf(font, options) {
110
139
  yMax: require_sfnt.i16(glyph, 8)
111
140
  };
112
141
  };
142
+ const compositeComponents = (glyphId) => {
143
+ const header = glyphHeader(glyphId);
144
+ if (header === void 0 || header.numberOfContours >= 0) return;
145
+ const glyph = glyphBytes(glyphId);
146
+ return glyph === void 0 ? void 0 : readComponents(glyph);
147
+ };
148
+ const resolveInkBounds = (glyphId, depth) => {
149
+ const header = glyphHeader(glyphId);
150
+ if (header === void 0) return;
151
+ if (header.numberOfContours >= 0) return {
152
+ xMin: header.xMin,
153
+ yMin: header.yMin,
154
+ xMax: header.xMax,
155
+ yMax: header.yMax
156
+ };
157
+ if (depth >= MAX_COMPOSITE_DEPTH) return;
158
+ const components = compositeComponents(glyphId);
159
+ if (components === void 0) return;
160
+ let bounds;
161
+ for (const component of components) {
162
+ if (!component.argsAreXyValues) return;
163
+ const componentBytes = glyphBytes(component.glyphIndex);
164
+ if (componentBytes === void 0) return;
165
+ if (componentBytes.length === 0) continue;
166
+ const componentBounds = resolveInkBounds(component.glyphIndex, depth + 1);
167
+ if (componentBounds === void 0) return;
168
+ const placed = placeComponentBounds(componentBounds, component);
169
+ bounds = bounds === void 0 ? placed : require_glyph_bounds.unionGlyphInkBounds(bounds, placed);
170
+ }
171
+ return bounds;
172
+ };
113
173
  return {
114
174
  numGlyphs: options.numGlyphs,
115
175
  glyphBytes,
116
176
  glyphHeader,
117
- compositeComponents(glyphId) {
118
- const header = glyphHeader(glyphId);
119
- if (header === void 0 || header.numberOfContours >= 0) return;
120
- const glyph = glyphBytes(glyphId);
121
- return glyph === void 0 ? void 0 : readComponents(glyph);
122
- }
177
+ compositeComponents,
178
+ glyphInkBounds: (glyphId) => resolveInkBounds(glyphId, 0)
123
179
  };
124
180
  }
125
181
  //#endregion
package/dist/glyf.d.cts CHANGED
@@ -1,3 +1,4 @@
1
+ import { t as GlyphInkBounds } from "./glyph-bounds-BV_Z40KS.cjs";
1
2
  import { t as SfntFont } from "./sfnt-V08bb5ut.cjs";
2
3
  //#region src/glyf.d.ts
3
4
  interface GlyphHeader {
@@ -20,6 +21,7 @@ interface GlyfTable {
20
21
  glyphBytes(glyphId: number): Uint8Array<ArrayBuffer> | undefined;
21
22
  glyphHeader(glyphId: number): GlyphHeader | undefined;
22
23
  compositeComponents(glyphId: number): readonly CompositeComponent[] | undefined;
24
+ glyphInkBounds(glyphId: number): GlyphInkBounds | undefined;
23
25
  }
24
26
  interface GlyfOptions {
25
27
  readonly numGlyphs: number;
package/dist/glyf.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { t as GlyphInkBounds } from "./glyph-bounds-BV_Z40KS.js";
1
2
  import { t as SfntFont } from "./sfnt-V08bb5ut.js";
2
3
  //#region src/glyf.d.ts
3
4
  interface GlyphHeader {
@@ -20,6 +21,7 @@ interface GlyfTable {
20
21
  glyphBytes(glyphId: number): Uint8Array<ArrayBuffer> | undefined;
21
22
  glyphHeader(glyphId: number): GlyphHeader | undefined;
22
23
  compositeComponents(glyphId: number): readonly CompositeComponent[] | undefined;
24
+ glyphInkBounds(glyphId: number): GlyphInkBounds | undefined;
23
25
  }
24
26
  interface GlyfOptions {
25
27
  readonly numGlyphs: number;