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
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"),
@@ -1,4 +1,4 @@
1
- import { n as PdfDict, r as PdfObject } from "./objects-B7HdMeWS.cjs";
1
+ import { n as PdfDict, r as PdfObject } from "./objects-e2RS3-yT.cjs";
2
2
  import { MathFont } from "./math-font.cjs";
3
3
  //#region src/math-font-write.d.ts
4
4
  interface MathFontObjectRefs {
@@ -1,4 +1,4 @@
1
- import { n as PdfDict, r as PdfObject } from "./objects-B7HdMeWS.js";
1
+ import { n as PdfDict, r as PdfObject } from "./objects-e2RS3-yT.js";
2
2
  import { MathFont } from "./math-font.js";
3
3
  //#region src/math-font-write.d.ts
4
4
  interface MathFontObjectRefs {
@@ -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) => {
@@ -34,15 +34,20 @@ const MATH_VALUE_RECORD_INDEX = {
34
34
  const MATH_VALUE_RECORDS_START = 8;
35
35
  const MATH_VALUE_RECORD_SIZE = 4;
36
36
  const RADICAL_DEGREE_BOTTOM_RAISE_PERCENT_OFFSET = 212;
37
+ const MATH_TABLE_HEADER_CONSTANTS_OFFSET_FIELD = 4;
38
+ const MATH_TABLE_HEADER_GLYPH_INFO_OFFSET_FIELD = 6;
39
+ const MATH_TABLE_HEADER_VARIANTS_OFFSET_FIELD = 8;
40
+ const PERCENT_SCALE_DENOMINATOR = 100;
41
+ const MATH_VALUE_TABLE_HEADER_SIZE = 4;
37
42
  function mathValueRecord(bytes, constantsOffset, index) {
38
43
  return require_sfnt.i16(bytes, constantsOffset + MATH_VALUE_RECORDS_START + index * MATH_VALUE_RECORD_SIZE);
39
44
  }
40
45
  function parseMathConstants(bytes, mathTableOffset) {
41
- const constantsOffset = mathTableOffset + require_sfnt.u16(bytes, mathTableOffset + 4);
46
+ const constantsOffset = mathTableOffset + require_sfnt.u16(bytes, mathTableOffset + MATH_TABLE_HEADER_CONSTANTS_OFFSET_FIELD);
42
47
  const field = (index) => mathValueRecord(bytes, constantsOffset, index);
43
48
  return {
44
- scriptPercentScaleDown: require_sfnt.i16(bytes, constantsOffset + 0) / 100,
45
- scriptScriptPercentScaleDown: require_sfnt.i16(bytes, constantsOffset + 2) / 100,
49
+ scriptPercentScaleDown: require_sfnt.i16(bytes, constantsOffset + 0) / PERCENT_SCALE_DENOMINATOR,
50
+ scriptScriptPercentScaleDown: require_sfnt.i16(bytes, constantsOffset + 2) / PERCENT_SCALE_DENOMINATOR,
46
51
  axisHeight: field(MATH_VALUE_RECORD_INDEX.axisHeight),
47
52
  subscriptShiftDown: field(MATH_VALUE_RECORD_INDEX.subscriptShiftDown),
48
53
  subscriptBaselineDropMin: field(MATH_VALUE_RECORD_INDEX.subscriptBaselineDropMin),
@@ -77,11 +82,11 @@ function parseGlyphValueTable(bytes, tableOffset) {
77
82
  const coverage = require_ot_layout_common.parseCoverage(bytes, tableOffset + require_sfnt.u16(bytes, tableOffset));
78
83
  const values = /* @__PURE__ */ new Map();
79
84
  if (coverage === void 0) return values;
80
- for (const [glyphId, coverageIndex] of coverage.entries()) values.set(glyphId, require_sfnt.i16(bytes, tableOffset + 4 + coverageIndex * 4));
85
+ for (const [glyphId, coverageIndex] of coverage.entries()) values.set(glyphId, require_sfnt.i16(bytes, tableOffset + MATH_VALUE_TABLE_HEADER_SIZE + coverageIndex * MATH_VALUE_RECORD_SIZE));
81
86
  return values;
82
87
  }
83
88
  function parseMathGlyphInfo(bytes, mathTableOffset) {
84
- const glyphInfoOffset = mathTableOffset + require_sfnt.u16(bytes, mathTableOffset + 6);
89
+ const glyphInfoOffset = mathTableOffset + require_sfnt.u16(bytes, mathTableOffset + MATH_TABLE_HEADER_GLYPH_INFO_OFFSET_FIELD);
85
90
  const italicsInfoOffset = require_sfnt.u16(bytes, glyphInfoOffset + 0);
86
91
  const topAccentOffset = require_sfnt.u16(bytes, glyphInfoOffset + 2);
87
92
  return {
@@ -93,6 +98,13 @@ const MATH_GLYPH_VARIANT_RECORD_SIZE = 4;
93
98
  const GLYPH_PART_RECORD_SIZE = 10;
94
99
  const GLYPH_PART_FLAG_EXTENDER = 1;
95
100
  const MATH_VARIANTS_HEADER_SIZE = 10;
101
+ const GLYPH_PART_END_CONNECTOR_OFFSET = 4;
102
+ const GLYPH_PART_FULL_ADVANCE_OFFSET = 6;
103
+ const GLYPH_PART_FLAGS_OFFSET = 8;
104
+ const MATH_GLYPH_CONSTRUCTION_HEADER_SIZE = 4;
105
+ const MATH_VARIANTS_HORIZONTAL_COVERAGE_OFFSET_FIELD = 4;
106
+ const MATH_VARIANTS_VERTICAL_COUNT_FIELD = 6;
107
+ const MATH_VARIANTS_HORIZONTAL_COUNT_FIELD = 8;
96
108
  function parseGlyphAssembly(bytes, assemblyOffset) {
97
109
  const partCount = require_sfnt.u16(bytes, assemblyOffset + MATH_VALUE_RECORD_SIZE);
98
110
  const parts = [];
@@ -101,9 +113,9 @@ function parseGlyphAssembly(bytes, assemblyOffset) {
101
113
  parts.push({
102
114
  glyphId: require_sfnt.u16(bytes, recordOffset),
103
115
  startConnectorLength: require_sfnt.u16(bytes, recordOffset + 2),
104
- endConnectorLength: require_sfnt.u16(bytes, recordOffset + 4),
105
- fullAdvance: require_sfnt.u16(bytes, recordOffset + 6),
106
- isExtender: (require_sfnt.u16(bytes, recordOffset + 8) & GLYPH_PART_FLAG_EXTENDER) !== 0
116
+ endConnectorLength: require_sfnt.u16(bytes, recordOffset + GLYPH_PART_END_CONNECTOR_OFFSET),
117
+ fullAdvance: require_sfnt.u16(bytes, recordOffset + GLYPH_PART_FULL_ADVANCE_OFFSET),
118
+ isExtender: (require_sfnt.u16(bytes, recordOffset + GLYPH_PART_FLAGS_OFFSET) & GLYPH_PART_FLAG_EXTENDER) !== 0
107
119
  });
108
120
  }
109
121
  return {
@@ -116,7 +128,7 @@ function parseGlyphConstruction(bytes, constructionOffset) {
116
128
  const variantCount = require_sfnt.u16(bytes, constructionOffset + 2);
117
129
  const variants = [];
118
130
  for (let i = 0; i < variantCount; i++) {
119
- const recordOffset = constructionOffset + 4 + i * MATH_GLYPH_VARIANT_RECORD_SIZE;
131
+ const recordOffset = constructionOffset + MATH_GLYPH_CONSTRUCTION_HEADER_SIZE + i * MATH_GLYPH_VARIANT_RECORD_SIZE;
120
132
  variants.push({
121
133
  glyphId: require_sfnt.u16(bytes, recordOffset),
122
134
  advanceMeasurement: require_sfnt.u16(bytes, recordOffset + 2)
@@ -139,7 +151,7 @@ function parseConstructionsForAxis(bytes, variantsOffset, coverageOffset, count,
139
151
  return constructions;
140
152
  }
141
153
  function parseMathVariants(bytes, mathTableOffset) {
142
- const variantsTableOffset = require_sfnt.u16(bytes, mathTableOffset + 8);
154
+ const variantsTableOffset = require_sfnt.u16(bytes, mathTableOffset + MATH_TABLE_HEADER_VARIANTS_OFFSET_FIELD);
143
155
  if (variantsTableOffset === 0) return {
144
156
  minConnectorOverlap: 0,
145
157
  vertical: /* @__PURE__ */ new Map(),
@@ -147,9 +159,9 @@ function parseMathVariants(bytes, mathTableOffset) {
147
159
  };
148
160
  const variantsOffset = mathTableOffset + variantsTableOffset;
149
161
  const verticalCoverageOffset = require_sfnt.u16(bytes, variantsOffset + 2);
150
- const horizontalCoverageOffset = require_sfnt.u16(bytes, variantsOffset + 4);
151
- const verticalCount = require_sfnt.u16(bytes, variantsOffset + 6);
152
- const horizontalCount = require_sfnt.u16(bytes, variantsOffset + 8);
162
+ const horizontalCoverageOffset = require_sfnt.u16(bytes, variantsOffset + MATH_VARIANTS_HORIZONTAL_COVERAGE_OFFSET_FIELD);
163
+ const verticalCount = require_sfnt.u16(bytes, variantsOffset + MATH_VARIANTS_VERTICAL_COUNT_FIELD);
164
+ const horizontalCount = require_sfnt.u16(bytes, variantsOffset + MATH_VARIANTS_HORIZONTAL_COUNT_FIELD);
153
165
  const verticalArrayOffset = variantsOffset + MATH_VARIANTS_HEADER_SIZE;
154
166
  const horizontalArrayOffset = verticalArrayOffset + verticalCount * 2;
155
167
  return {
@@ -33,15 +33,20 @@ const MATH_VALUE_RECORD_INDEX = {
33
33
  const MATH_VALUE_RECORDS_START = 8;
34
34
  const MATH_VALUE_RECORD_SIZE = 4;
35
35
  const RADICAL_DEGREE_BOTTOM_RAISE_PERCENT_OFFSET = 212;
36
+ const MATH_TABLE_HEADER_CONSTANTS_OFFSET_FIELD = 4;
37
+ const MATH_TABLE_HEADER_GLYPH_INFO_OFFSET_FIELD = 6;
38
+ const MATH_TABLE_HEADER_VARIANTS_OFFSET_FIELD = 8;
39
+ const PERCENT_SCALE_DENOMINATOR = 100;
40
+ const MATH_VALUE_TABLE_HEADER_SIZE = 4;
36
41
  function mathValueRecord(bytes, constantsOffset, index) {
37
42
  return i16(bytes, constantsOffset + MATH_VALUE_RECORDS_START + index * MATH_VALUE_RECORD_SIZE);
38
43
  }
39
44
  function parseMathConstants(bytes, mathTableOffset) {
40
- const constantsOffset = mathTableOffset + u16(bytes, mathTableOffset + 4);
45
+ const constantsOffset = mathTableOffset + u16(bytes, mathTableOffset + MATH_TABLE_HEADER_CONSTANTS_OFFSET_FIELD);
41
46
  const field = (index) => mathValueRecord(bytes, constantsOffset, index);
42
47
  return {
43
- scriptPercentScaleDown: i16(bytes, constantsOffset + 0) / 100,
44
- scriptScriptPercentScaleDown: i16(bytes, constantsOffset + 2) / 100,
48
+ scriptPercentScaleDown: i16(bytes, constantsOffset + 0) / PERCENT_SCALE_DENOMINATOR,
49
+ scriptScriptPercentScaleDown: i16(bytes, constantsOffset + 2) / PERCENT_SCALE_DENOMINATOR,
45
50
  axisHeight: field(MATH_VALUE_RECORD_INDEX.axisHeight),
46
51
  subscriptShiftDown: field(MATH_VALUE_RECORD_INDEX.subscriptShiftDown),
47
52
  subscriptBaselineDropMin: field(MATH_VALUE_RECORD_INDEX.subscriptBaselineDropMin),
@@ -76,11 +81,11 @@ function parseGlyphValueTable(bytes, tableOffset) {
76
81
  const coverage = parseCoverage(bytes, tableOffset + u16(bytes, tableOffset));
77
82
  const values = /* @__PURE__ */ new Map();
78
83
  if (coverage === void 0) return values;
79
- for (const [glyphId, coverageIndex] of coverage.entries()) values.set(glyphId, i16(bytes, tableOffset + 4 + coverageIndex * 4));
84
+ for (const [glyphId, coverageIndex] of coverage.entries()) values.set(glyphId, i16(bytes, tableOffset + MATH_VALUE_TABLE_HEADER_SIZE + coverageIndex * MATH_VALUE_RECORD_SIZE));
80
85
  return values;
81
86
  }
82
87
  function parseMathGlyphInfo(bytes, mathTableOffset) {
83
- const glyphInfoOffset = mathTableOffset + u16(bytes, mathTableOffset + 6);
88
+ const glyphInfoOffset = mathTableOffset + u16(bytes, mathTableOffset + MATH_TABLE_HEADER_GLYPH_INFO_OFFSET_FIELD);
84
89
  const italicsInfoOffset = u16(bytes, glyphInfoOffset + 0);
85
90
  const topAccentOffset = u16(bytes, glyphInfoOffset + 2);
86
91
  return {
@@ -92,6 +97,13 @@ const MATH_GLYPH_VARIANT_RECORD_SIZE = 4;
92
97
  const GLYPH_PART_RECORD_SIZE = 10;
93
98
  const GLYPH_PART_FLAG_EXTENDER = 1;
94
99
  const MATH_VARIANTS_HEADER_SIZE = 10;
100
+ const GLYPH_PART_END_CONNECTOR_OFFSET = 4;
101
+ const GLYPH_PART_FULL_ADVANCE_OFFSET = 6;
102
+ const GLYPH_PART_FLAGS_OFFSET = 8;
103
+ const MATH_GLYPH_CONSTRUCTION_HEADER_SIZE = 4;
104
+ const MATH_VARIANTS_HORIZONTAL_COVERAGE_OFFSET_FIELD = 4;
105
+ const MATH_VARIANTS_VERTICAL_COUNT_FIELD = 6;
106
+ const MATH_VARIANTS_HORIZONTAL_COUNT_FIELD = 8;
95
107
  function parseGlyphAssembly(bytes, assemblyOffset) {
96
108
  const partCount = u16(bytes, assemblyOffset + MATH_VALUE_RECORD_SIZE);
97
109
  const parts = [];
@@ -100,9 +112,9 @@ function parseGlyphAssembly(bytes, assemblyOffset) {
100
112
  parts.push({
101
113
  glyphId: u16(bytes, recordOffset),
102
114
  startConnectorLength: u16(bytes, recordOffset + 2),
103
- endConnectorLength: u16(bytes, recordOffset + 4),
104
- fullAdvance: u16(bytes, recordOffset + 6),
105
- isExtender: (u16(bytes, recordOffset + 8) & GLYPH_PART_FLAG_EXTENDER) !== 0
115
+ endConnectorLength: u16(bytes, recordOffset + GLYPH_PART_END_CONNECTOR_OFFSET),
116
+ fullAdvance: u16(bytes, recordOffset + GLYPH_PART_FULL_ADVANCE_OFFSET),
117
+ isExtender: (u16(bytes, recordOffset + GLYPH_PART_FLAGS_OFFSET) & GLYPH_PART_FLAG_EXTENDER) !== 0
106
118
  });
107
119
  }
108
120
  return {
@@ -115,7 +127,7 @@ function parseGlyphConstruction(bytes, constructionOffset) {
115
127
  const variantCount = u16(bytes, constructionOffset + 2);
116
128
  const variants = [];
117
129
  for (let i = 0; i < variantCount; i++) {
118
- const recordOffset = constructionOffset + 4 + i * MATH_GLYPH_VARIANT_RECORD_SIZE;
130
+ const recordOffset = constructionOffset + MATH_GLYPH_CONSTRUCTION_HEADER_SIZE + i * MATH_GLYPH_VARIANT_RECORD_SIZE;
119
131
  variants.push({
120
132
  glyphId: u16(bytes, recordOffset),
121
133
  advanceMeasurement: u16(bytes, recordOffset + 2)
@@ -138,7 +150,7 @@ function parseConstructionsForAxis(bytes, variantsOffset, coverageOffset, count,
138
150
  return constructions;
139
151
  }
140
152
  function parseMathVariants(bytes, mathTableOffset) {
141
- const variantsTableOffset = u16(bytes, mathTableOffset + 8);
153
+ const variantsTableOffset = u16(bytes, mathTableOffset + MATH_TABLE_HEADER_VARIANTS_OFFSET_FIELD);
142
154
  if (variantsTableOffset === 0) return {
143
155
  minConnectorOverlap: 0,
144
156
  vertical: /* @__PURE__ */ new Map(),
@@ -146,9 +158,9 @@ function parseMathVariants(bytes, mathTableOffset) {
146
158
  };
147
159
  const variantsOffset = mathTableOffset + variantsTableOffset;
148
160
  const verticalCoverageOffset = u16(bytes, variantsOffset + 2);
149
- const horizontalCoverageOffset = u16(bytes, variantsOffset + 4);
150
- const verticalCount = u16(bytes, variantsOffset + 6);
151
- const horizontalCount = u16(bytes, variantsOffset + 8);
161
+ const horizontalCoverageOffset = u16(bytes, variantsOffset + MATH_VARIANTS_HORIZONTAL_COVERAGE_OFFSET_FIELD);
162
+ const verticalCount = u16(bytes, variantsOffset + MATH_VARIANTS_VERTICAL_COUNT_FIELD);
163
+ const horizontalCount = u16(bytes, variantsOffset + MATH_VARIANTS_HORIZONTAL_COUNT_FIELD);
152
164
  const verticalArrayOffset = variantsOffset + MATH_VARIANTS_HEADER_SIZE;
153
165
  const horizontalArrayOffset = verticalArrayOffset + verticalCount * 2;
154
166
  return {
package/dist/matrix.cjs CHANGED
@@ -48,8 +48,9 @@ function scaleMatrix(sx, sy) {
48
48
  ];
49
49
  }
50
50
  const BEZIER_KAPPA = .5522847498;
51
+ const DEGREES_PER_HALF_TURN = 180;
51
52
  function rotationMatrix(degrees) {
52
- const radians = degrees * Math.PI / 180;
53
+ const radians = degrees * Math.PI / DEGREES_PER_HALF_TURN;
53
54
  const cos = Math.cos(radians);
54
55
  const sin = Math.sin(radians);
55
56
  return [
@@ -68,7 +69,7 @@ function matrixScaleY(m) {
68
69
  return Math.hypot(m[2], m[3]);
69
70
  }
70
71
  function matrixRotationDegrees(m) {
71
- return Math.atan2(m[1], m[0]) * 180 / Math.PI;
72
+ return Math.atan2(m[1], m[0]) * DEGREES_PER_HALF_TURN / Math.PI;
72
73
  }
73
74
  function rotatePointAboutCenter(point, center, degrees) {
74
75
  const relative = {