pdf-parser.js 5.2.27 → 5.2.29

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 (145) hide show
  1. package/dist/{afm-widths-BYiX2L9D.cjs → afm-widths-BHD2HZIL.cjs} +553 -642
  2. package/dist/{afm-widths-blUDDjlI.js → afm-widths-B_IGbGky.js} +553 -642
  3. package/dist/afm-widths.cjs +1 -1
  4. package/dist/afm-widths.js +1 -1
  5. package/dist/annotations.cjs +5 -3
  6. package/dist/annotations.js +5 -3
  7. package/dist/builtin-encoding.cjs +17 -6
  8. package/dist/builtin-encoding.js +17 -6
  9. package/dist/bytes/crc32.cjs +5 -3
  10. package/dist/bytes/crc32.js +5 -3
  11. package/dist/bytes/flate.cjs +0 -1
  12. package/dist/bytes/flate.js +0 -1
  13. package/dist/cff-bounds.cjs +42 -24
  14. package/dist/cff-bounds.js +42 -24
  15. package/dist/cff.cjs +13 -6
  16. package/dist/cff.js +13 -6
  17. package/dist/cmap-table.cjs +54 -26
  18. package/dist/cmap-table.js +54 -26
  19. package/dist/cmap.cjs +5 -3
  20. package/dist/cmap.js +5 -3
  21. package/dist/content-write.cjs +3 -2
  22. package/dist/content-write.js +3 -2
  23. package/dist/crypto/aes.cjs +76 -55
  24. package/dist/crypto/aes.js +76 -55
  25. package/dist/crypto/md5.cjs +345 -149
  26. package/dist/crypto/md5.js +345 -149
  27. package/dist/crypto/rc4.cjs +5 -4
  28. package/dist/crypto/rc4.js +5 -4
  29. package/dist/crypto/sha2.cjs +92 -43
  30. package/dist/crypto/sha2.js +92 -43
  31. package/dist/embedded-font.cjs +4 -2
  32. package/dist/embedded-font.js +4 -2
  33. package/dist/encoding.cjs +1 -1
  34. package/dist/encoding.js +1 -1
  35. package/dist/encrypt-write.cjs +25 -21
  36. package/dist/encrypt-write.js +25 -21
  37. package/dist/encrypt.cjs +43 -64
  38. package/dist/encrypt.js +43 -64
  39. package/dist/filters.cjs +40 -20
  40. package/dist/filters.js +40 -20
  41. package/dist/font-face.cjs +2 -1
  42. package/dist/font-face.js +2 -1
  43. package/dist/font-read.cjs +12 -6
  44. package/dist/font-read.js +12 -6
  45. package/dist/font-tables.cjs +55 -28
  46. package/dist/font-tables.js +55 -28
  47. package/dist/gdef-table.cjs +6 -3
  48. package/dist/gdef-table.js +6 -3
  49. package/dist/glyf-contours.cjs +3 -1
  50. package/dist/glyf-contours.js +3 -1
  51. package/dist/glyf.cjs +22 -11
  52. package/dist/glyf.js +22 -11
  53. package/dist/gpos-table.cjs +37 -19
  54. package/dist/gpos-table.js +37 -19
  55. package/dist/gsub-table.cjs +28 -17
  56. package/dist/gsub-table.js +28 -17
  57. package/dist/hmtx-table.cjs +5 -3
  58. package/dist/hmtx-table.js +5 -3
  59. package/dist/image/ccitt-encode.cjs +8 -5
  60. package/dist/image/ccitt-encode.js +8 -5
  61. package/dist/image/ccitt.cjs +801 -209
  62. package/dist/image/ccitt.js +801 -209
  63. package/dist/image/jbig2-arith.cjs +340 -306
  64. package/dist/image/jbig2-arith.js +340 -306
  65. package/dist/image/jbig2-bitmap.cjs +8 -5
  66. package/dist/image/jbig2-bitmap.js +8 -5
  67. package/dist/image/jbig2-generic.cjs +240 -69
  68. package/dist/image/jbig2-generic.js +240 -69
  69. package/dist/image/jbig2-text.cjs +4 -2
  70. package/dist/image/jbig2-text.js +4 -2
  71. package/dist/image/jbig2.cjs +69 -31
  72. package/dist/image/jbig2.js +69 -31
  73. package/dist/image/jp2-boxes.cjs +52 -27
  74. package/dist/image/jp2-boxes.js +52 -27
  75. package/dist/image/jpeg-info.cjs +29 -24
  76. package/dist/image/jpeg-info.js +29 -24
  77. package/dist/image/jpeg2000-codestream.cjs +44 -24
  78. package/dist/image/jpeg2000-codestream.js +44 -24
  79. package/dist/image/jpeg2000-dwt.cjs +2 -1
  80. package/dist/image/jpeg2000-dwt.js +2 -1
  81. package/dist/image/jpeg2000-t1.cjs +21 -11
  82. package/dist/image/jpeg2000-t1.js +21 -11
  83. package/dist/image/jpeg2000-t2.cjs +12 -5
  84. package/dist/image/jpeg2000-t2.js +12 -5
  85. package/dist/image/jpeg2000-tagtree.cjs +8 -4
  86. package/dist/image/jpeg2000-tagtree.js +8 -4
  87. package/dist/image/jpeg2000.cjs +11 -6
  88. package/dist/image/jpeg2000.js +11 -6
  89. package/dist/image/png-decode.cjs +62 -39
  90. package/dist/image/png-decode.d.cts +3 -2
  91. package/dist/image/png-decode.d.ts +3 -2
  92. package/dist/image/png-decode.js +62 -39
  93. package/dist/image/png-filter.cjs +23 -15
  94. package/dist/image/png-filter.js +23 -15
  95. package/dist/images-read.cjs +41 -36
  96. package/dist/images-read.js +41 -36
  97. package/dist/index.cjs +1 -1
  98. package/dist/index.js +1 -1
  99. package/dist/interpret.cjs +39 -24
  100. package/dist/interpret.js +39 -24
  101. package/dist/lexer.cjs +86 -51
  102. package/dist/lexer.js +86 -51
  103. package/dist/math-content-write.cjs +9 -5
  104. package/dist/math-content-write.js +9 -5
  105. package/dist/math-font-write.cjs +2 -1
  106. package/dist/math-font-write.js +2 -1
  107. package/dist/math-font.cjs +16 -7
  108. package/dist/math-font.js +16 -7
  109. package/dist/math-table.cjs +25 -13
  110. package/dist/math-table.js +25 -13
  111. package/dist/matrix.cjs +3 -2
  112. package/dist/matrix.js +3 -2
  113. package/dist/measure.cjs +1 -1
  114. package/dist/measure.js +1 -1
  115. package/dist/navigation.cjs +10 -5
  116. package/dist/navigation.js +10 -5
  117. package/dist/ot-layout-common.cjs +4 -2
  118. package/dist/ot-layout-common.js +4 -2
  119. package/dist/parse.cjs +7 -5
  120. package/dist/parse.js +7 -5
  121. package/dist/pdf-text.cjs +5 -2
  122. package/dist/pdf-text.js +5 -2
  123. package/dist/predictors.cjs +14 -9
  124. package/dist/predictors.js +14 -9
  125. package/dist/raster.cjs +30 -19
  126. package/dist/raster.js +30 -19
  127. package/dist/read.cjs +17 -8
  128. package/dist/read.js +17 -8
  129. package/dist/serialize.cjs +6 -2
  130. package/dist/serialize.js +6 -2
  131. package/dist/sfnt-subset.cjs +25 -13
  132. package/dist/sfnt-subset.js +25 -13
  133. package/dist/sfnt.cjs +20 -10
  134. package/dist/sfnt.js +20 -10
  135. package/dist/text-group.cjs +0 -1
  136. package/dist/text-group.js +0 -1
  137. package/dist/tounicode.cjs +4 -2
  138. package/dist/tounicode.js +4 -2
  139. package/dist/winansi.cjs +1 -1
  140. package/dist/winansi.js +1 -1
  141. package/dist/write.cjs +20 -12
  142. package/dist/write.js +20 -12
  143. package/dist/xref.cjs +5 -2
  144. package/dist/xref.js +5 -2
  145. package/package.json +2 -2
