pdf-parser.js 5.2.26 → 5.2.28

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 (221) 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.d.cts +2 -2
  7. package/dist/annotations.d.ts +2 -2
  8. package/dist/annotations.js +5 -3
  9. package/dist/attachments.d.cts +2 -2
  10. package/dist/attachments.d.ts +2 -2
  11. package/dist/builtin-encoding.cjs +17 -6
  12. package/dist/builtin-encoding.js +17 -6
  13. package/dist/bytes/crc32.cjs +5 -3
  14. package/dist/bytes/crc32.js +5 -3
  15. package/dist/bytes/flate.cjs +0 -1
  16. package/dist/bytes/flate.js +0 -1
  17. package/dist/cff-bounds.cjs +73 -45
  18. package/dist/cff-bounds.js +73 -45
  19. package/dist/cff.cjs +13 -6
  20. package/dist/cff.js +13 -6
  21. package/dist/cmap-table.cjs +54 -26
  22. package/dist/cmap-table.js +54 -26
  23. package/dist/cmap.cjs +5 -3
  24. package/dist/cmap.js +5 -3
  25. package/dist/content-read.d.cts +1 -1
  26. package/dist/content-read.d.ts +1 -1
  27. package/dist/content-write.cjs +21 -14
  28. package/dist/content-write.d.cts +2 -2
  29. package/dist/content-write.d.ts +2 -2
  30. package/dist/content-write.js +21 -14
  31. package/dist/crypto/aes.cjs +76 -55
  32. package/dist/crypto/aes.js +76 -55
  33. package/dist/crypto/md5.cjs +345 -149
  34. package/dist/crypto/md5.js +345 -149
  35. package/dist/crypto/rc4.cjs +5 -4
  36. package/dist/crypto/rc4.js +5 -4
  37. package/dist/crypto/sha2.cjs +92 -43
  38. package/dist/crypto/sha2.js +92 -43
  39. package/dist/document.cjs +17 -11
  40. package/dist/document.d.cts +1 -1
  41. package/dist/document.d.ts +1 -1
  42. package/dist/document.js +17 -11
  43. package/dist/{embedded-font-Bnhh4juV.d.ts → embedded-font-ByD7ZiQS.d.ts} +1 -1
  44. package/dist/{embedded-font-CEf-zBCA.d.cts → embedded-font-DgVBedw6.d.cts} +1 -1
  45. package/dist/embedded-font-write.d.cts +2 -2
  46. package/dist/embedded-font-write.d.ts +2 -2
  47. package/dist/embedded-font.cjs +4 -2
  48. package/dist/embedded-font.d.cts +1 -1
  49. package/dist/embedded-font.d.ts +1 -1
  50. package/dist/embedded-font.js +4 -2
  51. package/dist/encoding.cjs +1 -1
  52. package/dist/encoding.js +1 -1
  53. package/dist/encrypt-write.cjs +25 -21
  54. package/dist/encrypt-write.d.cts +1 -1
  55. package/dist/encrypt-write.d.ts +1 -1
  56. package/dist/encrypt-write.js +25 -21
  57. package/dist/encrypt.cjs +43 -64
  58. package/dist/encrypt.d.cts +1 -1
  59. package/dist/encrypt.d.ts +1 -1
  60. package/dist/encrypt.js +43 -64
  61. package/dist/filters.cjs +46 -26
  62. package/dist/filters.d.cts +1 -1
  63. package/dist/filters.d.ts +1 -1
  64. package/dist/filters.js +46 -26
  65. package/dist/font-face.cjs +2 -1
  66. package/dist/font-face.js +2 -1
  67. package/dist/font-read.cjs +12 -6
  68. package/dist/font-read.d.cts +1 -1
  69. package/dist/font-read.d.ts +1 -1
  70. package/dist/font-read.js +12 -6
  71. package/dist/font-registry.d.cts +3 -3
  72. package/dist/font-registry.d.ts +3 -3
  73. package/dist/font-tables.cjs +55 -28
  74. package/dist/font-tables.js +55 -28
  75. package/dist/form.cjs +13 -8
  76. package/dist/form.d.cts +2 -2
  77. package/dist/form.d.ts +2 -2
  78. package/dist/form.js +13 -8
  79. package/dist/gdef-table.cjs +6 -3
  80. package/dist/gdef-table.js +6 -3
  81. package/dist/{glyf-contours-C0epBNqP.d.ts → glyf-contours-B1PsI9oA.d.ts} +1 -1
  82. package/dist/{glyf-contours-BRpvd0rt.d.cts → glyf-contours-NHBpgks-.d.cts} +1 -1
  83. package/dist/glyf-contours.cjs +3 -1
  84. package/dist/glyf-contours.d.cts +1 -1
  85. package/dist/glyf-contours.d.ts +1 -1
  86. package/dist/glyf-contours.js +3 -1
  87. package/dist/glyf.cjs +22 -11
  88. package/dist/glyf.js +22 -11
  89. package/dist/gpos-table.cjs +37 -19
  90. package/dist/gpos-table.js +37 -19
  91. package/dist/gsub-table.cjs +40 -25
  92. package/dist/gsub-table.js +40 -25
  93. package/dist/hmtx-table.cjs +5 -3
  94. package/dist/hmtx-table.js +5 -3
  95. package/dist/image/ccitt-encode.cjs +8 -5
  96. package/dist/image/ccitt-encode.js +8 -5
  97. package/dist/image/ccitt.cjs +801 -209
  98. package/dist/image/ccitt.js +801 -209
  99. package/dist/image/jbig2-arith.cjs +340 -306
  100. package/dist/image/jbig2-arith.js +340 -306
  101. package/dist/image/jbig2-bitmap.cjs +8 -5
  102. package/dist/image/jbig2-bitmap.js +8 -5
  103. package/dist/image/jbig2-generic.cjs +240 -69
  104. package/dist/image/jbig2-generic.js +240 -69
  105. package/dist/image/jbig2-text.cjs +4 -2
  106. package/dist/image/jbig2-text.js +4 -2
  107. package/dist/image/jbig2.cjs +69 -31
  108. package/dist/image/jbig2.js +69 -31
  109. package/dist/image/jp2-boxes.cjs +52 -27
  110. package/dist/image/jp2-boxes.js +52 -27
  111. package/dist/image/jpeg-info.cjs +29 -24
  112. package/dist/image/jpeg-info.js +29 -24
  113. package/dist/image/jpeg2000-codestream.cjs +61 -32
  114. package/dist/image/jpeg2000-codestream.js +61 -32
  115. package/dist/image/jpeg2000-dwt.cjs +2 -1
  116. package/dist/image/jpeg2000-dwt.js +2 -1
  117. package/dist/image/jpeg2000-t1.cjs +21 -11
  118. package/dist/image/jpeg2000-t1.js +21 -11
  119. package/dist/image/jpeg2000-t2.cjs +12 -5
  120. package/dist/image/jpeg2000-t2.js +12 -5
  121. package/dist/image/jpeg2000-tagtree.cjs +8 -4
  122. package/dist/image/jpeg2000-tagtree.js +8 -4
  123. package/dist/image/jpeg2000.cjs +11 -6
  124. package/dist/image/jpeg2000.js +11 -6
  125. package/dist/image/png-decode.cjs +62 -39
  126. package/dist/image/png-decode.d.cts +3 -2
  127. package/dist/image/png-decode.d.ts +3 -2
  128. package/dist/image/png-decode.js +62 -39
  129. package/dist/image/png-filter.cjs +23 -15
  130. package/dist/image/png-filter.js +23 -15
  131. package/dist/images-read.cjs +41 -36
  132. package/dist/images-read.d.cts +2 -2
  133. package/dist/images-read.d.ts +2 -2
  134. package/dist/images-read.js +41 -36
  135. package/dist/index.cjs +1 -1
  136. package/dist/index.d.cts +1 -1
  137. package/dist/index.d.ts +1 -1
  138. package/dist/index.js +1 -1
  139. package/dist/interpret.cjs +68 -40
  140. package/dist/interpret.d.cts +1 -1
  141. package/dist/interpret.d.ts +1 -1
  142. package/dist/interpret.js +68 -40
  143. package/dist/lexer.cjs +86 -51
  144. package/dist/lexer.js +86 -51
  145. package/dist/math-content-write.cjs +9 -5
  146. package/dist/math-content-write.js +9 -5
  147. package/dist/math-font-write.cjs +2 -1
  148. package/dist/math-font-write.d.cts +1 -1
  149. package/dist/math-font-write.d.ts +1 -1
  150. package/dist/math-font-write.js +2 -1
  151. package/dist/math-font.cjs +16 -7
  152. package/dist/math-font.js +16 -7
  153. package/dist/math-table.cjs +25 -13
  154. package/dist/math-table.js +25 -13
  155. package/dist/matrix.cjs +3 -2
  156. package/dist/matrix.js +3 -2
  157. package/dist/measure.cjs +1 -1
  158. package/dist/measure.js +1 -1
  159. package/dist/names.cjs +7 -7
  160. package/dist/names.d.cts +2 -2
  161. package/dist/names.d.ts +2 -2
  162. package/dist/names.js +7 -7
  163. package/dist/navigation.cjs +16 -12
  164. package/dist/navigation.d.cts +4 -4
  165. package/dist/navigation.d.ts +4 -4
  166. package/dist/navigation.js +16 -12
  167. package/dist/{objects-B7HdMeWS.d.cts → objects-e2RS3-yT.d.cts} +3 -3
  168. package/dist/{objects-B7HdMeWS.d.ts → objects-e2RS3-yT.d.ts} +3 -3
  169. package/dist/objects.d.cts +1 -1
  170. package/dist/objects.d.ts +1 -1
  171. package/dist/optional-content.d.cts +2 -2
  172. package/dist/optional-content.d.ts +2 -2
  173. package/dist/ot-layout-common.cjs +22 -15
  174. package/dist/ot-layout-common.js +22 -15
  175. package/dist/parse.cjs +7 -5
  176. package/dist/parse.d.cts +1 -1
  177. package/dist/parse.d.ts +1 -1
  178. package/dist/parse.js +7 -5
  179. package/dist/pdf-text.cjs +5 -2
  180. package/dist/pdf-text.js +5 -2
  181. package/dist/predictors.cjs +14 -9
  182. package/dist/predictors.d.cts +1 -1
  183. package/dist/predictors.d.ts +1 -1
  184. package/dist/predictors.js +14 -9
  185. package/dist/raster.cjs +30 -19
  186. package/dist/raster.d.cts +8 -8
  187. package/dist/raster.d.ts +8 -8
  188. package/dist/raster.js +30 -19
  189. package/dist/read.cjs +29 -16
  190. package/dist/read.js +29 -16
  191. package/dist/serialize.cjs +6 -2
  192. package/dist/serialize.d.cts +1 -1
  193. package/dist/serialize.d.ts +1 -1
  194. package/dist/serialize.js +6 -2
  195. package/dist/sfnt-subset.cjs +25 -13
  196. package/dist/sfnt-subset.d.cts +1 -1
  197. package/dist/sfnt-subset.d.ts +1 -1
  198. package/dist/sfnt-subset.js +25 -13
  199. package/dist/sfnt.cjs +20 -10
  200. package/dist/sfnt.js +20 -10
  201. package/dist/structure.d.cts +2 -2
  202. package/dist/structure.d.ts +2 -2
  203. package/dist/text-group.cjs +0 -1
  204. package/dist/text-group.js +0 -1
  205. package/dist/text-layout.d.cts +1 -1
  206. package/dist/text-layout.d.ts +1 -1
  207. package/dist/tounicode.cjs +4 -2
  208. package/dist/tounicode.d.cts +1 -1
  209. package/dist/tounicode.d.ts +1 -1
  210. package/dist/tounicode.js +4 -2
  211. package/dist/winansi.cjs +1 -1
  212. package/dist/winansi.js +1 -1
  213. package/dist/write.cjs +20 -12
  214. package/dist/write.d.cts +1 -1
  215. package/dist/write.d.ts +1 -1
  216. package/dist/write.js +20 -12
  217. package/dist/xref.cjs +5 -2
  218. package/dist/xref.d.cts +1 -1
  219. package/dist/xref.d.ts +1 -1
  220. package/dist/xref.js +5 -2
  221. package/package.json +1 -1
