pdf-parser.js 5.2.27 → 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 (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 +1 -1
package/dist/lexer.cjs CHANGED
@@ -1,44 +1,79 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_bytes_reader = require("./bytes/reader.cjs");
3
3
  //#region src/lexer.ts
4
+ const LEFT_PAREN = 40;
5
+ const RIGHT_PAREN = 41;
6
+ const LESS_THAN = 60;
7
+ const GREATER_THAN = 62;
8
+ const LEFT_BRACKET = 91;
9
+ const RIGHT_BRACKET = 93;
10
+ const LEFT_BRACE = 123;
11
+ const RIGHT_BRACE = 125;
12
+ const SOLIDUS = 47;
13
+ const PERCENT_SIGN = 37;
14
+ const REVERSE_SOLIDUS = 92;
15
+ const NUMBER_SIGN = 35;
16
+ const PLUS_SIGN = 43;
17
+ const MINUS_SIGN = 45;
18
+ const FULL_STOP = 46;
19
+ const LINE_FEED = 10;
20
+ const CARRIAGE_RETURN = 13;
21
+ const HORIZONTAL_TAB = 9;
22
+ const BACKSPACE = 8;
23
+ const FORM_FEED = 12;
24
+ const DIGIT_ZERO = 48;
25
+ const DIGIT_SEVEN = 55;
26
+ const DIGIT_NINE = 57;
27
+ const UPPER_A = 65;
28
+ const UPPER_F = 70;
29
+ const LOWER_A = 97;
30
+ const LOWER_B = 98;
31
+ const LOWER_F = 102;
32
+ const LOWER_N = 110;
33
+ const LOWER_R = 114;
34
+ const LOWER_T = 116;
35
+ const HEX_DIGIT_ALPHA_OFFSET = 10;
36
+ const HEX_RADIX = 16;
37
+ const OCTAL_RADIX = 8;
38
+ const BYTE_MASK = 255;
4
39
  const DELIMITER_BYTES = /* @__PURE__ */ new Set([
5
- 40,
6
- 41,
7
- 60,
8
- 62,
9
- 91,
10
- 93,
11
- 123,
12
- 125,
13
- 47,
14
- 37
40
+ LEFT_PAREN,
41
+ RIGHT_PAREN,
42
+ LESS_THAN,
43
+ GREATER_THAN,
44
+ LEFT_BRACKET,
45
+ RIGHT_BRACKET,
46
+ LEFT_BRACE,
47
+ RIGHT_BRACE,
48
+ SOLIDUS,
49
+ PERCENT_SIGN
15
50
  ]);
16
51
  function isRegularByte(byte) {
17
52
  return !require_bytes_reader.isAsciiWhitespace(byte) && !DELIMITER_BYTES.has(byte);
18
53
  }
19
54
  function isDigit(byte) {
20
- return byte !== void 0 && byte >= 48 && byte <= 57;
55
+ return byte !== void 0 && byte >= DIGIT_ZERO && byte <= DIGIT_NINE;
21
56
  }
22
57
  function isHexDigit(byte) {
23
- return byte !== void 0 && (byte >= 48 && byte <= 57 || byte >= 65 && byte <= 70 || byte >= 97 && byte <= 102);
58
+ return byte !== void 0 && (byte >= DIGIT_ZERO && byte <= DIGIT_NINE || byte >= UPPER_A && byte <= UPPER_F || byte >= LOWER_A && byte <= LOWER_F);
24
59
  }
25
60
  function hexDigitValue(byte) {
26
- if (byte >= 48 && byte <= 57) return byte - 48;
27
- if (byte >= 65 && byte <= 70) return byte - 65 + 10;
28
- return byte - 97 + 10;
61
+ if (byte >= DIGIT_ZERO && byte <= DIGIT_NINE) return byte - DIGIT_ZERO;
62
+ if (byte >= UPPER_A && byte <= UPPER_F) return byte - UPPER_A + HEX_DIGIT_ALPHA_OFFSET;
63
+ return byte - LOWER_A + HEX_DIGIT_ALPHA_OFFSET;
29
64
  }
30
65
  function skipWhitespaceAndComments(reader) {
31
66
  for (;;) {
32
67
  reader.skipWhitespace();
33
- if (reader.peek() !== 37) return;
34
- while (!reader.atEnd() && reader.peek() !== 10 && reader.peek() !== 13) reader.next();
68
+ if (reader.peek() !== PERCENT_SIGN) return;
69
+ while (!reader.atEnd() && reader.peek() !== LINE_FEED && reader.peek() !== CARRIAGE_RETURN) reader.next();
35
70
  }
36
71
  }
37
72
  function readNumberToken(reader) {
38
73
  const start = reader.offset;
39
- if (reader.peek() === 43 || reader.peek() === 45) reader.next();
74
+ if (reader.peek() === PLUS_SIGN || reader.peek() === MINUS_SIGN) reader.next();
40
75
  while (isDigit(reader.peek())) reader.next();
41
- if (reader.peek() === 46) {
76
+ if (reader.peek() === FULL_STOP) {
42
77
  reader.next();
43
78
  while (isDigit(reader.peek())) reader.next();
44
79
  }
@@ -54,11 +89,11 @@ function readNameToken(reader) {
54
89
  for (;;) {
55
90
  const byte = reader.peek();
56
91
  if (byte === void 0 || !isRegularByte(byte)) break;
57
- if (byte === 35 && isHexDigit(reader.peek(1)) && isHexDigit(reader.peek(2))) {
92
+ if (byte === NUMBER_SIGN && isHexDigit(reader.peek(1)) && isHexDigit(reader.peek(2))) {
58
93
  reader.next();
59
94
  const hi = hexDigitValue(reader.next());
60
95
  const lo = hexDigitValue(reader.next());
61
- bytes.push(hi * 16 + lo);
96
+ bytes.push(hi * HEX_RADIX + lo);
62
97
  } else bytes.push(reader.next());
63
98
  }
64
99
  return {
@@ -73,38 +108,38 @@ function readLiteralStringToken(reader) {
73
108
  for (;;) {
74
109
  const byte = reader.next();
75
110
  if (byte === void 0) break;
76
- if (byte === 92) {
111
+ if (byte === REVERSE_SOLIDUS) {
77
112
  const esc = reader.next();
78
113
  if (esc === void 0) break;
79
- if (esc === 110) bytes.push(10);
80
- else if (esc === 114) bytes.push(13);
81
- else if (esc === 116) bytes.push(9);
82
- else if (esc === 98) bytes.push(8);
83
- else if (esc === 102) bytes.push(12);
84
- else if (esc === 40 || esc === 41 || esc === 92) bytes.push(esc);
85
- else if (esc === 13) {
86
- if (reader.peek() === 10) reader.next();
87
- } else if (esc === 10) {} else if (esc >= 48 && esc <= 55) {
88
- let value = esc - 48;
89
- for (let i = 0; i < 2 && reader.peek() !== void 0 && reader.peek() >= 48 && reader.peek() <= 55; i++) value = value * 8 + (reader.next() - 48);
90
- bytes.push(value & 255);
114
+ if (esc === LOWER_N) bytes.push(LINE_FEED);
115
+ else if (esc === LOWER_R) bytes.push(CARRIAGE_RETURN);
116
+ else if (esc === LOWER_T) bytes.push(HORIZONTAL_TAB);
117
+ else if (esc === LOWER_B) bytes.push(BACKSPACE);
118
+ else if (esc === LOWER_F) bytes.push(FORM_FEED);
119
+ else if (esc === LEFT_PAREN || esc === RIGHT_PAREN || esc === REVERSE_SOLIDUS) bytes.push(esc);
120
+ else if (esc === CARRIAGE_RETURN) {
121
+ if (reader.peek() === LINE_FEED) reader.next();
122
+ } else if (esc === LINE_FEED) {} else if (esc >= DIGIT_ZERO && esc <= DIGIT_SEVEN) {
123
+ let value = esc - DIGIT_ZERO;
124
+ for (let i = 0; i < 2 && reader.peek() !== void 0 && reader.peek() >= DIGIT_ZERO && reader.peek() <= DIGIT_SEVEN; i++) value = value * OCTAL_RADIX + (reader.next() - DIGIT_ZERO);
125
+ bytes.push(value & BYTE_MASK);
91
126
  } else bytes.push(esc);
92
127
  continue;
93
128
  }
94
- if (byte === 40) {
129
+ if (byte === LEFT_PAREN) {
95
130
  depth++;
96
131
  bytes.push(byte);
97
132
  continue;
98
133
  }
99
- if (byte === 41) {
134
+ if (byte === RIGHT_PAREN) {
100
135
  depth--;
101
136
  if (depth === 0) break;
102
137
  bytes.push(byte);
103
138
  continue;
104
139
  }
105
- if (byte === 13) {
106
- if (reader.peek() === 10) reader.next();
107
- bytes.push(10);
140
+ if (byte === CARRIAGE_RETURN) {
141
+ if (reader.peek() === LINE_FEED) reader.next();
142
+ bytes.push(LINE_FEED);
108
143
  continue;
109
144
  }
110
145
  bytes.push(byte);
@@ -119,12 +154,12 @@ function readHexStringToken(reader) {
119
154
  const digits = [];
120
155
  for (;;) {
121
156
  const byte = reader.next();
122
- if (byte === void 0 || byte === 62) break;
157
+ if (byte === void 0 || byte === GREATER_THAN) break;
123
158
  if (isHexDigit(byte)) digits.push(hexDigitValue(byte));
124
159
  }
125
160
  if (digits.length % 2 === 1) digits.push(0);
126
161
  const bytes = new Uint8Array(digits.length / 2);
127
- for (let i = 0; i < bytes.length; i++) bytes[i] = digits[i * 2] * 16 + digits[i * 2 + 1];
162
+ for (let i = 0; i < bytes.length; i++) bytes[i] = digits[i * 2] * HEX_RADIX + digits[i * 2 + 1];
128
163
  return {
129
164
  kind: "hexString",
130
165
  value: bytes
@@ -142,18 +177,18 @@ function nextToken(reader) {
142
177
  skipWhitespaceAndComments(reader);
143
178
  const byte = reader.peek();
144
179
  if (byte === void 0) return;
145
- if (byte === 47) return readNameToken(reader);
146
- if (byte === 40) return readLiteralStringToken(reader);
147
- if (byte === 60) {
148
- if (reader.peek(1) === 60) {
180
+ if (byte === SOLIDUS) return readNameToken(reader);
181
+ if (byte === LEFT_PAREN) return readLiteralStringToken(reader);
182
+ if (byte === LESS_THAN) {
183
+ if (reader.peek(1) === LESS_THAN) {
149
184
  reader.next();
150
185
  reader.next();
151
186
  return { kind: "dictStart" };
152
187
  }
153
188
  return readHexStringToken(reader);
154
189
  }
155
- if (byte === 62) {
156
- if (reader.peek(1) === 62) {
190
+ if (byte === GREATER_THAN) {
191
+ if (reader.peek(1) === GREATER_THAN) {
157
192
  reader.next();
158
193
  reader.next();
159
194
  return { kind: "dictEnd" };
@@ -161,19 +196,19 @@ function nextToken(reader) {
161
196
  reader.next();
162
197
  return nextToken(reader);
163
198
  }
164
- if (byte === 91) {
199
+ if (byte === LEFT_BRACKET) {
165
200
  reader.next();
166
201
  return { kind: "arrayStart" };
167
202
  }
168
- if (byte === 93) {
203
+ if (byte === RIGHT_BRACKET) {
169
204
  reader.next();
170
205
  return { kind: "arrayEnd" };
171
206
  }
172
- if (byte === 123 || byte === 125) {
207
+ if (byte === LEFT_BRACE || byte === RIGHT_BRACE) {
173
208
  reader.next();
174
209
  return nextToken(reader);
175
210
  }
176
- if (byte === 43 || byte === 45 || byte === 46 || isDigit(byte)) return readNumberToken(reader);
211
+ if (byte === PLUS_SIGN || byte === MINUS_SIGN || byte === FULL_STOP || isDigit(byte)) return readNumberToken(reader);
177
212
  return readKeywordToken(reader);
178
213
  }
179
214
  //#endregion
package/dist/lexer.js CHANGED
@@ -1,43 +1,78 @@
1
1
  import { isAsciiWhitespace } from "./bytes/reader.js";
2
2
  //#region src/lexer.ts
3
+ const LEFT_PAREN = 40;
4
+ const RIGHT_PAREN = 41;
5
+ const LESS_THAN = 60;
6
+ const GREATER_THAN = 62;
7
+ const LEFT_BRACKET = 91;
8
+ const RIGHT_BRACKET = 93;
9
+ const LEFT_BRACE = 123;
10
+ const RIGHT_BRACE = 125;
11
+ const SOLIDUS = 47;
12
+ const PERCENT_SIGN = 37;
13
+ const REVERSE_SOLIDUS = 92;
14
+ const NUMBER_SIGN = 35;
15
+ const PLUS_SIGN = 43;
16
+ const MINUS_SIGN = 45;
17
+ const FULL_STOP = 46;
18
+ const LINE_FEED = 10;
19
+ const CARRIAGE_RETURN = 13;
20
+ const HORIZONTAL_TAB = 9;
21
+ const BACKSPACE = 8;
22
+ const FORM_FEED = 12;
23
+ const DIGIT_ZERO = 48;
24
+ const DIGIT_SEVEN = 55;
25
+ const DIGIT_NINE = 57;
26
+ const UPPER_A = 65;
27
+ const UPPER_F = 70;
28
+ const LOWER_A = 97;
29
+ const LOWER_B = 98;
30
+ const LOWER_F = 102;
31
+ const LOWER_N = 110;
32
+ const LOWER_R = 114;
33
+ const LOWER_T = 116;
34
+ const HEX_DIGIT_ALPHA_OFFSET = 10;
35
+ const HEX_RADIX = 16;
36
+ const OCTAL_RADIX = 8;
37
+ const BYTE_MASK = 255;
3
38
  const DELIMITER_BYTES = /* @__PURE__ */ new Set([
4
- 40,
5
- 41,
6
- 60,
7
- 62,
8
- 91,
9
- 93,
10
- 123,
11
- 125,
12
- 47,
13
- 37
39
+ LEFT_PAREN,
40
+ RIGHT_PAREN,
41
+ LESS_THAN,
42
+ GREATER_THAN,
43
+ LEFT_BRACKET,
44
+ RIGHT_BRACKET,
45
+ LEFT_BRACE,
46
+ RIGHT_BRACE,
47
+ SOLIDUS,
48
+ PERCENT_SIGN
14
49
  ]);
15
50
  function isRegularByte(byte) {
16
51
  return !isAsciiWhitespace(byte) && !DELIMITER_BYTES.has(byte);
17
52
  }
18
53
  function isDigit(byte) {
19
- return byte !== void 0 && byte >= 48 && byte <= 57;
54
+ return byte !== void 0 && byte >= DIGIT_ZERO && byte <= DIGIT_NINE;
20
55
  }
21
56
  function isHexDigit(byte) {
22
- return byte !== void 0 && (byte >= 48 && byte <= 57 || byte >= 65 && byte <= 70 || byte >= 97 && byte <= 102);
57
+ return byte !== void 0 && (byte >= DIGIT_ZERO && byte <= DIGIT_NINE || byte >= UPPER_A && byte <= UPPER_F || byte >= LOWER_A && byte <= LOWER_F);
23
58
  }
24
59
  function hexDigitValue(byte) {
25
- if (byte >= 48 && byte <= 57) return byte - 48;
26
- if (byte >= 65 && byte <= 70) return byte - 65 + 10;
27
- return byte - 97 + 10;
60
+ if (byte >= DIGIT_ZERO && byte <= DIGIT_NINE) return byte - DIGIT_ZERO;
61
+ if (byte >= UPPER_A && byte <= UPPER_F) return byte - UPPER_A + HEX_DIGIT_ALPHA_OFFSET;
62
+ return byte - LOWER_A + HEX_DIGIT_ALPHA_OFFSET;
28
63
  }
29
64
  function skipWhitespaceAndComments(reader) {
30
65
  for (;;) {
31
66
  reader.skipWhitespace();
32
- if (reader.peek() !== 37) return;
33
- while (!reader.atEnd() && reader.peek() !== 10 && reader.peek() !== 13) reader.next();
67
+ if (reader.peek() !== PERCENT_SIGN) return;
68
+ while (!reader.atEnd() && reader.peek() !== LINE_FEED && reader.peek() !== CARRIAGE_RETURN) reader.next();
34
69
  }
35
70
  }
36
71
  function readNumberToken(reader) {
37
72
  const start = reader.offset;
38
- if (reader.peek() === 43 || reader.peek() === 45) reader.next();
73
+ if (reader.peek() === PLUS_SIGN || reader.peek() === MINUS_SIGN) reader.next();
39
74
  while (isDigit(reader.peek())) reader.next();
40
- if (reader.peek() === 46) {
75
+ if (reader.peek() === FULL_STOP) {
41
76
  reader.next();
42
77
  while (isDigit(reader.peek())) reader.next();
43
78
  }
@@ -53,11 +88,11 @@ function readNameToken(reader) {
53
88
  for (;;) {
54
89
  const byte = reader.peek();
55
90
  if (byte === void 0 || !isRegularByte(byte)) break;
56
- if (byte === 35 && isHexDigit(reader.peek(1)) && isHexDigit(reader.peek(2))) {
91
+ if (byte === NUMBER_SIGN && isHexDigit(reader.peek(1)) && isHexDigit(reader.peek(2))) {
57
92
  reader.next();
58
93
  const hi = hexDigitValue(reader.next());
59
94
  const lo = hexDigitValue(reader.next());
60
- bytes.push(hi * 16 + lo);
95
+ bytes.push(hi * HEX_RADIX + lo);
61
96
  } else bytes.push(reader.next());
62
97
  }
63
98
  return {
@@ -72,38 +107,38 @@ function readLiteralStringToken(reader) {
72
107
  for (;;) {
73
108
  const byte = reader.next();
74
109
  if (byte === void 0) break;
75
- if (byte === 92) {
110
+ if (byte === REVERSE_SOLIDUS) {
76
111
  const esc = reader.next();
77
112
  if (esc === void 0) break;
78
- if (esc === 110) bytes.push(10);
79
- else if (esc === 114) bytes.push(13);
80
- else if (esc === 116) bytes.push(9);
81
- else if (esc === 98) bytes.push(8);
82
- else if (esc === 102) bytes.push(12);
83
- else if (esc === 40 || esc === 41 || esc === 92) bytes.push(esc);
84
- else if (esc === 13) {
85
- if (reader.peek() === 10) reader.next();
86
- } else if (esc === 10) {} else if (esc >= 48 && esc <= 55) {
87
- let value = esc - 48;
88
- for (let i = 0; i < 2 && reader.peek() !== void 0 && reader.peek() >= 48 && reader.peek() <= 55; i++) value = value * 8 + (reader.next() - 48);
89
- bytes.push(value & 255);
113
+ if (esc === LOWER_N) bytes.push(LINE_FEED);
114
+ else if (esc === LOWER_R) bytes.push(CARRIAGE_RETURN);
115
+ else if (esc === LOWER_T) bytes.push(HORIZONTAL_TAB);
116
+ else if (esc === LOWER_B) bytes.push(BACKSPACE);
117
+ else if (esc === LOWER_F) bytes.push(FORM_FEED);
118
+ else if (esc === LEFT_PAREN || esc === RIGHT_PAREN || esc === REVERSE_SOLIDUS) bytes.push(esc);
119
+ else if (esc === CARRIAGE_RETURN) {
120
+ if (reader.peek() === LINE_FEED) reader.next();
121
+ } else if (esc === LINE_FEED) {} else if (esc >= DIGIT_ZERO && esc <= DIGIT_SEVEN) {
122
+ let value = esc - DIGIT_ZERO;
123
+ for (let i = 0; i < 2 && reader.peek() !== void 0 && reader.peek() >= DIGIT_ZERO && reader.peek() <= DIGIT_SEVEN; i++) value = value * OCTAL_RADIX + (reader.next() - DIGIT_ZERO);
124
+ bytes.push(value & BYTE_MASK);
90
125
  } else bytes.push(esc);
91
126
  continue;
92
127
  }
93
- if (byte === 40) {
128
+ if (byte === LEFT_PAREN) {
94
129
  depth++;
95
130
  bytes.push(byte);
96
131
  continue;
97
132
  }
98
- if (byte === 41) {
133
+ if (byte === RIGHT_PAREN) {
99
134
  depth--;
100
135
  if (depth === 0) break;
101
136
  bytes.push(byte);
102
137
  continue;
103
138
  }
104
- if (byte === 13) {
105
- if (reader.peek() === 10) reader.next();
106
- bytes.push(10);
139
+ if (byte === CARRIAGE_RETURN) {
140
+ if (reader.peek() === LINE_FEED) reader.next();
141
+ bytes.push(LINE_FEED);
107
142
  continue;
108
143
  }
109
144
  bytes.push(byte);
@@ -118,12 +153,12 @@ function readHexStringToken(reader) {
118
153
  const digits = [];
119
154
  for (;;) {
120
155
  const byte = reader.next();
121
- if (byte === void 0 || byte === 62) break;
156
+ if (byte === void 0 || byte === GREATER_THAN) break;
122
157
  if (isHexDigit(byte)) digits.push(hexDigitValue(byte));
123
158
  }
124
159
  if (digits.length % 2 === 1) digits.push(0);
125
160
  const bytes = new Uint8Array(digits.length / 2);
126
- for (let i = 0; i < bytes.length; i++) bytes[i] = digits[i * 2] * 16 + digits[i * 2 + 1];
161
+ for (let i = 0; i < bytes.length; i++) bytes[i] = digits[i * 2] * HEX_RADIX + digits[i * 2 + 1];
127
162
  return {
128
163
  kind: "hexString",
129
164
  value: bytes
@@ -141,18 +176,18 @@ function nextToken(reader) {
141
176
  skipWhitespaceAndComments(reader);
142
177
  const byte = reader.peek();
143
178
  if (byte === void 0) return;
144
- if (byte === 47) return readNameToken(reader);
145
- if (byte === 40) return readLiteralStringToken(reader);
146
- if (byte === 60) {
147
- if (reader.peek(1) === 60) {
179
+ if (byte === SOLIDUS) return readNameToken(reader);
180
+ if (byte === LEFT_PAREN) return readLiteralStringToken(reader);
181
+ if (byte === LESS_THAN) {
182
+ if (reader.peek(1) === LESS_THAN) {
148
183
  reader.next();
149
184
  reader.next();
150
185
  return { kind: "dictStart" };
151
186
  }
152
187
  return readHexStringToken(reader);
153
188
  }
154
- if (byte === 62) {
155
- if (reader.peek(1) === 62) {
189
+ if (byte === GREATER_THAN) {
190
+ if (reader.peek(1) === GREATER_THAN) {
156
191
  reader.next();
157
192
  reader.next();
158
193
  return { kind: "dictEnd" };
@@ -160,19 +195,19 @@ function nextToken(reader) {
160
195
  reader.next();
161
196
  return nextToken(reader);
162
197
  }
163
- if (byte === 91) {
198
+ if (byte === LEFT_BRACKET) {
164
199
  reader.next();
165
200
  return { kind: "arrayStart" };
166
201
  }
167
- if (byte === 93) {
202
+ if (byte === RIGHT_BRACKET) {
168
203
  reader.next();
169
204
  return { kind: "arrayEnd" };
170
205
  }
171
- if (byte === 123 || byte === 125) {
206
+ if (byte === LEFT_BRACE || byte === RIGHT_BRACE) {
172
207
  reader.next();
173
208
  return nextToken(reader);
174
209
  }
175
- if (byte === 43 || byte === 45 || byte === 46 || isDigit(byte)) return readNumberToken(reader);
210
+ if (byte === PLUS_SIGN || byte === MINUS_SIGN || byte === FULL_STOP || isDigit(byte)) return readNumberToken(reader);
176
211
  return readKeywordToken(reader);
177
212
  }
178
213
  //#endregion
@@ -9,6 +9,8 @@ function toPdfX(positioned, itemXPt) {
9
9
  function toPdfY(positioned, itemYPt) {
10
10
  return positioned.yPt + positioned.box.heightPt - itemYPt;
11
11
  }
12
+ const BITS_PER_BYTE = 8;
13
+ const BYTE_MASK = 255;
12
14
  function writeRgbOperator(writer, color, operator) {
13
15
  writer.writeAscii(`${require_serialize.formatNumber(color.r)} ${require_serialize.formatNumber(color.g)} ${require_serialize.formatNumber(color.b)} ${operator}\n`);
14
16
  }
@@ -22,8 +24,8 @@ function encodeGlyphRunToCids(font, text) {
22
24
  }
23
25
  const bytes = new Uint8Array(gids.length * 2);
24
26
  gids.forEach((gid, index) => {
25
- bytes[index * 2] = gid >> 8 & 255;
26
- bytes[index * 2 + 1] = gid & 255;
27
+ bytes[index * 2] = gid >> BITS_PER_BYTE & BYTE_MASK;
28
+ bytes[index * 2 + 1] = gid & BYTE_MASK;
27
29
  });
28
30
  return bytes;
29
31
  }
@@ -41,13 +43,15 @@ function writeGlyphRun(writer, positioned, item, ctx) {
41
43
  writer.writeAscii("ET\n");
42
44
  }
43
45
  function cidBytes(glyphId) {
44
- return new Uint8Array([glyphId >> 8 & 255, glyphId & 255]);
46
+ return new Uint8Array([glyphId >> BITS_PER_BYTE & BYTE_MASK, glyphId & BYTE_MASK]);
45
47
  }
48
+ const UTF16_BOM_HIGH_BYTE = 254;
49
+ const UTF16_BOM_LOW_BYTE = 255;
46
50
  function utf16BeWithBom(text) {
47
- const bytes = [254, 255];
51
+ const bytes = [UTF16_BOM_HIGH_BYTE, UTF16_BOM_LOW_BYTE];
48
52
  for (let i = 0; i < text.length; i++) {
49
53
  const unit = text.charCodeAt(i);
50
- bytes.push(unit >> 8 & 255, unit & 255);
54
+ bytes.push(unit >> BITS_PER_BYTE & BYTE_MASK, unit & BYTE_MASK);
51
55
  }
52
56
  return new Uint8Array(bytes);
53
57
  }
@@ -8,6 +8,8 @@ function toPdfX(positioned, itemXPt) {
8
8
  function toPdfY(positioned, itemYPt) {
9
9
  return positioned.yPt + positioned.box.heightPt - itemYPt;
10
10
  }
11
+ const BITS_PER_BYTE = 8;
12
+ const BYTE_MASK = 255;
11
13
  function writeRgbOperator(writer, color, operator) {
12
14
  writer.writeAscii(`${formatNumber(color.r)} ${formatNumber(color.g)} ${formatNumber(color.b)} ${operator}\n`);
13
15
  }
@@ -21,8 +23,8 @@ function encodeGlyphRunToCids(font, text) {
21
23
  }
22
24
  const bytes = new Uint8Array(gids.length * 2);
23
25
  gids.forEach((gid, index) => {
24
- bytes[index * 2] = gid >> 8 & 255;
25
- bytes[index * 2 + 1] = gid & 255;
26
+ bytes[index * 2] = gid >> BITS_PER_BYTE & BYTE_MASK;
27
+ bytes[index * 2 + 1] = gid & BYTE_MASK;
26
28
  });
27
29
  return bytes;
28
30
  }
@@ -40,13 +42,15 @@ function writeGlyphRun(writer, positioned, item, ctx) {
40
42
  writer.writeAscii("ET\n");
41
43
  }
42
44
  function cidBytes(glyphId) {
43
- return new Uint8Array([glyphId >> 8 & 255, glyphId & 255]);
45
+ return new Uint8Array([glyphId >> BITS_PER_BYTE & BYTE_MASK, glyphId & BYTE_MASK]);
44
46
  }
47
+ const UTF16_BOM_HIGH_BYTE = 254;
48
+ const UTF16_BOM_LOW_BYTE = 255;
45
49
  function utf16BeWithBom(text) {
46
- const bytes = [254, 255];
50
+ const bytes = [UTF16_BOM_HIGH_BYTE, UTF16_BOM_LOW_BYTE];
47
51
  for (let i = 0; i < text.length; i++) {
48
52
  const unit = text.charCodeAt(i);
49
- bytes.push(unit >> 8 & 255, unit & 255);
53
+ bytes.push(unit >> BITS_PER_BYTE & BYTE_MASK, unit & BYTE_MASK);
50
54
  }
51
55
  return new Uint8Array(bytes);
52
56
  }
@@ -10,9 +10,10 @@ function buildWidthsArray(font, usedGlyphs) {
10
10
  for (const glyphId of [...usedGlyphs.keys()].sort((a, b) => a - b)) entries.push(require_objects.pdfNum(glyphId), require_objects.pdfArray([require_objects.pdfNum(font.glyphSpaceWidth(glyphId))]));
11
11
  return require_objects.pdfArray(entries);
12
12
  }
13
+ const GLYPH_SPACE_UNITS_PER_EM = 1e3;
13
14
  function buildFontDescriptor(font, fontFileRef) {
14
15
  const d = font.descriptor;
15
- const scale = 1e3 / d.unitsPerEm;
16
+ const scale = GLYPH_SPACE_UNITS_PER_EM / d.unitsPerEm;
16
17
  return require_objects.pdfDict({
17
18
  Type: require_objects.pdfName("FontDescriptor"),
18
19
  FontName: require_objects.pdfName("STIXTwoMath-Regular"),
@@ -9,9 +9,10 @@ function buildWidthsArray(font, usedGlyphs) {
9
9
  for (const glyphId of [...usedGlyphs.keys()].sort((a, b) => a - b)) entries.push(pdfNum(glyphId), pdfArray([pdfNum(font.glyphSpaceWidth(glyphId))]));
10
10
  return pdfArray(entries);
11
11
  }
12
+ const GLYPH_SPACE_UNITS_PER_EM = 1e3;
12
13
  function buildFontDescriptor(font, fontFileRef) {
13
14
  const d = font.descriptor;
14
- const scale = 1e3 / d.unitsPerEm;
15
+ const scale = GLYPH_SPACE_UNITS_PER_EM / d.unitsPerEm;
15
16
  return pdfDict({
16
17
  Type: pdfName("FontDescriptor"),
17
18
  FontName: pdfName("STIXTwoMath-Regular"),
@@ -8,6 +8,15 @@ const require_math_stretch = require("./math-stretch.cjs");
8
8
  const require_math_table = require("./math-table.cjs");
9
9
  let byte_codec = require("byte-codec");
10
10
  //#region src/math-font.ts
11
+ const HEAD_UNITS_PER_EM_OFFSET = 18;
12
+ const HEAD_X_MIN_OFFSET = 36;
13
+ const HEAD_Y_MIN_OFFSET = 38;
14
+ const HEAD_X_MAX_OFFSET = 40;
15
+ const HEAD_Y_MAX_OFFSET = 42;
16
+ const HHEA_ASCENDER_OFFSET = 4;
17
+ const HHEA_DESCENDER_OFFSET = 6;
18
+ const OS2_CAP_HEIGHT_OFFSET = 88;
19
+ const GLYPH_SPACE_UNITS_PER_EM = 1e3;
11
20
  function toPt(designUnits, unitsPerEm, sizePt) {
12
21
  return designUnits / unitsPerEm * sizePt;
13
22
  }
@@ -124,12 +133,12 @@ function loadMathFont() {
124
133
  const os2Bytes = require_sfnt.sfntTableBytes(sfnt, "OS/2");
125
134
  const cffBytes = require_sfnt.sfntTableBytes(sfnt, "CFF ");
126
135
  if (headBytes === void 0 || hheaBytes === void 0 || cffBytes === void 0) throw new Error("embedded math font is missing a required sfnt table (head/hhea/CFF )");
127
- const unitsPerEm = require_sfnt.u16(headBytes, 18);
128
- const ascentDesignUnits = require_sfnt.i16(hheaBytes, 4);
129
- const descentDesignUnits = require_sfnt.i16(hheaBytes, 6);
130
- const bboxMin = [require_sfnt.i16(headBytes, 36), require_sfnt.i16(headBytes, 38)];
131
- const bboxMax = [require_sfnt.i16(headBytes, 40), require_sfnt.i16(headBytes, 42)];
132
- const capHeight = os2Bytes === void 0 ? ascentDesignUnits : require_sfnt.i16(os2Bytes, 88);
136
+ const unitsPerEm = require_sfnt.u16(headBytes, HEAD_UNITS_PER_EM_OFFSET);
137
+ const ascentDesignUnits = require_sfnt.i16(hheaBytes, HHEA_ASCENDER_OFFSET);
138
+ const descentDesignUnits = require_sfnt.i16(hheaBytes, HHEA_DESCENDER_OFFSET);
139
+ const bboxMin = [require_sfnt.i16(headBytes, HEAD_X_MIN_OFFSET), require_sfnt.i16(headBytes, HEAD_Y_MIN_OFFSET)];
140
+ const bboxMax = [require_sfnt.i16(headBytes, HEAD_X_MAX_OFFSET), require_sfnt.i16(headBytes, HEAD_Y_MAX_OFFSET)];
141
+ const capHeight = os2Bytes === void 0 ? ascentDesignUnits : require_sfnt.i16(os2Bytes, OS2_CAP_HEIGHT_OFFSET);
133
142
  const cmap = require_cmap_table.buildCmapLookup(sfnt);
134
143
  if (cmap === void 0) throw new Error("embedded math font has no readable cmap subtable");
135
144
  const hmtx = require_hmtx_table.parseHmtx(sfnt);
@@ -148,7 +157,7 @@ function loadMathFont() {
148
157
  italicAngle: 0
149
158
  },
150
159
  glyphId: (codePoint) => cmap(codePoint),
151
- glyphSpaceWidth: (glyphId) => hmtx.advanceWidth(glyphId) * 1e3 / unitsPerEm,
160
+ glyphSpaceWidth: (glyphId) => hmtx.advanceWidth(glyphId) * GLYPH_SPACE_UNITS_PER_EM / unitsPerEm,
152
161
  glyphInkBounds: (glyphId) => inkBounds?.bounds(glyphId),
153
162
  minConnectorOverlap: math.variants.minConnectorOverlap,
154
163
  stretchyConstruction: (codePoint, axis) => {
package/dist/math-font.js CHANGED
@@ -7,6 +7,15 @@ import { assembleStretchyGlyph, scaleMathStretchConstruction } from "./math-stre
7
7
  import { parseMathTable } from "./math-table.js";
8
8
  import { base64ToBytes } from "byte-codec";
9
9
  //#region src/math-font.ts
10
+ const HEAD_UNITS_PER_EM_OFFSET = 18;
11
+ const HEAD_X_MIN_OFFSET = 36;
12
+ const HEAD_Y_MIN_OFFSET = 38;
13
+ const HEAD_X_MAX_OFFSET = 40;
14
+ const HEAD_Y_MAX_OFFSET = 42;
15
+ const HHEA_ASCENDER_OFFSET = 4;
16
+ const HHEA_DESCENDER_OFFSET = 6;
17
+ const OS2_CAP_HEIGHT_OFFSET = 88;
18
+ const GLYPH_SPACE_UNITS_PER_EM = 1e3;
10
19
  function toPt(designUnits, unitsPerEm, sizePt) {
11
20
  return designUnits / unitsPerEm * sizePt;
12
21
  }
@@ -123,12 +132,12 @@ function loadMathFont() {
123
132
  const os2Bytes = sfntTableBytes(sfnt, "OS/2");
124
133
  const cffBytes = sfntTableBytes(sfnt, "CFF ");
125
134
  if (headBytes === void 0 || hheaBytes === void 0 || cffBytes === void 0) throw new Error("embedded math font is missing a required sfnt table (head/hhea/CFF )");
126
- const unitsPerEm = u16(headBytes, 18);
127
- const ascentDesignUnits = i16(hheaBytes, 4);
128
- const descentDesignUnits = i16(hheaBytes, 6);
129
- const bboxMin = [i16(headBytes, 36), i16(headBytes, 38)];
130
- const bboxMax = [i16(headBytes, 40), i16(headBytes, 42)];
131
- const capHeight = os2Bytes === void 0 ? ascentDesignUnits : i16(os2Bytes, 88);
135
+ const unitsPerEm = u16(headBytes, HEAD_UNITS_PER_EM_OFFSET);
136
+ const ascentDesignUnits = i16(hheaBytes, HHEA_ASCENDER_OFFSET);
137
+ const descentDesignUnits = i16(hheaBytes, HHEA_DESCENDER_OFFSET);
138
+ const bboxMin = [i16(headBytes, HEAD_X_MIN_OFFSET), i16(headBytes, HEAD_Y_MIN_OFFSET)];
139
+ const bboxMax = [i16(headBytes, HEAD_X_MAX_OFFSET), i16(headBytes, HEAD_Y_MAX_OFFSET)];
140
+ const capHeight = os2Bytes === void 0 ? ascentDesignUnits : i16(os2Bytes, OS2_CAP_HEIGHT_OFFSET);
132
141
  const cmap = buildCmapLookup(sfnt);
133
142
  if (cmap === void 0) throw new Error("embedded math font has no readable cmap subtable");
134
143
  const hmtx = parseHmtx(sfnt);
@@ -147,7 +156,7 @@ function loadMathFont() {
147
156
  italicAngle: 0
148
157
  },
149
158
  glyphId: (codePoint) => cmap(codePoint),
150
- glyphSpaceWidth: (glyphId) => hmtx.advanceWidth(glyphId) * 1e3 / unitsPerEm,
159
+ glyphSpaceWidth: (glyphId) => hmtx.advanceWidth(glyphId) * GLYPH_SPACE_UNITS_PER_EM / unitsPerEm,
151
160
  glyphInkBounds: (glyphId) => inkBounds?.bounds(glyphId),
152
161
  minConnectorOverlap: math.variants.minConnectorOverlap,
153
162
  stretchyConstruction: (codePoint, axis) => {