@@ -1,6 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_image_jbig2_errors = require("./jbig2-errors.cjs");
3
- //#region src/image/jbig2-bitmap.ts
4
3
  const MAX_JBIG2_BITMAP_PIXELS = 1 << 26;
5
4
  var Jbig2BitmapTooLargeError = class extends require_image_jbig2_errors.Jbig2ParseError {
6
5
  constructor(width, height) {
@@ -51,21 +50,25 @@ function combineBitmap(destination, source, x, y, operator) {
51
50
  }
52
51
  }
53
52
  }
53
+ const BITS_PER_BYTE = 8;
54
+ const BYTE_INDEX_SHIFT = 3;
55
+ const BYTE_BIT_MASK = 7;
56
+ const MSB_FIRST_BIT_MASK = 128;
54
57
  function packBitmapRows(bitmap, width, height) {
55
- const bytesPerRow = Math.ceil(width / 8);
58
+ const bytesPerRow = Math.ceil(width / BITS_PER_BYTE);
56
59
  const out = new Uint8Array(bytesPerRow * height);
57
60
  for (let y = 0; y < height; y++) {
58
61
  const rowStart = y * bytesPerRow;
59
- for (let x = 0; x < width; x++) if (getPixel(bitmap, x, y) === 1) out[rowStart + (x >> 3)] = (out[rowStart + (x >> 3)] ?? 0) | 128 >> (x & 7);
62
+ for (let x = 0; x < width; x++) if (getPixel(bitmap, x, y) === 1) out[rowStart + (x >> BYTE_INDEX_SHIFT)] = (out[rowStart + (x >> BYTE_INDEX_SHIFT)] ?? 0) | MSB_FIRST_BIT_MASK >> (x & BYTE_BIT_MASK);
60
63
  }
61
64
  return out;
62
65
  }