@@ -11,17 +11,28 @@ const DEFAULT_GSUB_FEATURE_TAGS = [
11
11
  ];
12
12
  const GSUB_OPT_IN_FEATURE_TAGS = ["smcp", "dlig"];
13
13
  const GSUB_HEADER_SIZE = 10;
14
+ const GSUB_HEADER_SCRIPT_LIST_OFFSET = 4;
15
+ const GSUB_HEADER_FEATURE_LIST_OFFSET = 6;
16
+ const GSUB_HEADER_LOOKUP_LIST_OFFSET = 8;
14
17
  const SCRIPT_RECORD_SIZE = 6;
18
+ const SCRIPT_RECORD_OFFSET_FIELD_OFFSET = 4;
15
19
  const FEATURE_RECORD_SIZE = 6;
20
+ const FEATURE_RECORD_OFFSET_FIELD_OFFSET = 4;
16
21
  const LANG_SYS_HEADER_SIZE = 6;
22
+ const LANG_SYS_FEATURE_INDEX_COUNT_OFFSET = 4;
17
23
  const FEATURE_HEADER_SIZE = 4;
18
24
  const LOOKUP_HEADER_SIZE = 6;
25
+ const LOOKUP_HEADER_SUBTABLE_COUNT_OFFSET = 4;
19
26
  const LOOKUP_TYPE_SINGLE_SUBST = 1;
