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
@@ -3,17 +3,28 @@ import { hasBytes, sfntTableBytes, u16, u32, u8 } from "./sfnt.js";
3
3
  const CMAP_HEADER_SIZE = 4;
4
4
  const SUBTABLE_RECORD_SIZE = 8;
5
5
  const MAX_UNICODE_CODE_POINT = 1114111;
6
+ const SUBTABLE_RECORD_OFFSET_FIELD = 4;
7
+ const CMAP_FORMAT_4 = 4;
8
+ const CMAP_FORMAT_6 = 6;
9
+ const CMAP_FORMAT_12 = 12;
10
+ const INT16_SIGN_BIT = 32768;
11
+ const UINT16_MODULUS = 65536;
12
+ const UINT16_MASK = 65535;
6
13
  const FORMAT_4_HEADER_SIZE = 14;
14
+ const FORMAT_4_SEG_COUNT_X2_FIELD = 6;
15
+ const FORMAT_4_PARALLEL_ARRAY_COUNT = 4;
16
+ const MAX_BMP_CODE_POINT = 65535;
17
+ const LAST_MAPPABLE_BMP_CODE = 65534;
7
18
  function parseFormat4(bytes, subtableOffset) {
8
19
  if (!hasBytes(bytes, subtableOffset, FORMAT_4_HEADER_SIZE)) return;
9
- const segCountX2 = u16(bytes, subtableOffset + 6);
20
+ const segCountX2 = u16(bytes, subtableOffset + FORMAT_4_SEG_COUNT_X2_FIELD);
10
21
  if (segCountX2 === 0 || segCountX2 % 2 !== 0) return;
11
22
  const segCount = segCountX2 / 2;
12
23
  const endCodesOffset = subtableOffset + FORMAT_4_HEADER_SIZE;
13
24
  const startCodesOffset = endCodesOffset + segCountX2 + 2;
14
25
  const idDeltasOffset = startCodesOffset + segCountX2;
15
26
  const idRangeOffsetsOffset = idDeltasOffset + segCountX2;
16
- if (!hasBytes(bytes, endCodesOffset, segCountX2 * 4 + 2)) return;
27
+ if (!hasBytes(bytes, endCodesOffset, segCountX2 * FORMAT_4_PARALLEL_ARRAY_COUNT + 2)) return;
17
28
  const segments = [];
18
29
  for (let i = 0; i < segCount; i++) {
19
30
  const idRangeOffsetPos = idRangeOffsetsOffset + i * 2;
@@ -21,27 +32,27 @@ function parseFormat4(bytes, subtableOffset) {
21
32
  segments.push({
22
33
  endCode: u16(bytes, endCodesOffset + i * 2),
23
34
  startCode: u16(bytes, startCodesOffset + i * 2),
24
- idDelta: rawDelta >= 32768 ? rawDelta - 65536 : rawDelta,
35
+ idDelta: rawDelta >= INT16_SIGN_BIT ? rawDelta - UINT16_MODULUS : rawDelta,
25
36
  idRangeOffsetPos,
26
37
  idRangeOffset: u16(bytes, idRangeOffsetPos)
27
38
  });
28
39
  }
29
40
  const lookup = (codePoint) => {
30
- if (codePoint > 65535) return;
41
+ if (codePoint > MAX_BMP_CODE_POINT) return;
31
42
  for (const segment of segments) {
32
43
  if (codePoint < segment.startCode || codePoint > segment.endCode) continue;
33
- if (segment.idRangeOffset === 0) return codePoint + segment.idDelta & 65535;
44
+ if (segment.idRangeOffset === 0) return codePoint + segment.idDelta & UINT16_MASK;
34
45
  const glyphIndexAddress = segment.idRangeOffsetPos + segment.idRangeOffset + (codePoint - segment.startCode) * 2;
35
46
  if (!hasBytes(bytes, glyphIndexAddress, 2)) return;
36
47
  const glyphId = u16(bytes, glyphIndexAddress);
37
- return glyphId === 0 ? void 0 : glyphId + segment.idDelta & 65535;
48
+ return glyphId === 0 ? void 0 : glyphId + segment.idDelta & UINT16_MASK;
38
49
  }
39
50
  };
40
51
  return {
41
52
  lookup,
42
53
  forEachMapping(visit) {
43
54
  for (const segment of segments) {
44
- const end = Math.min(segment.endCode, 65534);
55
+ const end = Math.min(segment.endCode, LAST_MAPPABLE_BMP_CODE);
45
56
  for (let code = segment.startCode; code <= end; code++) {
46
57
  const glyphId = lookup(code);
47
58
  if (glyphId !== void 0 && glyphId !== 0) visit(code, glyphId);
@@ -51,10 +62,13 @@ function parseFormat4(bytes, subtableOffset) {
51
62
  };
52
63
  }
53
64
  const FORMAT_12_HEADER_SIZE = 16;
65
+ const FORMAT_12_NUM_GROUPS_FIELD = 12;
54
66
  const FORMAT_12_GROUP_SIZE = 12;
67
+ const FORMAT_12_GROUP_END_CHAR_CODE_FIELD = 4;
68
+ const FORMAT_12_GROUP_START_GLYPH_ID_FIELD = 8;
55
69
  function parseFormat12(bytes, subtableOffset) {
56
70
  if (!hasBytes(bytes, subtableOffset, FORMAT_12_HEADER_SIZE)) return;
57
- const numGroups = u32(bytes, subtableOffset + 12);
71
+ const numGroups = u32(bytes, subtableOffset + FORMAT_12_NUM_GROUPS_FIELD);
58
72
  const groupsOffset = subtableOffset + FORMAT_12_HEADER_SIZE;
59
73
  if (!hasBytes(bytes, groupsOffset, numGroups * FORMAT_12_GROUP_SIZE)) return;
60
74
  const groups = [];
@@ -62,8 +76,8 @@ function parseFormat12(bytes, subtableOffset) {
62
76
  const recordOffset = groupsOffset + i * FORMAT_12_GROUP_SIZE;
63
77
  groups.push({
64
78
  startCharCode: u32(bytes, recordOffset),
65
- endCharCode: u32(bytes, recordOffset + 4),
66
- startGlyphId: u32(bytes, recordOffset + 8)
79
+ endCharCode: u32(bytes, recordOffset + FORMAT_12_GROUP_END_CHAR_CODE_FIELD),
80
+ startGlyphId: u32(bytes, recordOffset + FORMAT_12_GROUP_START_GLYPH_ID_FIELD)
67
81
  });
68
82
  }
69
83
  return {
@@ -79,18 +93,20 @@ function parseFormat12(bytes, subtableOffset) {
79
93
  };
80
94
  }
81
95
  const FORMAT_0_SIZE = 262;
96
+ const FORMAT_0_GLYPH_ID_ARRAY_OFFSET = 6;
97
+ const MAX_FORMAT_0_CODE = 255;
82
98
  function parseFormat0(bytes, subtableOffset) {
83
99
  if (!hasBytes(bytes, subtableOffset, FORMAT_0_SIZE)) return;
84
- const glyphIdArrayOffset = subtableOffset + 6;
100
+ const glyphIdArrayOffset = subtableOffset + FORMAT_0_GLYPH_ID_ARRAY_OFFSET;
85
101
  const lookup = (codePoint) => {
86
- if (codePoint < 0 || codePoint > 255) return;
102
+ if (codePoint < 0 || codePoint > MAX_FORMAT_0_CODE) return;
87
103
  const glyphId = u8(bytes, glyphIdArrayOffset + codePoint);
88
104
  return glyphId === 0 ? void 0 : glyphId;
89
105
  };
90
106
  return {
91
107
  lookup,
92
108
  forEachMapping(visit) {
93
- for (let code = 0; code <= 255; code++) {
109
+ for (let code = 0; code <= MAX_FORMAT_0_CODE; code++) {
94
110
  const glyphId = lookup(code);
95
111
  if (glyphId !== void 0) visit(code, glyphId);
96
112
  }
@@ -98,10 +114,12 @@ function parseFormat0(bytes, subtableOffset) {
98
114
  };
99
115
  }
100
116
  const FORMAT_6_HEADER_SIZE = 10;
117
+ const FORMAT_6_FIRST_CODE_FIELD = 6;
118
+ const FORMAT_6_ENTRY_COUNT_FIELD = 8;
101
119
  function parseFormat6(bytes, subtableOffset) {
102
120
  if (!hasBytes(bytes, subtableOffset, FORMAT_6_HEADER_SIZE)) return;
103
- const firstCode = u16(bytes, subtableOffset + 6);
104
- const entryCount = u16(bytes, subtableOffset + 8);
121
+ const firstCode = u16(bytes, subtableOffset + FORMAT_6_FIRST_CODE_FIELD);
122
+ const entryCount = u16(bytes, subtableOffset + FORMAT_6_ENTRY_COUNT_FIELD);
105
123
  const glyphIdArrayOffset = subtableOffset + FORMAT_6_HEADER_SIZE;
106
124
  if (!hasBytes(bytes, glyphIdArrayOffset, entryCount * 2)) return;
107
125
  const lookup = (codePoint) => {
@@ -121,19 +139,29 @@ function parseFormat6(bytes, subtableOffset) {
121
139
  }
122
140
  };
123
141
  }
142
+ const PLATFORM_WINDOWS = 3;
143
+ const PLATFORM_UNICODE = 0;
144
+ const ENCODING_WINDOWS_UCS4 = 10;
145
+ const ENCODING_WINDOWS_UNICODE_BMP = 1;
146
+ const RANK_WINDOWS_UCS4_FORMAT_12 = 0;
147
+ const RANK_UNICODE_FORMAT_12 = 1;
148
+ const RANK_OTHER_FORMAT_12 = 2;
149
+ const RANK_WINDOWS_BMP_FORMAT_4 = 3;
150
+ const RANK_OTHER_FORMAT_4 = 4;
151
+ const RANK_FORMAT_6 = 5;
124
152
  function preferenceRank(subtable) {
125
- if (subtable.format === 12) {
126
- if (subtable.platformId === 3 && subtable.encodingId === 10) return 0;
127
- if (subtable.platformId === 0) return 1;
128
- return 2;
153
+ if (subtable.format === CMAP_FORMAT_12) {
154
+ if (subtable.platformId === PLATFORM_WINDOWS && subtable.encodingId === ENCODING_WINDOWS_UCS4) return RANK_WINDOWS_UCS4_FORMAT_12;
155
+ if (subtable.platformId === PLATFORM_UNICODE) return RANK_UNICODE_FORMAT_12;
156
+ return RANK_OTHER_FORMAT_12;
129
157
  }
130
- if (subtable.format === 4) return subtable.platformId === 3 && subtable.encodingId === 1 ? 3 : 4;
131
- return 5;
158
+ if (subtable.format === CMAP_FORMAT_4) return subtable.platformId === PLATFORM_WINDOWS && subtable.encodingId === ENCODING_WINDOWS_UNICODE_BMP ? RANK_WINDOWS_BMP_FORMAT_4 : RANK_OTHER_FORMAT_4;
159
+ return RANK_FORMAT_6;
132
160
  }
133
161
  function parseSubtable(bytes, record) {
134
- if (record.format === 12) return parseFormat12(bytes, record.offset);
135
- if (record.format === 4) return parseFormat4(bytes, record.offset);
136
- if (record.format === 6) return parseFormat6(bytes, record.offset);
162
+ if (record.format === CMAP_FORMAT_12) return parseFormat12(bytes, record.offset);
163
+ if (record.format === CMAP_FORMAT_4) return parseFormat4(bytes, record.offset);
164
+ if (record.format === CMAP_FORMAT_6) return parseFormat6(bytes, record.offset);
137
165
  return record.format === 0 ? parseFormat0(bytes, record.offset) : void 0;
138
166
  }
139
167
  function readCmapSubtables(font) {
@@ -144,7 +172,7 @@ function readCmapSubtables(font) {
144
172
  const subtables = [];
145
173
  for (let i = 0; i < numTables; i++) {
146
174
  const recordOffset = CMAP_HEADER_SIZE + i * SUBTABLE_RECORD_SIZE;
147
- const offset = u32(cmapBytes, recordOffset + 4);
175
+ const offset = u32(cmapBytes, recordOffset + SUBTABLE_RECORD_OFFSET_FIELD);
148
176
  if (!hasBytes(cmapBytes, offset, 2)) continue;
149
177
  const record = {
150
178
  platformId: u16(cmapBytes, recordOffset),
@@ -163,7 +191,7 @@ function readCmapSubtables(font) {
163
191
  return subtables;
164
192
  }
165
193
  function buildCmapLookup(font) {
166
- return readCmapSubtables(font).filter((s) => s.format === 4 || s.format === 6 || s.format === 12).sort((a, b) => preferenceRank(a) - preferenceRank(b))[0]?.lookup;
194
+ return readCmapSubtables(font).filter((s) => s.format === CMAP_FORMAT_4 || s.format === CMAP_FORMAT_6 || s.format === CMAP_FORMAT_12).sort((a, b) => preferenceRank(a) - preferenceRank(b))[0]?.lookup;
167
195
  }
168
196
  //#endregion
169
197
  export { buildCmapLookup, readCmapSubtables };
package/dist/cmap.cjs CHANGED
@@ -2,14 +2,16 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_bytes_reader = require("./bytes/reader.cjs");
3
3
  const require_lexer = require("./lexer.cjs");
4
4
  //#region src/cmap.ts
5
+ const BYTE_RADIX = 256;
6
+ const BITS_PER_BYTE = 8;
5
7
  function hexBytesToNumber(bytes) {
6
8
  let value = 0;
7
- for (const byte of bytes) value = value * 256 + byte;
9
+ for (const byte of bytes) value = value * BYTE_RADIX + byte;
8
10
  return value;
9
11
  }
10
12
  function decodeUtf16BEString(bytes) {
11
13
  const units = [];
12
- for (let i = 0; i + 1 < bytes.length; i += 2) units.push((bytes[i] ?? 0) << 8 | (bytes[i + 1] ?? 0));
14
+ for (let i = 0; i + 1 < bytes.length; i += 2) units.push((bytes[i] ?? 0) << BITS_PER_BYTE | (bytes[i + 1] ?? 0));
13
15
  return String.fromCharCode(...units);
14
16
  }
15
17
  function parseToUnicodeCMap(bytes, sink) {
@@ -85,7 +87,7 @@ function readBfRange(reader, map, sink) {
85
87
  function registerBfRangeSingle(map, lo, hi, dstBytes) {
86
88
  if (dstBytes.length < 2) return;
87
89
  const prefix = decodeUtf16BEString(dstBytes.subarray(0, dstBytes.length - 2));
88
- const baseUnit = (dstBytes[dstBytes.length - 2] ?? 0) << 8 | (dstBytes[dstBytes.length - 1] ?? 0);
90
+ const baseUnit = (dstBytes[dstBytes.length - 2] ?? 0) << BITS_PER_BYTE | (dstBytes[dstBytes.length - 1] ?? 0);
89
91
  for (let code = lo; code <= hi; code++) map.set(code, prefix + String.fromCharCode(baseUnit + (code - lo)));
90
92
  }
91
93
  function readBfRangeArray(reader, map, lo, sink) {
package/dist/cmap.js CHANGED
@@ -1,14 +1,16 @@
1
1
  import { ByteReader } from "./bytes/reader.js";
2
2
  import { nextToken } from "./lexer.js";
3
3
  //#region src/cmap.ts
4
+ const BYTE_RADIX = 256;
5
+ const BITS_PER_BYTE = 8;
4
6
  function hexBytesToNumber(bytes) {
5
7
  let value = 0;
6
- for (const byte of bytes) value = value * 256 + byte;
8
+ for (const byte of bytes) value = value * BYTE_RADIX + byte;
7
9
  return value;
8
10
  }
9
11
  function decodeUtf16BEString(bytes) {
10
12
  const units = [];
11
- for (let i = 0; i + 1 < bytes.length; i += 2) units.push((bytes[i] ?? 0) << 8 | (bytes[i + 1] ?? 0));
13
+ for (let i = 0; i + 1 < bytes.length; i += 2) units.push((bytes[i] ?? 0) << BITS_PER_BYTE | (bytes[i + 1] ?? 0));
12
14
  return String.fromCharCode(...units);
13
15
  }
14
16
  function parseToUnicodeCMap(bytes, sink) {
@@ -84,7 +86,7 @@ function readBfRange(reader, map, sink) {
84
86
  function registerBfRangeSingle(map, lo, hi, dstBytes) {
85
87
  if (dstBytes.length < 2) return;
86
88
  const prefix = decodeUtf16BEString(dstBytes.subarray(0, dstBytes.length - 2));
87
- const baseUnit = (dstBytes[dstBytes.length - 2] ?? 0) << 8 | (dstBytes[dstBytes.length - 1] ?? 0);
89
+ const baseUnit = (dstBytes[dstBytes.length - 2] ?? 0) << BITS_PER_BYTE | (dstBytes[dstBytes.length - 1] ?? 0);
88
90
  for (let code = lo; code <= hi; code++) map.set(code, prefix + String.fromCharCode(baseUnit + (code - lo)));
89
91
  }
90
92
  function readBfRangeArray(reader, map, lo, sink) {
@@ -1,5 +1,5 @@
1
1
  import { PdfDiagnosticSink } from "./diagnostics.cjs";
2
- import { n as PdfDict, r as PdfObject } from "./objects-B7HdMeWS.cjs";
2
+ import { n as PdfDict, r as PdfObject } from "./objects-e2RS3-yT.cjs";
3
3
  //#region src/content-read.d.ts
4
4
  interface ContentOperation {
5
5
  readonly operands: readonly PdfObject[];
@@ -1,5 +1,5 @@
1
1
  import { PdfDiagnosticSink } from "./diagnostics.js";
2
- import { n as PdfDict, r as PdfObject } from "./objects-B7HdMeWS.js";
2
+ import { n as PdfDict, r as PdfObject } from "./objects-e2RS3-yT.js";
3
3
  //#region src/content-read.d.ts
4
4
  interface ContentOperation {
5
5
  readonly operands: readonly PdfObject[];
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_afm_widths = require("./afm-widths-BYiX2L9D.cjs");
2
+ const require_afm_widths = require("./afm-widths-BHD2HZIL.cjs");
3
3
  const require_objects = require("./objects.cjs");
4
4
  const require_bytes_writer = require("./bytes/writer.cjs");
5
5
  const require_serialize = require("./serialize.cjs");
@@ -8,6 +8,7 @@ const require_embedded_font = require("./embedded-font.cjs");
8
8
  //#region src/content-write.ts
9
9
  const GLYPH_SPACE_UNITS_PER_EM = 1e3;
10
10
  const EMBEDDED_HORIZONTAL_SCALE_PERCENT = 100;
11
+ const PERCENT_SCALE_FACTOR = 100;
11
12
  function writeRgbOperator(writer, color, operator) {
12
13
  writer.writeAscii(`${require_serialize.formatNumber(color.r)} ${require_serialize.formatNumber(color.g)} ${require_serialize.formatNumber(color.b)} ${operator}\n`);
13
14
  }
@@ -43,15 +44,15 @@ function writeShowTextBlock(writer, item, resourceName, scalePercent, show) {
43
44
  writer.writeAscii(` ${show.operator}\n`);
44
45
  writer.writeAscii("ET\n");
45
46
  }
46
- function writeStandardText(writer, item, standardName, resourceName, measurer, substitutions) {
47
+ function writeStandardText(writer, item, standardName, resourceName, measurer) {
47
48
  const encoded = require_afm_widths.encodeForShow(item.text, standardName);
48
- substitutions.push(...encoded.substitutions);
49
49
  const scale = measurer.horizontalScaleFor(item.font);
50
- writeShowTextBlock(writer, item, resourceName, scale * 100, {
50
+ writeShowTextBlock(writer, item, resourceName, scale * PERCENT_SCALE_FACTOR, {
51
51
  operand: require_objects.pdfHexString(encoded.codes),
52
52
  operator: "Tj"
53
53
  });
54
54
  if (item.underline === true) writeUnderline(writer, item, item.widthPt ?? encoded.width1000 / GLYPH_SPACE_UNITS_PER_EM * item.sizePt * scale, measurer.underlineAtSize(item.font, item.sizePt));
55
+ return encoded.substitutions;
55
56
  }
56
57
  function embeddedShowOperand(encoded) {
57
58
  if (encoded.kerns.length === 0) return {
@@ -71,22 +72,25 @@ function embeddedShowOperand(encoded) {
71
72
  operator: "TJ"
72
73
  };
73
74
  }
74
- function writeEmbeddedText(writer, item, face, resourceName, missingGlyphs) {
75
+ function writeEmbeddedText(writer, item, face, resourceName) {
75
76
  const encoded = require_embedded_font.encodeForShowEmbedded(item.text, face);
76
- missingGlyphs.push(...encoded.substitutions);
77
77
  writeShowTextBlock(writer, item, resourceName, EMBEDDED_HORIZONTAL_SCALE_PERCENT, embeddedShowOperand(encoded));
78
78
  if (item.underline === true) writeUnderline(writer, item, item.widthPt ?? encoded.width1000 / GLYPH_SPACE_UNITS_PER_EM * item.sizePt, {
79
79
  offsetPt: face.metrics.underlinePositionGlyphSpace / GLYPH_SPACE_UNITS_PER_EM * item.sizePt,
80
80
  thicknessPt: face.metrics.underlineThicknessGlyphSpace / GLYPH_SPACE_UNITS_PER_EM * item.sizePt
81
81
  });
82
+ return encoded.substitutions;
82
83
  }
83
- function writeText(writer, item, context, substitutions, missingGlyphs) {
84
+ function writeText(writer, item, context) {
84
85
  const font = context.resolveFont(item.font);
85
- if (font.kind === "embedded") {
86
- writeEmbeddedText(writer, item, font.face, font.resourceName, missingGlyphs);
87
- return;
88
- }
89
- writeStandardText(writer, item, font.standardName, font.resourceName, context.measurer, substitutions);
86
+ if (font.kind === "embedded") return {
87
+ substitutions: [],
88
+ missingGlyphs: writeEmbeddedText(writer, item, font.face, font.resourceName)
89
+ };
90
+ return {
91
+ substitutions: writeStandardText(writer, item, font.standardName, font.resourceName, context.measurer),
92
+ missingGlyphs: []
93
+ };
90
94
  }
91
95
  function paintOperatorFor(fill, stroke, fillRule) {
92
96
  const evenOdd = fillRule === "evenodd";
@@ -332,8 +336,11 @@ function writeContentStream(items, context) {
332
336
  if (layerObjectNum !== void 0) writer.writeAscii(` /OC ${layerObjectNum} 0 R`);
333
337
  writer.writeAscii(" >> BDC\n");
334
338
  }
335
- if (item.kind === "text") writeText(writer, item, context, substitutions, missingGlyphs);
336
- else if (item.kind === "image") writeImage(writer, item, context);
339
+ if (item.kind === "text") {
340
+ const written = writeText(writer, item, context);
341
+ substitutions.push(...written.substitutions);
342
+ missingGlyphs.push(...written.missingGlyphs);
343
+ } else if (item.kind === "image") writeImage(writer, item, context);
337
344
  else if (item.kind === "rect") writeRect(writer, item);
338
345
  else if (item.kind === "line") writeLine(writer, item);
339
346
  else if (item.kind === "ellipse") writeEllipse(writer, item);
@@ -1,6 +1,6 @@
1
1
  import { r as StandardFontName } from "./afm-widths-CneRyu5l.cjs";
2
2
  import { LayoutItem } from "./layout.cjs";
3
- import { r as EmbeddedFaceSubstitution, t as EmbeddedFace } from "./embedded-font-CEf-zBCA.cjs";
3
+ import { r as EmbeddedFaceSubstitution, t as EmbeddedFace } from "./embedded-font-DgVBedw6.cjs";
4
4
  import { WinAnsiSubstitution } from "./winansi.cjs";
5
5
  import { LayoutFont, TextMeasurer } from "document-schema.js";
6
6
  //#region src/content-write.d.ts
@@ -18,7 +18,7 @@ interface ResolvedImageResource {
18
18
  }
19
19
  interface ContentWriteContext {
20
20
  readonly measurer: TextMeasurer;
21
- resolveFont: (font: LayoutFont) => ResolvedFontResource;
21
+ resolveFont: (font: Readonly<LayoutFont>) => ResolvedFontResource;
22
22
  resolveImage: (imageId: string) => ResolvedImageResource;
23
23
  readonly layerObjectNumberOf?: (name: string) => number | undefined;
24
24
  readonly nextMcid?: () => number;
@@ -1,6 +1,6 @@
1
1
  import { r as StandardFontName } from "./afm-widths-CneRyu5l.js";
2
2
  import { LayoutItem } from "./layout.js";
3
- import { r as EmbeddedFaceSubstitution, t as EmbeddedFace } from "./embedded-font-Bnhh4juV.js";
3
+ import { r as EmbeddedFaceSubstitution, t as EmbeddedFace } from "./embedded-font-ByD7ZiQS.js";
4
4
  import { WinAnsiSubstitution } from "./winansi.js";
5
5
  import { LayoutFont, TextMeasurer } from "document-schema.js";
6
6
  //#region src/content-write.d.ts
@@ -18,7 +18,7 @@ interface ResolvedImageResource {
18
18
  }
19
19
  interface ContentWriteContext {
20
20
  readonly measurer: TextMeasurer;
21
- resolveFont: (font: LayoutFont) => ResolvedFontResource;
21
+ resolveFont: (font: Readonly<LayoutFont>) => ResolvedFontResource;
22
22
  resolveImage: (imageId: string) => ResolvedImageResource;
23
23
  readonly layerObjectNumberOf?: (name: string) => number | undefined;
24
24
  readonly nextMcid?: () => number;
@@ -1,4 +1,4 @@
1
- import { h as encodeForShow } from "./afm-widths-blUDDjlI.js";
1
+ import { h as encodeForShow } from "./afm-widths-B_IGbGky.js";
2
2
  import { pdfArray, pdfHexString, pdfNum } from "./objects.js";
3
3
  import { ByteWriter } from "./bytes/writer.js";
4
4
  import { formatNumber, writeObject } from "./serialize.js";
@@ -7,6 +7,7 @@ import { encodeForShowEmbedded } from "./embedded-font.js";
7
7
  //#region src/content-write.ts
8
8
  const GLYPH_SPACE_UNITS_PER_EM = 1e3;
9
9
  const EMBEDDED_HORIZONTAL_SCALE_PERCENT = 100;
10
+ const PERCENT_SCALE_FACTOR = 100;
10
11
  function writeRgbOperator(writer, color, operator) {
11
12
  writer.writeAscii(`${formatNumber(color.r)} ${formatNumber(color.g)} ${formatNumber(color.b)} ${operator}\n`);
12
13
  }
@@ -42,15 +43,15 @@ function writeShowTextBlock(writer, item, resourceName, scalePercent, show) {
42
43
  writer.writeAscii(` ${show.operator}\n`);
43
44
  writer.writeAscii("ET\n");
44
45
  }
45
- function writeStandardText(writer, item, standardName, resourceName, measurer, substitutions) {
46
+ function writeStandardText(writer, item, standardName, resourceName, measurer) {
46
47
  const encoded = encodeForShow(item.text, standardName);
47
- substitutions.push(...encoded.substitutions);
48
48
  const scale = measurer.horizontalScaleFor(item.font);
49
- writeShowTextBlock(writer, item, resourceName, scale * 100, {
49
+ writeShowTextBlock(writer, item, resourceName, scale * PERCENT_SCALE_FACTOR, {
50
50
  operand: pdfHexString(encoded.codes),
51
51
  operator: "Tj"
52
52
  });
53
53
  if (item.underline === true) writeUnderline(writer, item, item.widthPt ?? encoded.width1000 / GLYPH_SPACE_UNITS_PER_EM * item.sizePt * scale, measurer.underlineAtSize(item.font, item.sizePt));
54
+ return encoded.substitutions;
54
55
  }
55
56
  function embeddedShowOperand(encoded) {
56
57
  if (encoded.kerns.length === 0) return {
@@ -70,22 +71,25 @@ function embeddedShowOperand(encoded) {
70
71
  operator: "TJ"
71
72
  };
72
73
  }
73
- function writeEmbeddedText(writer, item, face, resourceName, missingGlyphs) {
74
+ function writeEmbeddedText(writer, item, face, resourceName) {
74
75
  const encoded = encodeForShowEmbedded(item.text, face);
75
- missingGlyphs.push(...encoded.substitutions);
76
76
  writeShowTextBlock(writer, item, resourceName, EMBEDDED_HORIZONTAL_SCALE_PERCENT, embeddedShowOperand(encoded));
77
77
  if (item.underline === true) writeUnderline(writer, item, item.widthPt ?? encoded.width1000 / GLYPH_SPACE_UNITS_PER_EM * item.sizePt, {
78
78
  offsetPt: face.metrics.underlinePositionGlyphSpace / GLYPH_SPACE_UNITS_PER_EM * item.sizePt,
79
79
  thicknessPt: face.metrics.underlineThicknessGlyphSpace / GLYPH_SPACE_UNITS_PER_EM * item.sizePt
80
80
  });
81
+ return encoded.substitutions;
81
82
  }
82
- function writeText(writer, item, context, substitutions, missingGlyphs) {
83
+ function writeText(writer, item, context) {
83
84
  const font = context.resolveFont(item.font);
84
- if (font.kind === "embedded") {
85
- writeEmbeddedText(writer, item, font.face, font.resourceName, missingGlyphs);
86
- return;
87
- }
88
- writeStandardText(writer, item, font.standardName, font.resourceName, context.measurer, substitutions);
85
+ if (font.kind === "embedded") return {
86
+ substitutions: [],
87
+ missingGlyphs: writeEmbeddedText(writer, item, font.face, font.resourceName)
88
+ };
89
+ return {
90
+ substitutions: writeStandardText(writer, item, font.standardName, font.resourceName, context.measurer),
91
+ missingGlyphs: []
92
+ };
89
93
  }
90
94
  function paintOperatorFor(fill, stroke, fillRule) {
91
95
  const evenOdd = fillRule === "evenodd";
@@ -331,8 +335,11 @@ function writeContentStream(items, context) {
331
335
  if (layerObjectNum !== void 0) writer.writeAscii(` /OC ${layerObjectNum} 0 R`);
332
336
  writer.writeAscii(" >> BDC\n");
333
337
  }
334
- if (item.kind === "text") writeText(writer, item, context, substitutions, missingGlyphs);
335
- else if (item.kind === "image") writeImage(writer, item, context);
338
+ if (item.kind === "text") {
339
+ const written = writeText(writer, item, context);
340
+ substitutions.push(...written.substitutions);
341
+ missingGlyphs.push(...written.missingGlyphs);
342
+ } else if (item.kind === "image") writeImage(writer, item, context);
336
343
  else if (item.kind === "rect") writeRect(writer, item);
337
344
  else if (item.kind === "line") writeLine(writer, item);
338
345
  else if (item.kind === "ellipse") writeEllipse(writer, item);