63
66
  function unpackBitmapRows(packed, width, height) {
64
67
  const bitmap = createBitmap(width, height);
65
- const bytesPerRow = Math.ceil(width / 8);
68
+ const bytesPerRow = Math.ceil(width / BITS_PER_BYTE);
66
69
  for (let y = 0; y < height; y++) {
67
70
  const rowStart = y * bytesPerRow;
68
- for (let x = 0; x < width; x++) bitmap.data[y * width + x] = (packed[rowStart + (x >> 3)] ?? 0) >> 7 - (x & 7) & 1;
71
+ for (let x = 0; x < width; x++) bitmap.data[y * width + x] = (packed[rowStart + (x >> BYTE_INDEX_SHIFT)] ?? 0) >> BYTE_BIT_MASK - (x & BYTE_BIT_MASK) & 1;
69
72
  }
70
73
  return bitmap;
71
74
  }
@@ -1,5 +1,4 @@
1
1
  import { Jbig2ParseError } from "./jbig2-errors.js";
2
- //#region src/image/jbig2-bitmap.ts
3
2
  const MAX_JBIG2_BITMAP_PIXELS = 1 << 26;
4
3
  var Jbig2BitmapTooLargeError = class extends Jbig2ParseError {
5
4
  constructor(width, height) {
@@ -50,21 +49,25 @@ function combineBitmap(destination, source, x, y, operator) {
50
49
  }
51
50
  }
52
51
  }
52
+ const BITS_PER_BYTE = 8;
53
+ const BYTE_INDEX_SHIFT = 3;
54
+ const BYTE_BIT_MASK = 7;
55
+ const MSB_FIRST_BIT_MASK = 128;
53
56
  function packBitmapRows(bitmap, width, height) {
54
- const bytesPerRow = Math.ceil(width / 8);
57
+ const bytesPerRow = Math.ceil(width / BITS_PER_BYTE);
55
58
  const out = new Uint8Array(bytesPerRow * height);
56
59
  for (let y = 0; y < height; y++) {
57
60
  const rowStart = y * bytesPerRow;
58
- for (let x = 0; x < width; x++) if (getPixel(bitmap, x, y) === 1) out[rowStart + (x >> 3)] = (out[rowStart + (x >> 3)] ?? 0) | 128 >> (x & 7);
61
+ for (let x = 0; x < width; x++) if (getPixel(bitmap, x, y) === 1) out[rowStart + (x >> BYTE_INDEX_SHIFT)] = (out[rowStart + (x >> BYTE_INDEX_SHIFT)] ?? 0) | MSB_FIRST_BIT_MASK >> (x & BYTE_BIT_MASK);
59
62
  }
60
63
  return out;
61
64
  }
62
65
  function unpackBitmapRows(packed, width, height) {
63
66
  const bitmap = createBitmap(width, height);
64
- const bytesPerRow = Math.ceil(width / 8);
67
+ const bytesPerRow = Math.ceil(width / BITS_PER_BYTE);
65
68
  for (let y = 0; y < height; y++) {
66
69
  const rowStart = y * bytesPerRow;
67
- for (let x = 0; x < width; x++) bitmap.data[y * width + x] = (packed[rowStart + (x >> 3)] ?? 0) >> 7 - (x & 7) & 1;
70
+ for (let x = 0; x < width; x++) bitmap.data[y * width + x] = (packed[rowStart + (x >> BYTE_INDEX_SHIFT)] ?? 0) >> BYTE_BIT_MASK - (x & BYTE_BIT_MASK) & 1;
68
71
  }
69
72
  return bitmap;
70
73
  }