20
27
  const LOOKUP_TYPE_LIGATURE_SUBST = 4;
21
28
  const LOOKUP_TYPE_CONTEXT_SUBST = 5;
22
29
  const LOOKUP_TYPE_CHAIN_CONTEXT_SUBST = 6;
23
30
  const LOOKUP_TYPE_EXTENSION_SUBST = 7;
24
31
  const EXTENSION_SUBST_HEADER_SIZE = 8;
32
+ const EXTENSION_SUBST_OFFSET_FIELD_OFFSET = 4;
33
+ const BITS_PER_BYTE = 8;
34
+ const BYTE_MASK = 255;
35
+ const SUBST_FORMAT_AND_COVERAGE_SIZE = 4;
25
36
  const LOOKUP_FLAG_IGNORE_BASE_GLYPHS = 2;
26
37
  const LOOKUP_FLAG_IGNORE_LIGATURES = 4;
27
38
  const LOOKUP_FLAG_IGNORE_MARKS = 8;
@@ -30,14 +41,14 @@ const LOOKUP_FLAG_MARK_ATTACHMENT_TYPE = 65280;
30
41
  const MAX_LOOKUP_NESTING_DEPTH = 6;
31
42
  const PREFERRED_SCRIPT_TAGS = ["latn", "DFLT"];