@@ -2,76 +2,252 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_image_jbig2_errors = require("./jbig2-errors.cjs");
3
3
  const require_image_jbig2_bitmap = require("./jbig2-bitmap.cjs");
4
4
  //#region src/image/jbig2-generic.ts
5
- function fixed(dx, dy) {
6
- return {
7
- kind: "fixed",
8
- dx,
9
- dy
10
- };
11
- }
12
- function at(index) {
13
- return {
14
- kind: "at",
15
- index
16
- };
17
- }
18
5
  const GENERIC_TEMPLATES = [
19
6
  [
20
- at(3),
21
- fixed(-1, -2),
22
- fixed(0, -2),
23
- fixed(1, -2),
24
- at(2),
25
- at(1),
26
- fixed(-2, -1),
27
- fixed(-1, -1),
28
- fixed(0, -1),
29
- fixed(1, -1),
30
- fixed(2, -1),
31
- at(0),
32
- fixed(-4, 0),
33
- fixed(-3, 0),
34
- fixed(-2, 0),
35
- fixed(-1, 0)
7
+ {
8
+ kind: "at",
9
+ index: 3
10
+ },
11
+ {
12
+ kind: "fixed",
13
+ dx: -1,
14
+ dy: -2
15
+ },
16
+ {
17
+ kind: "fixed",
18
+ dx: 0,
19
+ dy: -2
20
+ },
21
+ {
22
+ kind: "fixed",
23
+ dx: 1,
24
+ dy: -2
25
+ },
26
+ {
27
+ kind: "at",
28
+ index: 2
29
+ },
30
+ {
31
+ kind: "at",
32
+ index: 1
33
+ },
34
+ {
35
+ kind: "fixed",
36
+ dx: -2,
37
+ dy: -1
38
+ },
39
+ {
40
+ kind: "fixed",
41
+ dx: -1,
42
+ dy: -1
43
+ },
44
+ {
45
+ kind: "fixed",
46
+ dx: 0,
47
+ dy: -1
48
+ },
49
+ {
50
+ kind: "fixed",
51
+ dx: 1,
52
+ dy: -1
53
+ },
54
+ {
55
+ kind: "fixed",
56
+ dx: 2,
57
+ dy: -1
58
+ },
59
+ {
60
+ kind: "at",
61
+ index: 0
62
+ },
63
+ {
64
+ kind: "fixed",
65
+ dx: -4,
66
+ dy: 0
67
+ },
68
+ {
69
+ kind: "fixed",
70
+ dx: -3,
71
+ dy: 0
72
+ },
73
+ {
74
+ kind: "fixed",
75
+ dx: -2,
76
+ dy: 0
77
+ },
78
+ {
79
+ kind: "fixed",
80
+ dx: -1,
81
+ dy: 0
82
+ }
36
83
  ],
37
84
  [
38
- fixed(-1, -2),
39
- fixed(0, -2),
40
- fixed(1, -2),
41
- fixed(2, -2),
42
- fixed(-2, -1),
43
- fixed(-1, -1),
44
- fixed(0, -1),
45
- fixed(1, -1),
46
- fixed(2, -1),
47
- at(0),
48
- fixed(-3, 0),
49
- fixed(-2, 0),
50
- fixed(-1, 0)
85
+ {
86
+ kind: "fixed",
87
+ dx: -1,
88
+ dy: -2
89
+ },
90
+ {
91
+ kind: "fixed",
92
+ dx: 0,
93
+ dy: -2
94
+ },
95
+ {
96
+ kind: "fixed",
97
+ dx: 1,
98
+ dy: -2
99
+ },
100
+ {
101
+ kind: "fixed",
102
+ dx: 2,
103
+ dy: -2
104
+ },
105
+ {
106
+ kind: "fixed",
107
+ dx: -2,
108
+ dy: -1
109
+ },
110
+ {
111
+ kind: "fixed",
112
+ dx: -1,
113
+ dy: -1
114
+ },
115
+ {
116
+ kind: "fixed",
117
+ dx: 0,
118
+ dy: -1
119
+ },
120
+ {
121
+ kind: "fixed",
122
+ dx: 1,
123
+ dy: -1
124
+ },
125
+ {
126
+ kind: "fixed",
127
+ dx: 2,
128
+ dy: -1
129
+ },
130
+ {
131
+ kind: "at",
132
+ index: 0
133
+ },
134
+ {
135
+ kind: "fixed",
136
+ dx: -3,
137
+ dy: 0
138
+ },
139
+ {
140
+ kind: "fixed",
141
+ dx: -2,
142
+ dy: 0
143
+ },
144
+ {
145
+ kind: "fixed",
146
+ dx: -1,
147
+ dy: 0
148
+ }
51
149
  ],
52
150
  [
53
- fixed(-1, -2),
54
- fixed(0, -2),
55
- fixed(1, -2),
56
- fixed(-2, -1),
57
- fixed(-1, -1),
58
- fixed(0, -1),
59
- fixed(1, -1),
60
- at(0),
61
- fixed(-2, 0),
62
- fixed(-1, 0)
151
+ {
152
+ kind: "fixed",
153
+ dx: -1,
154
+ dy: -2
155
+ },
156
+ {
157
+ kind: "fixed",
158
+ dx: 0,
159
+ dy: -2
160
+ },
161
+ {
162
+ kind: "fixed",
163
+ dx: 1,
164
+ dy: -2
165
+ },
166
+ {
167
+ kind: "fixed",
168
+ dx: -2,
169
+ dy: -1
170
+ },
171
+ {
172
+ kind: "fixed",
173
+ dx: -1,
174
+ dy: -1
175
+ },
176
+ {
177
+ kind: "fixed",
178
+ dx: 0,
179
+ dy: -1
180
+ },
181
+ {
182
+ kind: "fixed",
183
+ dx: 1,
184
+ dy: -1
185
+ },
186
+ {
187
+ kind: "at",
188
+ index: 0
189
+ },
190
+ {
191
+ kind: "fixed",
192
+ dx: -2,
193
+ dy: 0
194
+ },
195
+ {
196
+ kind: "fixed",
197
+ dx: -1,
198
+ dy: 0
199
+ }
63
200
  ],
64
201
  [
65
- fixed(-3, -1),
66
- fixed(-2, -1),
67
- fixed(-1, -1),
68
- fixed(0, -1),
69
- fixed(1, -1),
70
- at(0),
71
- fixed(-4, 0),
72
- fixed(-3, 0),
73
- fixed(-2, 0),
74
- fixed(-1, 0)
202
+ {
203
+ kind: "fixed",
204
+ dx: -3,
205
+ dy: -1
206
+ },
207
+ {
208
+ kind: "fixed",
209
+ dx: -2,
210
+ dy: -1
211
+ },
212
+ {
213
+ kind: "fixed",
214
+ dx: -1,
215
+ dy: -1
216
+ },
217
+ {
218
+ kind: "fixed",
219
+ dx: 0,
220
+ dy: -1
221
+ },
222
+ {
223
+ kind: "fixed",
224
+ dx: 1,
225
+ dy: -1
226
+ },
227
+ {
228
+ kind: "at",
229
+ index: 0
230
+ },
231
+ {
232
+ kind: "fixed",
233
+ dx: -4,
234
+ dy: 0
235
+ },
236
+ {
237
+ kind: "fixed",
238
+ dx: -3,
239
+ dy: 0
240
+ },
241
+ {
242
+ kind: "fixed",
243
+ dx: -2,
244
+ dy: 0
245
+ },
246
+ {
247
+ kind: "fixed",
248
+ dx: -1,
249
+ dy: 0
250
+ }
75
251
  ]
76
252
  ];
77
253
  const GENERIC_SLTP_CONTEXT = [
@@ -80,12 +256,7 @@ const GENERIC_SLTP_CONTEXT = [
80
256
  229,
81
257
  405
82
258
  ];
83
- const GENERIC_CONTEXT_BITS = [
84
- 16,
85
- 13,
86
- 10,
87
- 10
88
- ];
259
+ const GENERIC_CONTEXT_BITS = GENERIC_TEMPLATES.map((positions) => positions.length);
89
260
  function resolveTemplate(template) {
90
261
  const positions = GENERIC_TEMPLATES[template];
91
262
  if (positions === void 0) throw new require_image_jbig2_errors.Jbig2UnsupportedError(`generic region declares GBTEMPLATE ${String(template)}, which is outside the 0-3 range T.88 6.2.5.3 defines`);
@@ -200,7 +371,7 @@ const REFINEMENT_TEMPLATES = [[
200
371
  reference(1, 1)
201
372
  ]];
202
373
  const TPGRON_UNSUPPORTED = "JBIG2 refinement region sets TPGRON (typical prediction, T.88 6.3.5.6), whose per-template pseudo-context constants this decoder has no way to verify against a real encoder; refusing rather than risking a silently wrong bitmap";
203
- const REFINEMENT_CONTEXT_BITS = [13, 10];
374
+ const REFINEMENT_CONTEXT_BITS = REFINEMENT_TEMPLATES.map((positions) => positions.length);
204
375
  const NOMINAL_REFINEMENT_AT = [{
205
376
  x: -1,
206
377
  y: -1