32
43
  function readTag(bytes, offset) {
33
- return String.fromCharCode(u16(bytes, offset) >> 8, u16(bytes, offset) & 255, u16(bytes, offset + 2) >> 8, u16(bytes, offset + 2) & 255);
44
+ return String.fromCharCode(u16(bytes, offset) >> BITS_PER_BYTE, u16(bytes, offset) & BYTE_MASK, u16(bytes, offset + 2) >> BITS_PER_BYTE, u16(bytes, offset + 2) & BYTE_MASK);
34
45
  }
35
46
  function glyphSkipper(lookupFlag, markFilteringSet, gdef) {
36
47
  if (gdef === void 0 || lookupFlag === 0) return () => false;
37
48
  const ignoreBase = (lookupFlag & LOOKUP_FLAG_IGNORE_BASE_GLYPHS) !== 0;
38
49
  const ignoreLigatures = (lookupFlag & LOOKUP_FLAG_IGNORE_LIGATURES) !== 0;
39
50
  const ignoreMarks = (lookupFlag & LOOKUP_FLAG_IGNORE_MARKS) !== 0;
40
- const markAttachmentType = (lookupFlag & LOOKUP_FLAG_MARK_ATTACHMENT_TYPE) >> 8;
51
+ const markAttachmentType = (lookupFlag & LOOKUP_FLAG_MARK_ATTACHMENT_TYPE) >> BITS_PER_BYTE;
41
52
  const useMarkFilteringSet = (lookupFlag & LOOKUP_FLAG_USE_MARK_FILTERING_SET) !== 0;
42
53
  return (glyphId) => {
43
54
  const glyphClass = gdef.glyphClass(glyphId);
@@ -60,7 +71,7 @@ function parseSingleSubstFormat1(bytes, subtableOffset, skip) {
60
71
  if (!hasBytes(bytes, subtableOffset, SINGLE_SUBST_FORMAT_1_SIZE)) return;
61
72
  const coverage = parseCoverage(bytes, subtableOffset + u16(bytes, subtableOffset + 2));
62
73
  if (coverage === void 0) return;
63
- const delta = i16(bytes, subtableOffset + 4);
74
+ const delta = i16(bytes, subtableOffset + SUBST_FORMAT_AND_COVERAGE_SIZE);
64
75
  return (slots, index) => {
65
76
  const slot = slots[index];
66
77
  if (skip(slot.glyphId)) return;
@@ -79,7 +90,7 @@ function parseSingleSubstFormat2(bytes, subtableOffset, skip) {
79
90
  if (!hasBytes(bytes, subtableOffset, SINGLE_SUBST_FORMAT_2_HEADER_SIZE)) return;
80
91
  const coverage = parseCoverage(bytes, subtableOffset + u16(bytes, subtableOffset + 2));
81
92
  if (coverage === void 0) return;
82
- const glyphCount = u16(bytes, subtableOffset + 4);
93
+ const glyphCount = u16(bytes, subtableOffset + SUBST_FORMAT_AND_COVERAGE_SIZE);
83
94
  const substitutesOffset = subtableOffset + SINGLE_SUBST_FORMAT_2_HEADER_SIZE;
84
95
  if (!hasBytes(bytes, substitutesOffset, glyphCount * 2)) return;
85
96
  return (slots, index) => {
@@ -103,7 +114,7 @@ function parseLigatureSubstFormat1(bytes, subtableOffset, skip) {
103
114
  if (!hasBytes(bytes, subtableOffset, LIGATURE_SUBST_FORMAT_1_HEADER_SIZE)) return;
104
115
  const coverage = parseCoverage(bytes, subtableOffset + u16(bytes, subtableOffset + 2));
105
116
  if (coverage === void 0) return;
106
- const ligSetCount = u16(bytes, subtableOffset + 4);
117
+ const ligSetCount = u16(bytes, subtableOffset + SUBST_FORMAT_AND_COVERAGE_SIZE);
107
118
  const ligSetOffsetsOffset = subtableOffset + LIGATURE_SUBST_FORMAT_1_HEADER_SIZE;
108
119
  if (!hasBytes(bytes, ligSetOffsetsOffset, ligSetCount * 2)) return;
109
120
  return (slots, index) => {
@@ -192,7 +203,10 @@ function applyContextualRule(slots, inputSlots, records, lookupOf, skip, depth)
192
203
  const lookup = lookupOf(record.lookupIndex);
193
204
  if (lookup === void 0 || record.sequenceIndex >= inputSlots.length || depth >= MAX_LOOKUP_NESTING_DEPTH) return;
194
205
  const target = visibleInputSlot(window, record.sequenceIndex, skip);
195
- if (target !== void 0) applyLookupAtSlot(window, target, lookup, depth + 1);
206
+ if (target !== void 0) {
207
+ const application = applyLookupAtSlot(window, target, lookup, depth + 1);
208
+ if (application !== void 0) window.splice(target, application.consumed, ...application.replacement);
209
+ }
196
210
  }
197
211
  return {
198
212
  consumed: last - first + 1,
@@ -210,12 +224,8 @@ function visibleInputSlot(window, position, skip) {
210
224
  function applyLookupAtSlot(slots, index, lookup, depth) {
211
225
  for (const subtable of lookup.subtables) {
212
226
  const application = subtable(slots, index, depth);
213
- if (application !== void 0) {
214
- slots.splice(index, application.consumed, ...application.replacement);
215
- return application.replacement.length;
216
- }
227
+ if (application !== void 0) return application;
217
228
  }
218
- return 0;
219
229
  }
220
230
  const SUBST_LOOKUP_RECORD_SIZE = 4;
221
231
  function readSubstLookupRecords(bytes, offset, count) {
@@ -360,7 +370,7 @@ function parseSubtable(bytes, lookupType, subtableOffset, skip, lookupOf) {
360
370
  if (!hasBytes(bytes, subtableOffset, EXTENSION_SUBST_HEADER_SIZE) || u16(bytes, subtableOffset) !== 1) return;
361
371
  const extensionLookupType = u16(bytes, subtableOffset + 2);
362
372
  if (extensionLookupType === LOOKUP_TYPE_EXTENSION_SUBST) return;
363
- return parseSubtable(bytes, extensionLookupType, subtableOffset + u32(bytes, subtableOffset + 4), skip, lookupOf);
373
+ return parseSubtable(bytes, extensionLookupType, subtableOffset + u32(bytes, subtableOffset + EXTENSION_SUBST_OFFSET_FIELD_OFFSET), skip, lookupOf);
364
374
  }
365
375
  if (lookupType === LOOKUP_TYPE_SINGLE_SUBST) {
366
376
  if (!hasBytes(bytes, subtableOffset, 2)) return;
@@ -388,7 +398,7 @@ function parseContextualSubtable(bytes, chained, subtableOffset, skip, lookupOf)
388
398
  if (!hasBytes(bytes, subtableOffset, prefixSize)) return;
389
399
  const coverage = parseCoverage(bytes, subtableOffset + u16(bytes, subtableOffset + 2));
390
400
  if (coverage === void 0) return;
391
- const setCount = u16(bytes, subtableOffset + 4);
401
+ const setCount = u16(bytes, subtableOffset + SUBST_FORMAT_AND_COVERAGE_SIZE);
392
402
  const setOffsetsOffset = subtableOffset + prefixSize;
393
403
  if (!hasBytes(bytes, setOffsetsOffset, setCount * 2)) return;
394
404
  const glyphEquality = (expected) => (glyphId) => glyphId === expected;
@@ -404,10 +414,10 @@ function parseContextualSubtable(bytes, chained, subtableOffset, skip, lookupOf)
404
414
  if (!hasBytes(bytes, subtableOffset, prefixSize)) return;
405
415
  const coverage = parseCoverage(bytes, subtableOffset + u16(bytes, subtableOffset + 2));
406
416
  if (coverage === void 0) return;
407
- const inputClassDefOffset = chained ? u16(bytes, subtableOffset + 6) : u16(bytes, subtableOffset + 4);
417
+ const inputClassDefOffset = chained ? u16(bytes, subtableOffset + 6) : u16(bytes, subtableOffset + SUBST_FORMAT_AND_COVERAGE_SIZE);
408
418
  const inputClassDef = inputClassDefOffset === 0 ? constantZeroClassDef : parseClassDef(bytes, subtableOffset + inputClassDefOffset);
409
419
  const readAuxClassDef = (offset) => offset === 0 ? constantZeroClassDef : parseClassDef(bytes, subtableOffset + offset);
410
- const backtrackClassDef = chained ? readAuxClassDef(u16(bytes, subtableOffset + 4)) : constantZeroClassDef;
420
+ const backtrackClassDef = chained ? readAuxClassDef(u16(bytes, subtableOffset + SUBST_FORMAT_AND_COVERAGE_SIZE)) : constantZeroClassDef;
411
421
  const lookaheadClassDef = chained ? readAuxClassDef(u16(bytes, subtableOffset + 8)) : constantZeroClassDef;
412
422
  if (inputClassDef === void 0 || backtrackClassDef === void 0 || lookaheadClassDef === void 0) return;
413
423
  const setCount = u16(bytes, subtableOffset + prefixSize - 2);
@@ -429,9 +439,9 @@ function findScriptOffset(bytes, scriptListOffset) {
429
439
  if (!hasBytes(bytes, recordsOffset, scriptCount * SCRIPT_RECORD_SIZE) || scriptCount === 0) return;
430
440
  for (const wanted of PREFERRED_SCRIPT_TAGS) for (let i = 0; i < scriptCount; i++) {
431
441
  const recordOffset = recordsOffset + i * SCRIPT_RECORD_SIZE;
432
- if (readTag(bytes, recordOffset) === wanted) return scriptListOffset + u16(bytes, recordOffset + 4);
442
+ if (readTag(bytes, recordOffset) === wanted) return scriptListOffset + u16(bytes, recordOffset + SCRIPT_RECORD_OFFSET_FIELD_OFFSET);
433
443
  }
434
- return scriptListOffset + u16(bytes, recordsOffset + 4);
444
+ return scriptListOffset + u16(bytes, recordsOffset + SCRIPT_RECORD_OFFSET_FIELD_OFFSET);
435
445
  }
436
446
  function parseDefaultLangSysFeatureIndices(bytes, scriptOffset) {
437
447
  if (!hasBytes(bytes, scriptOffset, 2)) return [];
@@ -439,7 +449,7 @@ function parseDefaultLangSysFeatureIndices(bytes, scriptOffset) {
439
449
  if (defaultLangSysOffset === 0) return [];
440
450
  const langSysOffset = scriptOffset + defaultLangSysOffset;
441
451
  if (!hasBytes(bytes, langSysOffset, LANG_SYS_HEADER_SIZE)) return [];
442
- const featureIndexCount = u16(bytes, langSysOffset + 4);
452
+ const featureIndexCount = u16(bytes, langSysOffset + LANG_SYS_FEATURE_INDEX_COUNT_OFFSET);
443
453
  const indicesOffset = langSysOffset + LANG_SYS_HEADER_SIZE;
444
454
  if (!hasBytes(bytes, indicesOffset, featureIndexCount * 2)) return [];
445
455
  const indices = [];
@@ -457,7 +467,7 @@ function collectLookupIndices(bytes, featureListOffset, featureIndices, featureT
457
467
  if (featureIndex >= featureCount) continue;
458
468
  const recordOffset = recordsOffset + featureIndex * FEATURE_RECORD_SIZE;
459
469
  if (!featureTags.includes(readTag(bytes, recordOffset))) continue;
460
- const featureOffset = featureListOffset + u16(bytes, recordOffset + 4);
470
+ const featureOffset = featureListOffset + u16(bytes, recordOffset + FEATURE_RECORD_OFFSET_FIELD_OFFSET);
461
471
  if (!hasBytes(bytes, featureOffset, FEATURE_HEADER_SIZE)) continue;
462
472
  const lookupIndexCount = u16(bytes, featureOffset + 2);
463
473
  const indicesOffset = featureOffset + FEATURE_HEADER_SIZE;
@@ -475,12 +485,12 @@ function collectLookupIndices(bytes, featureListOffset, featureIndices, featureT
475
485
  function buildGsubShaper(font, options = {}) {
476
486
  const bytes = sfntTableBytes(font, "GSUB");
477
487
  if (bytes === void 0 || !hasBytes(bytes, 0, GSUB_HEADER_SIZE) || u16(bytes, 0) !== 1) return;
478
- const scriptOffset = findScriptOffset(bytes, u16(bytes, 4));
488
+ const scriptOffset = findScriptOffset(bytes, u16(bytes, GSUB_HEADER_SCRIPT_LIST_OFFSET));
479
489
  if (scriptOffset === void 0) return;
480
490
  const featureTags = [...DEFAULT_GSUB_FEATURE_TAGS, ...options.optInFeatures ?? []];
481
- const lookupIndices = collectLookupIndices(bytes, u16(bytes, 6), parseDefaultLangSysFeatureIndices(bytes, scriptOffset), featureTags);
491
+ const lookupIndices = collectLookupIndices(bytes, u16(bytes, GSUB_HEADER_FEATURE_LIST_OFFSET), parseDefaultLangSysFeatureIndices(bytes, scriptOffset), featureTags);
482
492
  if (lookupIndices.length === 0) return;
483
- const lookupListOffset = u16(bytes, 8);
493
+ const lookupListOffset = u16(bytes, GSUB_HEADER_LOOKUP_LIST_OFFSET);
484
494
  if (!hasBytes(bytes, lookupListOffset, 2)) return;
485
495
  const lookupCount = u16(bytes, lookupListOffset);
486
496
  const lookupOffsetsOffset = lookupListOffset + 2;
@@ -496,7 +506,7 @@ function buildGsubShaper(font, options = {}) {
496
506
  }
497
507
  const lookupFlag = u16(bytes, lookupOffset + 2);
498
508
  const lookupType = u16(bytes, lookupOffset);
499
- const subTableCount = u16(bytes, lookupOffset + 4);
509
+ const subTableCount = u16(bytes, lookupOffset + LOOKUP_HEADER_SUBTABLE_COUNT_OFFSET);
500
510
  const subtableOffsetsOffset = lookupOffset + LOOKUP_HEADER_SIZE;
501
511
  const markFilteringSetWidth = (lookupFlag & LOOKUP_FLAG_USE_MARK_FILTERING_SET) !== 0 ? 2 : 0;
502
512
  if (!hasBytes(bytes, subtableOffsetsOffset, subTableCount * 2 + markFilteringSetWidth)) {
@@ -525,8 +535,13 @@ function buildGsubShaper(font, options = {}) {
525
535
  for (const lookup of appliedLookups) {
526
536
  let slotIndex = 0;
527
537
  while (slotIndex < slots.length) {
528
- const advanced = applyLookupAtSlot(slots, slotIndex, lookup, 0);
529
- slotIndex += advanced !== 0 ? advanced : 1;
538
+ const application = applyLookupAtSlot(slots, slotIndex, lookup, 0);
539
+ if (application === void 0) {
540
+ slotIndex += 1;
541
+ continue;
542
+ }
543
+ slots.splice(slotIndex, application.consumed, ...application.replacement);
544
+ slotIndex += application.replacement.length !== 0 ? application.replacement.length : 1;
530
545
  }
531
546
  }
532
547
  return {
@@ -1,15 +1,17 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_sfnt = require("./sfnt.cjs");
3
3
  //#region src/hmtx-table.ts
4
+ const HHEA_NUMBER_OF_H_METRICS_OFFSET = 34;
5
+ const HMTX_LONG_HOR_METRIC_SIZE_BYTES = 4;
4
6
  function parseHmtx(font) {
5
7
  const hheaBytes = require_sfnt.sfntTableBytes(font, "hhea");
6
8
  const hmtxBytes = require_sfnt.sfntTableBytes(font, "hmtx");
7
9
  if (hheaBytes === void 0 || hmtxBytes === void 0) throw new Error("font has no hhea/hmtx table");
8
- const numberOfHMetrics = require_sfnt.u16(hheaBytes, 34);
10
+ const numberOfHMetrics = require_sfnt.u16(hheaBytes, HHEA_NUMBER_OF_H_METRICS_OFFSET);
9
11
  if (numberOfHMetrics === 0) throw new Error("font hhea numberOfHMetrics is zero");
10
- const lastWidth = require_sfnt.u16(hmtxBytes, (numberOfHMetrics - 1) * 4);
12
+ const lastWidth = require_sfnt.u16(hmtxBytes, (numberOfHMetrics - 1) * HMTX_LONG_HOR_METRIC_SIZE_BYTES);
11
13
  return { advanceWidth(glyphId) {
12
- if (glyphId < numberOfHMetrics) return require_sfnt.u16(hmtxBytes, glyphId * 4);
14
+ if (glyphId < numberOfHMetrics) return require_sfnt.u16(hmtxBytes, glyphId * HMTX_LONG_HOR_METRIC_SIZE_BYTES);
13
15
  return lastWidth;
14
16
  } };
15
17
  }
@@ -1,14 +1,16 @@
1
1
  import { sfntTableBytes, u16 } from "./sfnt.js";
2
2
  //#region src/hmtx-table.ts
3
+ const HHEA_NUMBER_OF_H_METRICS_OFFSET = 34;
4
+ const HMTX_LONG_HOR_METRIC_SIZE_BYTES = 4;
3
5
  function parseHmtx(font) {
4
6
  const hheaBytes = sfntTableBytes(font, "hhea");
5
7
  const hmtxBytes = sfntTableBytes(font, "hmtx");
6
8
  if (hheaBytes === void 0 || hmtxBytes === void 0) throw new Error("font has no hhea/hmtx table");
7
- const numberOfHMetrics = u16(hheaBytes, 34);
9
+ const numberOfHMetrics = u16(hheaBytes, HHEA_NUMBER_OF_H_METRICS_OFFSET);
8
10
  if (numberOfHMetrics === 0) throw new Error("font hhea numberOfHMetrics is zero");
9
- const lastWidth = u16(hmtxBytes, (numberOfHMetrics - 1) * 4);
11
+ const lastWidth = u16(hmtxBytes, (numberOfHMetrics - 1) * HMTX_LONG_HOR_METRIC_SIZE_BYTES);
10
12
  return { advanceWidth(glyphId) {
11
- if (glyphId < numberOfHMetrics) return u16(hmtxBytes, glyphId * 4);
13
+ if (glyphId < numberOfHMetrics) return u16(hmtxBytes, glyphId * HMTX_LONG_HOR_METRIC_SIZE_BYTES);
12
14
  return lastWidth;
13
15
  } };
14
16
  }
@@ -22,6 +22,9 @@ const VERTICAL_MODES = /* @__PURE__ */ new Map([
22
22
  ]);
23
23
  const LARGEST_MAKEUP_RUN = 2560;
24
24
  const MAKEUP_GRANULARITY = 64;
25
+ const BITS_PER_BYTE = 8;
26
+ const BYTE_INDEX_SHIFT = 3;
27
+ const BYTE_BIT_MASK = 7;
25
28
  var BitWriter = class {
26
29
  bytes = [];
27
30
  current = 0;
@@ -33,7 +36,7 @@ var BitWriter = class {
33
36
  for (const char of bits) {
34
37
  this.current = this.current << 1 | (char === "1" ? 1 : 0);
35
38
  this.used++;
36
- if (this.used === 8) {
39
+ if (this.used === BITS_PER_BYTE) {
37
40
  this.bytes.push(this.current);
38
41
  this.current = 0;
39
42
  this.used = 0;
@@ -41,7 +44,7 @@ var BitWriter = class {
41
44
  }
42
45
  }
43
46
  finish() {
44
- if (this.used > 0) this.bytes.push(this.current << 8 - this.used);
47
+ if (this.used > 0) this.bytes.push(this.current << BITS_PER_BYTE - this.used);
45
48
  return new Uint8Array(this.bytes);
46
49
  }
47
50
  };
@@ -59,7 +62,7 @@ function changingElements(bitmap, rowByteOffset, columns) {
59
62
  const changes = [];
60
63
  let previous = 1;
61
64
  for (let x = 0; x < columns; x++) {
62
- const pixel = (bitmap[rowByteOffset + (x >> 3)] ?? 0) >> 7 - (x & 7) & 1;
65
+ const pixel = (bitmap[rowByteOffset + (x >> BYTE_INDEX_SHIFT)] ?? 0) >> BYTE_BIT_MASK - (x & BYTE_BIT_MASK) & 1;
63
66
  if (pixel !== previous) {
64
67
  changes.push(x);
65
68
  previous = pixel;
@@ -70,7 +73,7 @@ function changingElements(bitmap, rowByteOffset, columns) {
70
73
  function encodeCcittFax(bitmap, options) {
71
74
  const { columns, rows, maxBytes } = options;
72
75
  if (columns <= 0 || rows <= 0) return /* @__PURE__ */ new Uint8Array(0);
73
- const rowBytes = columns + 7 >> 3;
76
+ const rowBytes = columns + BYTE_BIT_MASK >> BYTE_INDEX_SHIFT;
74
77
  const writer = new BitWriter();
75
78
  let reference = [];
76
79
  for (let y = 0; y < rows; y++) {
@@ -109,7 +112,7 @@ function encodeCcittFax(bitmap, options) {
109
112
  ci += 2;
110
113
  }
111
114
  }
112
- if (a0 < columns) white = ((bitmap[offset + (a0 >> 3)] ?? 0) >> 7 - (a0 & 7) & 1) === 1;
115
+ if (a0 < columns) white = ((bitmap[offset + (a0 >> BYTE_INDEX_SHIFT)] ?? 0) >> BYTE_BIT_MASK - (a0 & BYTE_BIT_MASK) & 1) === 1;
113
116
  }
114
117
  reference = current;
115
118
  }
@@ -21,6 +21,9 @@ const VERTICAL_MODES = /* @__PURE__ */ new Map([
21
21
  ]);
22
22
  const LARGEST_MAKEUP_RUN = 2560;
23
23
  const MAKEUP_GRANULARITY = 64;
24
+ const BITS_PER_BYTE = 8;
25
+ const BYTE_INDEX_SHIFT = 3;
26
+ const BYTE_BIT_MASK = 7;
24
27
  var BitWriter = class {
25
28
  bytes = [];
26
29
  current = 0;
@@ -32,7 +35,7 @@ var BitWriter = class {
32
35
  for (const char of bits) {
33
36
  this.current = this.current << 1 | (char === "1" ? 1 : 0);
34
37
  this.used++;
35
- if (this.used === 8) {
38
+ if (this.used === BITS_PER_BYTE) {
36
39
  this.bytes.push(this.current);
37
40
  this.current = 0;
38
41
  this.used = 0;
@@ -40,7 +43,7 @@ var BitWriter = class {
40
43
  }
41
44
  }
42
45
  finish() {
43
- if (this.used > 0) this.bytes.push(this.current << 8 - this.used);
46
+ if (this.used > 0) this.bytes.push(this.current << BITS_PER_BYTE - this.used);
44
47
  return new Uint8Array(this.bytes);
45
48
  }
46
49
  };
@@ -58,7 +61,7 @@ function changingElements(bitmap, rowByteOffset, columns) {
58
61
  const changes = [];
59
62
  let previous = 1;
60
63
  for (let x = 0; x < columns; x++) {
61
- const pixel = (bitmap[rowByteOffset + (x >> 3)] ?? 0) >> 7 - (x & 7) & 1;
64
+ const pixel = (bitmap[rowByteOffset + (x >> BYTE_INDEX_SHIFT)] ?? 0) >> BYTE_BIT_MASK - (x & BYTE_BIT_MASK) & 1;
62
65
  if (pixel !== previous) {
63
66
  changes.push(x);
64
67
  previous = pixel;
@@ -69,7 +72,7 @@ function changingElements(bitmap, rowByteOffset, columns) {
69
72
  function encodeCcittFax(bitmap, options) {
70
73
  const { columns, rows, maxBytes } = options;
71
74
  if (columns <= 0 || rows <= 0) return /* @__PURE__ */ new Uint8Array(0);
72
- const rowBytes = columns + 7 >> 3;
75
+ const rowBytes = columns + BYTE_BIT_MASK >> BYTE_INDEX_SHIFT;
73
76
  const writer = new BitWriter();
74
77
  let reference = [];
75
78
  for (let y = 0; y < rows; y++) {
@@ -108,7 +111,7 @@ function encodeCcittFax(bitmap, options) {
108
111
  ci += 2;
109
112
  }
110
113
  }
111
- if (a0 < columns) white = ((bitmap[offset + (a0 >> 3)] ?? 0) >> 7 - (a0 & 7) & 1) === 1;
114
+ if (a0 < columns) white = ((bitmap[offset + (a0 >> BYTE_INDEX_SHIFT)] ?? 0) >> BYTE_BIT_MASK - (a0 & BYTE_BIT_MASK) & 1) === 1;
112
115
  }
113
116
  reference = current;
114
117
  }