pdf-codec 1.5.0 → 1.7.0

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 (214) hide show
  1. package/README.md +100 -9
  2. package/dist/assets/caladea-bold.cjs +5 -0
  3. package/dist/assets/caladea-bold.d.cts +4 -0
  4. package/dist/assets/caladea-bold.d.ts +4 -0
  5. package/dist/assets/caladea-bold.js +4 -0
  6. package/dist/assets/caladea-bolditalic.cjs +5 -0
  7. package/dist/assets/caladea-bolditalic.d.cts +4 -0
  8. package/dist/assets/caladea-bolditalic.d.ts +4 -0
  9. package/dist/assets/caladea-bolditalic.js +4 -0
  10. package/dist/assets/caladea-italic.cjs +5 -0
  11. package/dist/assets/caladea-italic.d.cts +4 -0
  12. package/dist/assets/caladea-italic.d.ts +4 -0
  13. package/dist/assets/caladea-italic.js +4 -0
  14. package/dist/assets/caladea-regular.cjs +5 -0
  15. package/dist/assets/caladea-regular.d.cts +4 -0
  16. package/dist/assets/caladea-regular.d.ts +4 -0
  17. package/dist/assets/caladea-regular.js +4 -0
  18. package/dist/assets/carlito-bold.cjs +5 -0
  19. package/dist/assets/carlito-bold.d.cts +4 -0
  20. package/dist/assets/carlito-bold.d.ts +4 -0
  21. package/dist/assets/carlito-bold.js +4 -0
  22. package/dist/assets/carlito-bolditalic.cjs +5 -0
  23. package/dist/assets/carlito-bolditalic.d.cts +4 -0
  24. package/dist/assets/carlito-bolditalic.d.ts +4 -0
  25. package/dist/assets/carlito-bolditalic.js +4 -0
  26. package/dist/assets/carlito-italic.cjs +5 -0
  27. package/dist/assets/carlito-italic.d.cts +4 -0
  28. package/dist/assets/carlito-italic.d.ts +4 -0
  29. package/dist/assets/carlito-italic.js +4 -0
  30. package/dist/assets/carlito-regular.cjs +5 -0
  31. package/dist/assets/carlito-regular.d.cts +4 -0
  32. package/dist/assets/carlito-regular.d.ts +4 -0
  33. package/dist/assets/carlito-regular.js +4 -0
  34. package/dist/cff-bounds.cjs +432 -0
  35. package/dist/cff-bounds.d.cts +9 -0
  36. package/dist/cff-bounds.d.ts +9 -0
  37. package/dist/cff-bounds.js +431 -0
  38. package/dist/cff-probe.cjs +35 -0
  39. package/dist/cff-probe.d.cts +10 -0
  40. package/dist/cff-probe.d.ts +10 -0
  41. package/dist/cff-probe.js +34 -0
  42. package/dist/cff.cjs +158 -0
  43. package/dist/cff.d.cts +17 -0
  44. package/dist/cff.d.ts +17 -0
  45. package/dist/cff.js +150 -0
  46. package/dist/cmap-table.cjs +108 -0
  47. package/dist/cmap-table.d.cts +6 -0
  48. package/dist/cmap-table.d.ts +6 -0
  49. package/dist/cmap-table.js +107 -0
  50. package/dist/content-write.cjs +34 -14
  51. package/dist/content-write.d.cts +9 -2
  52. package/dist/content-write.d.ts +9 -2
  53. package/dist/content-write.js +34 -14
  54. package/dist/embedded-font-CLedn-mT.d.cts +42 -0
  55. package/dist/embedded-font-CbqkKgBl.d.ts +42 -0
  56. package/dist/embedded-font-write.cjs +92 -0
  57. package/dist/embedded-font-write.d.cts +22 -0
  58. package/dist/embedded-font-write.d.ts +22 -0
  59. package/dist/embedded-font-write.js +90 -0
  60. package/dist/embedded-font.cjs +142 -0
  61. package/dist/embedded-font.d.cts +2 -0
  62. package/dist/embedded-font.d.ts +2 -0
  63. package/dist/embedded-font.js +138 -0
  64. package/dist/filters.cjs +45 -2
  65. package/dist/filters.d.cts +4 -3
  66. package/dist/filters.d.ts +4 -3
  67. package/dist/filters.js +45 -2
  68. package/dist/font-registry-Cn7P9lAh.d.ts +38 -0
  69. package/dist/font-registry-yby02snZ.d.cts +38 -0
  70. package/dist/font-registry.cjs +152 -0
  71. package/dist/font-registry.d.cts +2 -0
  72. package/dist/font-registry.d.ts +2 -0
  73. package/dist/font-registry.js +150 -0
  74. package/dist/font-substitutes.cjs +13 -0
  75. package/dist/font-substitutes.d.cts +5 -0
  76. package/dist/font-substitutes.d.ts +5 -0
  77. package/dist/font-substitutes.js +12 -0
  78. package/dist/font-tables.cjs +127 -0
  79. package/dist/font-tables.d.cts +43 -0
  80. package/dist/font-tables.d.ts +43 -0
  81. package/dist/font-tables.js +122 -0
  82. package/dist/fonts.cjs +1 -0
  83. package/dist/fonts.d.cts +2 -1
  84. package/dist/fonts.d.ts +2 -1
  85. package/dist/fonts.js +1 -1
  86. package/dist/formula.d.cts +1 -1
  87. package/dist/formula.d.ts +1 -1
  88. package/dist/glyf.cjs +183 -0
  89. package/dist/glyf.d.cts +33 -0
  90. package/dist/glyf.d.ts +33 -0
  91. package/dist/glyf.js +181 -0
  92. package/dist/glyph-bounds-BV_Z40KS.d.cts +10 -0
  93. package/dist/glyph-bounds-BV_Z40KS.d.ts +10 -0
  94. package/dist/glyph-bounds.cjs +12 -0
  95. package/dist/glyph-bounds.d.cts +2 -0
  96. package/dist/glyph-bounds.d.ts +2 -0
  97. package/dist/glyph-bounds.js +11 -0
  98. package/dist/{math-hmtx.cjs → hmtx-table.cjs} +3 -3
  99. package/dist/{math-hmtx.d.ts → hmtx-table.d.cts} +2 -2
  100. package/dist/{math-hmtx.d.cts → hmtx-table.d.ts} +2 -2
  101. package/dist/{math-hmtx.js → hmtx-table.js} +3 -3
  102. package/dist/image/jbig2-arith.cjs +432 -0
  103. package/dist/image/jbig2-arith.d.cts +23 -0
  104. package/dist/image/jbig2-arith.d.ts +23 -0
  105. package/dist/image/jbig2-arith.js +426 -0
  106. package/dist/image/jbig2-bitmap.cjs +80 -0
  107. package/dist/image/jbig2-bitmap.d.cts +20 -0
  108. package/dist/image/jbig2-bitmap.d.ts +20 -0
  109. package/dist/image/jbig2-bitmap.js +72 -0
  110. package/dist/image/jbig2-errors.cjs +17 -0
  111. package/dist/image/jbig2-errors.d.cts +2 -0
  112. package/dist/image/jbig2-errors.d.ts +2 -0
  113. package/dist/image/jbig2-errors.js +15 -0
  114. package/dist/image/jbig2-generic.cjs +242 -0
  115. package/dist/image/jbig2-generic.d.cts +27 -0
  116. package/dist/image/jbig2-generic.d.ts +27 -0
  117. package/dist/image/jbig2-generic.js +237 -0
  118. package/dist/image/jbig2-text.cjs +175 -0
  119. package/dist/image/jbig2-text.d.cts +58 -0
  120. package/dist/image/jbig2-text.d.ts +58 -0
  121. package/dist/image/jbig2-text.js +170 -0
  122. package/dist/image/jbig2.cjs +333 -0
  123. package/dist/image/jbig2.d.cts +15 -0
  124. package/dist/image/jbig2.d.ts +15 -0
  125. package/dist/image/jbig2.js +332 -0
  126. package/dist/image/jp2-boxes.cjs +148 -0
  127. package/dist/image/jp2-boxes.d.cts +26 -0
  128. package/dist/image/jp2-boxes.d.ts +26 -0
  129. package/dist/image/jp2-boxes.js +146 -0
  130. package/dist/image/jpeg2000-codestream.cjs +309 -0
  131. package/dist/image/jpeg2000-codestream.d.cts +78 -0
  132. package/dist/image/jpeg2000-codestream.d.ts +78 -0
  133. package/dist/image/jpeg2000-codestream.js +308 -0
  134. package/dist/image/jpeg2000-dwt.cjs +148 -0
  135. package/dist/image/jpeg2000-dwt.d.cts +34 -0
  136. package/dist/image/jpeg2000-dwt.d.ts +34 -0
  137. package/dist/image/jpeg2000-dwt.js +145 -0
  138. package/dist/image/jpeg2000-errors.cjs +17 -0
  139. package/dist/image/jpeg2000-errors.d.cts +9 -0
  140. package/dist/image/jpeg2000-errors.d.ts +9 -0
  141. package/dist/image/jpeg2000-errors.js +15 -0
  142. package/dist/image/jpeg2000-t1.cjs +254 -0
  143. package/dist/image/jpeg2000-t1.d.cts +18 -0
  144. package/dist/image/jpeg2000-t1.d.ts +18 -0
  145. package/dist/image/jpeg2000-t1.js +253 -0
  146. package/dist/image/jpeg2000-t2.cjs +316 -0
  147. package/dist/image/jpeg2000-t2.d.cts +79 -0
  148. package/dist/image/jpeg2000-t2.d.ts +79 -0
  149. package/dist/image/jpeg2000-t2.js +311 -0
  150. package/dist/image/jpeg2000-tagtree.cjs +105 -0
  151. package/dist/image/jpeg2000-tagtree.d.cts +29 -0
  152. package/dist/image/jpeg2000-tagtree.d.ts +29 -0
  153. package/dist/image/jpeg2000-tagtree.js +103 -0
  154. package/dist/image/jpeg2000.cjs +322 -0
  155. package/dist/image/jpeg2000.d.cts +54 -0
  156. package/dist/image/jpeg2000.d.ts +54 -0
  157. package/dist/image/jpeg2000.js +320 -0
  158. package/dist/images-read.cjs +78 -1
  159. package/dist/images-read.js +78 -1
  160. package/dist/index.cjs +22 -0
  161. package/dist/index.d.cts +14 -3
  162. package/dist/index.d.ts +14 -3
  163. package/dist/index.js +9 -2
  164. package/dist/jbig2-errors-Bj6MPxrx.d.cts +9 -0
  165. package/dist/jbig2-errors-Bj6MPxrx.d.ts +9 -0
  166. package/dist/math-font-write.cjs +2 -31
  167. package/dist/math-font-write.js +1 -30
  168. package/dist/math-font.cjs +50 -23
  169. package/dist/math-font.d.cts +8 -1
  170. package/dist/math-font.d.ts +8 -1
  171. package/dist/math-font.js +48 -21
  172. package/dist/math-stretch-Bwk_bxh1.d.ts +24 -0
  173. package/dist/math-stretch-DXWjs8gL.d.cts +24 -0
  174. package/dist/math-stretch.cjs +96 -0
  175. package/dist/math-stretch.d.cts +2 -0
  176. package/dist/math-stretch.d.ts +2 -0
  177. package/dist/math-stretch.js +94 -0
  178. package/dist/math-table-DhPrNoPa.d.ts +70 -0
  179. package/dist/math-table-gFNB8DmQ.d.cts +70 -0
  180. package/dist/math-table.cjs +69 -1
  181. package/dist/math-table.d.cts +2 -45
  182. package/dist/math-table.d.ts +2 -45
  183. package/dist/math-table.js +69 -1
  184. package/dist/{math-types-Ba8qAf1p.d.cts → math-types-YSQUTviw.d.cts} +2 -0
  185. package/dist/{math-types-Ba8qAf1p.d.ts → math-types-YSQUTviw.d.ts} +2 -0
  186. package/dist/math-types.d.cts +1 -1
  187. package/dist/math-types.d.ts +1 -1
  188. package/dist/measure.cjs +65 -14
  189. package/dist/measure.d.cts +8 -1
  190. package/dist/measure.d.ts +8 -1
  191. package/dist/measure.js +64 -15
  192. package/dist/sfnt-V08bb5ut.d.cts +21 -0
  193. package/dist/sfnt-V08bb5ut.d.ts +21 -0
  194. package/dist/sfnt-subset.cjs +250 -0
  195. package/dist/sfnt-subset.d.cts +11 -0
  196. package/dist/sfnt-subset.d.ts +11 -0
  197. package/dist/sfnt-subset.js +249 -0
  198. package/dist/sfnt.cjs +50 -4
  199. package/dist/sfnt.d.cts +2 -17
  200. package/dist/sfnt.d.ts +2 -17
  201. package/dist/sfnt.js +47 -5
  202. package/dist/tounicode.cjs +34 -0
  203. package/dist/tounicode.d.cts +5 -0
  204. package/dist/tounicode.d.ts +5 -0
  205. package/dist/tounicode.js +33 -0
  206. package/dist/write.cjs +80 -10
  207. package/dist/write.d.cts +6 -0
  208. package/dist/write.d.ts +6 -0
  209. package/dist/write.js +81 -11
  210. package/package.json +1 -1
  211. package/dist/math-cmap.cjs +0 -81
  212. package/dist/math-cmap.d.cts +0 -6
  213. package/dist/math-cmap.d.ts +0 -6
  214. package/dist/math-cmap.js +0 -80
package/dist/glyf.js ADDED
@@ -0,0 +1,181 @@
1
+ import { f2dot14, hasBytes, i16, sfntTableBytes, u16, u32, u8 } from "./sfnt.js";
2
+ import { unionGlyphInkBounds } from "./glyph-bounds.js";
3
+ //#region src/glyf.ts
4
+ const LOCA_SHORT_ENTRY_SIZE = 2;
5
+ const LOCA_LONG_ENTRY_SIZE = 4;
6
+ const LOCA_SHORT_OFFSET_SCALE = 2;
7
+ function parseLoca(font, options) {
8
+ const bytes = sfntTableBytes(font, "loca");
9
+ if (bytes === void 0) return;
10
+ const entryCount = options.numGlyphs + 1;
11
+ const entrySize = options.indexToLocFormat === 0 ? LOCA_SHORT_ENTRY_SIZE : LOCA_LONG_ENTRY_SIZE;
12
+ if (!hasBytes(bytes, 0, entryCount * entrySize)) return;
13
+ const offsets = [];
14
+ for (let i = 0; i < entryCount; i++) offsets.push(options.indexToLocFormat === 0 ? u16(bytes, i * LOCA_SHORT_ENTRY_SIZE) * LOCA_SHORT_OFFSET_SCALE : u32(bytes, i * LOCA_LONG_ENTRY_SIZE));
15
+ return offsets;
16
+ }
17
+ const GLYPH_HEADER_SIZE = 10;
18
+ const ARG_1_AND_2_ARE_WORDS = 1;
19
+ const ARGS_ARE_XY_VALUES = 2;
20
+ const WE_HAVE_A_SCALE = 8;
21
+ const MORE_COMPONENTS = 32;
22
+ const WE_HAVE_AN_X_AND_Y_SCALE = 64;
23
+ const WE_HAVE_A_TWO_BY_TWO = 128;
24
+ const SCALED_COMPONENT_OFFSET = 2048;
25
+ const UNSCALED_COMPONENT_OFFSET = 4096;
26
+ const MAX_COMPOSITE_DEPTH = 5;
27
+ const COMPONENT_RECORD_HEADER_SIZE = 4;
28
+ function signedByte(value) {
29
+ return value >= 128 ? value - 256 : value;
30
+ }
31
+ function readComponents(glyph) {
32
+ const components = [];
33
+ let offset = GLYPH_HEADER_SIZE;
34
+ for (;;) {
35
+ if (!hasBytes(glyph, offset, COMPONENT_RECORD_HEADER_SIZE)) return;
36
+ const flags = u16(glyph, offset);
37
+ const glyphIndex = u16(glyph, offset + 2);
38
+ offset += COMPONENT_RECORD_HEADER_SIZE;
39
+ const argsAreWords = (flags & ARG_1_AND_2_ARE_WORDS) !== 0;
40
+ const argsAreXyValues = (flags & ARGS_ARE_XY_VALUES) !== 0;
41
+ const argsSize = argsAreWords ? 4 : 2;
42
+ if (!hasBytes(glyph, offset, argsSize)) return;
43
+ let argument1;
44
+ let argument2;
45
+ if (argsAreWords) {
46
+ argument1 = argsAreXyValues ? i16(glyph, offset) : u16(glyph, offset);
47
+ argument2 = argsAreXyValues ? i16(glyph, offset + 2) : u16(glyph, offset + 2);
48
+ } else {
49
+ argument1 = argsAreXyValues ? signedByte(u8(glyph, offset)) : u8(glyph, offset);
50
+ argument2 = argsAreXyValues ? signedByte(u8(glyph, offset + 1)) : u8(glyph, offset + 1);
51
+ }
52
+ offset += argsSize;
53
+ let transform;
54
+ if ((flags & WE_HAVE_A_SCALE) !== 0) {
55
+ if (!hasBytes(glyph, offset, 2)) return;
56
+ const scale = f2dot14(glyph, offset);
57
+ transform = [
58
+ scale,
59
+ 0,
60
+ 0,
61
+ scale
62
+ ];
63
+ offset += 2;
64
+ } else if ((flags & WE_HAVE_AN_X_AND_Y_SCALE) !== 0) {
65
+ if (!hasBytes(glyph, offset, 4)) return;
66
+ transform = [
67
+ f2dot14(glyph, offset),
68
+ 0,
69
+ 0,
70
+ f2dot14(glyph, offset + 2)
71
+ ];
72
+ offset += 4;
73
+ } else if ((flags & WE_HAVE_A_TWO_BY_TWO) !== 0) {
74
+ if (!hasBytes(glyph, offset, 8)) return;
75
+ transform = [
76
+ f2dot14(glyph, offset),
77
+ f2dot14(glyph, offset + 2),
78
+ f2dot14(glyph, offset + 4),
79
+ f2dot14(glyph, offset + 6)
80
+ ];
81
+ offset += 8;
82
+ }
83
+ components.push({
84
+ flags,
85
+ glyphIndex,
86
+ argument1,
87
+ argument2,
88
+ argsAreXyValues,
89
+ transform
90
+ });
91
+ if ((flags & MORE_COMPONENTS) === 0) return components;
92
+ }
93
+ }
94
+ function placeComponentBounds(bounds, component) {
95
+ const [a, b, c, d] = component.transform ?? [
96
+ 1,
97
+ 0,
98
+ 0,
99
+ 1
100
+ ];
101
+ const corners = [
102
+ [bounds.xMin, bounds.yMin],
103
+ [bounds.xMax, bounds.yMin],
104
+ [bounds.xMin, bounds.yMax],
105
+ [bounds.xMax, bounds.yMax]
106
+ ];
107
+ const xs = corners.map(([x, y]) => a * x + c * y);
108
+ const ys = corners.map(([x, y]) => b * x + d * y);
109
+ const scaledOffset = (component.flags & SCALED_COMPONENT_OFFSET) !== 0 && (component.flags & UNSCALED_COMPONENT_OFFSET) === 0;
110
+ const dx = scaledOffset ? a * component.argument1 + c * component.argument2 : component.argument1;
111
+ const dy = scaledOffset ? b * component.argument1 + d * component.argument2 : component.argument2;
112
+ return {
113
+ xMin: Math.min(...xs) + dx,
114
+ yMin: Math.min(...ys) + dy,
115
+ xMax: Math.max(...xs) + dx,
116
+ yMax: Math.max(...ys) + dy
117
+ };
118
+ }
119
+ function parseGlyf(font, options) {
120
+ const glyfBytes = sfntTableBytes(font, "glyf");
121
+ const loca = parseLoca(font, options);
122
+ if (glyfBytes === void 0 || loca === void 0) return;
123
+ const glyphBytes = (glyphId) => {
124
+ if (!Number.isInteger(glyphId) || glyphId < 0 || glyphId >= options.numGlyphs) return;
125
+ const start = loca[glyphId];
126
+ const end = loca[glyphId + 1];
127
+ if (end < start || !hasBytes(glyfBytes, start, end - start)) return;
128
+ return glyfBytes.subarray(start, end);
129
+ };
130
+ const glyphHeader = (glyphId) => {
131
+ const glyph = glyphBytes(glyphId);
132
+ if (glyph === void 0 || !hasBytes(glyph, 0, GLYPH_HEADER_SIZE)) return;
133
+ return {
134
+ numberOfContours: i16(glyph, 0),
135
+ xMin: i16(glyph, 2),
136
+ yMin: i16(glyph, 4),
137
+ xMax: i16(glyph, 6),
138
+ yMax: i16(glyph, 8)
139
+ };
140
+ };
141
+ const compositeComponents = (glyphId) => {
142
+ const header = glyphHeader(glyphId);
143
+ if (header === void 0 || header.numberOfContours >= 0) return;
144
+ const glyph = glyphBytes(glyphId);
145
+ return glyph === void 0 ? void 0 : readComponents(glyph);
146
+ };
147
+ const resolveInkBounds = (glyphId, depth) => {
148
+ const header = glyphHeader(glyphId);
149
+ if (header === void 0) return;
150
+ if (header.numberOfContours >= 0) return {
151
+ xMin: header.xMin,
152
+ yMin: header.yMin,
153
+ xMax: header.xMax,
154
+ yMax: header.yMax
155
+ };
156
+ if (depth >= MAX_COMPOSITE_DEPTH) return;
157
+ const components = compositeComponents(glyphId);
158
+ if (components === void 0) return;
159
+ let bounds;
160
+ for (const component of components) {
161
+ if (!component.argsAreXyValues) return;
162
+ const componentBytes = glyphBytes(component.glyphIndex);
163
+ if (componentBytes === void 0) return;
164
+ if (componentBytes.length === 0) continue;
165
+ const componentBounds = resolveInkBounds(component.glyphIndex, depth + 1);
166
+ if (componentBounds === void 0) return;
167
+ const placed = placeComponentBounds(componentBounds, component);
168
+ bounds = bounds === void 0 ? placed : unionGlyphInkBounds(bounds, placed);
169
+ }
170
+ return bounds;
171
+ };
172
+ return {
173
+ numGlyphs: options.numGlyphs,
174
+ glyphBytes,
175
+ glyphHeader,
176
+ compositeComponents,
177
+ glyphInkBounds: (glyphId) => resolveInkBounds(glyphId, 0)
178
+ };
179
+ }
180
+ //#endregion
181
+ export { parseGlyf, parseLoca };
@@ -0,0 +1,10 @@
1
+ //#region src/glyph-bounds.d.ts
2
+ interface GlyphInkBounds {
3
+ readonly xMin: number;
4
+ readonly yMin: number;
5
+ readonly xMax: number;
6
+ readonly yMax: number;
7
+ }
8
+ declare function unionGlyphInkBounds(a: GlyphInkBounds, b: GlyphInkBounds): GlyphInkBounds;
9
+ //#endregion
10
+ export { unionGlyphInkBounds as n, GlyphInkBounds as t };
@@ -0,0 +1,10 @@
1
+ //#region src/glyph-bounds.d.ts
2
+ interface GlyphInkBounds {
3
+ readonly xMin: number;
4
+ readonly yMin: number;
5
+ readonly xMax: number;
6
+ readonly yMax: number;
7
+ }
8
+ declare function unionGlyphInkBounds(a: GlyphInkBounds, b: GlyphInkBounds): GlyphInkBounds;
9
+ //#endregion
10
+ export { unionGlyphInkBounds as n, GlyphInkBounds as t };
@@ -0,0 +1,12 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/glyph-bounds.ts
3
+ function unionGlyphInkBounds(a, b) {
4
+ return {
5
+ xMin: Math.min(a.xMin, b.xMin),
6
+ yMin: Math.min(a.yMin, b.yMin),
7
+ xMax: Math.max(a.xMax, b.xMax),
8
+ yMax: Math.max(a.yMax, b.yMax)
9
+ };
10
+ }
11
+ //#endregion
12
+ exports.unionGlyphInkBounds = unionGlyphInkBounds;
@@ -0,0 +1,2 @@
1
+ import { n as unionGlyphInkBounds, t as GlyphInkBounds } from "./glyph-bounds-BV_Z40KS.cjs";
2
+ export { GlyphInkBounds, unionGlyphInkBounds };
@@ -0,0 +1,2 @@
1
+ import { n as unionGlyphInkBounds, t as GlyphInkBounds } from "./glyph-bounds-BV_Z40KS.js";
2
+ export { GlyphInkBounds, unionGlyphInkBounds };
@@ -0,0 +1,11 @@
1
+ //#region src/glyph-bounds.ts
2
+ function unionGlyphInkBounds(a, b) {
3
+ return {
4
+ xMin: Math.min(a.xMin, b.xMin),
5
+ yMin: Math.min(a.yMin, b.yMin),
6
+ xMax: Math.max(a.xMax, b.xMax),
7
+ yMax: Math.max(a.yMax, b.yMax)
8
+ };
9
+ }
10
+ //#endregion
11
+ export { unionGlyphInkBounds };
@@ -1,12 +1,12 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_sfnt = require("./sfnt.cjs");
3
- //#region src/math-hmtx.ts
3
+ //#region src/hmtx-table.ts
4
4
  function parseHmtx(font) {
5
5
  const hheaBytes = require_sfnt.sfntTableBytes(font, "hhea");
6
6
  const hmtxBytes = require_sfnt.sfntTableBytes(font, "hmtx");
7
- if (hheaBytes === void 0 || hmtxBytes === void 0) throw new Error("math font has no hhea/hmtx table");
7
+ if (hheaBytes === void 0 || hmtxBytes === void 0) throw new Error("font has no hhea/hmtx table");
8
8
  const numberOfHMetrics = require_sfnt.u16(hheaBytes, 34);
9
- if (numberOfHMetrics === 0) throw new Error("math font hhea numberOfHMetrics is zero");
9
+ if (numberOfHMetrics === 0) throw new Error("font hhea numberOfHMetrics is zero");
10
10
  const lastWidth = require_sfnt.u16(hmtxBytes, (numberOfHMetrics - 1) * 4);
11
11
  return { advanceWidth(glyphId) {
12
12
  if (glyphId < numberOfHMetrics) return require_sfnt.u16(hmtxBytes, glyphId * 4);
@@ -1,5 +1,5 @@
1
- import { SfntFont } from "./sfnt.js";
2
- //#region src/math-hmtx.d.ts
1
+ import { t as SfntFont } from "./sfnt-V08bb5ut.cjs";
2
+ //#region src/hmtx-table.d.ts
3
3
  interface HmtxTable {
4
4
  advanceWidth(glyphId: number): number;
5
5
  }
@@ -1,5 +1,5 @@
1
- import { SfntFont } from "./sfnt.cjs";
2
- //#region src/math-hmtx.d.ts
1
+ import { t as SfntFont } from "./sfnt-V08bb5ut.js";
2
+ //#region src/hmtx-table.d.ts
3
3
  interface HmtxTable {
4
4
  advanceWidth(glyphId: number): number;
5
5
  }
@@ -1,11 +1,11 @@
1
1
  import { sfntTableBytes, u16 } from "./sfnt.js";
2
- //#region src/math-hmtx.ts
2
+ //#region src/hmtx-table.ts
3
3
  function parseHmtx(font) {
4
4
  const hheaBytes = sfntTableBytes(font, "hhea");
5
5
  const hmtxBytes = sfntTableBytes(font, "hmtx");
6
- if (hheaBytes === void 0 || hmtxBytes === void 0) throw new Error("math font has no hhea/hmtx table");
6
+ if (hheaBytes === void 0 || hmtxBytes === void 0) throw new Error("font has no hhea/hmtx table");
7
7
  const numberOfHMetrics = u16(hheaBytes, 34);
8
- if (numberOfHMetrics === 0) throw new Error("math font hhea numberOfHMetrics is zero");
8
+ if (numberOfHMetrics === 0) throw new Error("font hhea numberOfHMetrics is zero");
9
9
  const lastWidth = u16(hmtxBytes, (numberOfHMetrics - 1) * 4);
10
10
  return { advanceWidth(glyphId) {
11
11
  if (glyphId < numberOfHMetrics) return u16(hmtxBytes, glyphId * 4);
@@ -0,0 +1,432 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/image/jbig2-arith.ts
3
+ const QE_STATES = [
4
+ [
5
+ 22017,
6
+ 1,
7
+ 1,
8
+ 1
9
+ ],
10
+ [
11
+ 13313,
12
+ 2,
13
+ 6,
14
+ 0
15
+ ],
16
+ [
17
+ 6145,
18
+ 3,
19
+ 9,
20
+ 0
21
+ ],
22
+ [
23
+ 2753,
24
+ 4,
25
+ 12,
26
+ 0
27
+ ],
28
+ [
29
+ 1313,
30
+ 5,
31
+ 29,
32
+ 0
33
+ ],
34
+ [
35
+ 545,
36
+ 38,
37
+ 33,
38
+ 0
39
+ ],
40
+ [
41
+ 22017,
42
+ 7,
43
+ 6,
44
+ 1
45
+ ],
46
+ [
47
+ 21505,
48
+ 8,
49
+ 14,
50
+ 0
51
+ ],
52
+ [
53
+ 18433,
54
+ 9,
55
+ 14,
56
+ 0
57
+ ],
58
+ [
59
+ 14337,
60
+ 10,
61
+ 14,
62
+ 0
63
+ ],
64
+ [
65
+ 12289,
66
+ 11,
67
+ 17,
68
+ 0
69
+ ],
70
+ [
71
+ 9217,
72
+ 12,
73
+ 18,
74
+ 0
75
+ ],
76
+ [
77
+ 7169,
78
+ 13,
79
+ 20,
80
+ 0
81
+ ],
82
+ [
83
+ 5633,
84
+ 29,
85
+ 21,
86
+ 0
87
+ ],
88
+ [
89
+ 22017,
90
+ 15,
91
+ 14,
92
+ 1
93
+ ],
94
+ [
95
+ 21505,
96
+ 16,
97
+ 14,
98
+ 0
99
+ ],
100
+ [
101
+ 20737,
102
+ 17,
103
+ 15,
104
+ 0
105
+ ],
106
+ [
107
+ 18433,
108
+ 18,
109
+ 16,
110
+ 0
111
+ ],
112
+ [
113
+ 14337,
114
+ 19,
115
+ 17,
116
+ 0
117
+ ],
118
+ [
119
+ 13313,
120
+ 20,
121
+ 18,
122
+ 0
123
+ ],
124
+ [
125
+ 12289,
126
+ 21,
127
+ 19,
128
+ 0
129
+ ],
130
+ [
131
+ 10241,
132
+ 22,
133
+ 19,
134
+ 0
135
+ ],
136
+ [
137
+ 9217,
138
+ 23,
139
+ 20,
140
+ 0
141
+ ],
142
+ [
143
+ 8705,
144
+ 24,
145
+ 21,
146
+ 0
147
+ ],
148
+ [
149
+ 7169,
150
+ 25,
151
+ 22,
152
+ 0
153
+ ],
154
+ [
155
+ 6145,
156
+ 26,
157
+ 23,
158
+ 0
159
+ ],
160
+ [
161
+ 5633,
162
+ 27,
163
+ 24,
164
+ 0
165
+ ],
166
+ [
167
+ 5121,
168
+ 28,
169
+ 25,
170
+ 0
171
+ ],
172
+ [
173
+ 4609,
174
+ 29,
175
+ 26,
176
+ 0
177
+ ],
178
+ [
179
+ 4353,
180
+ 30,
181
+ 27,
182
+ 0
183
+ ],
184
+ [
185
+ 2753,
186
+ 31,
187
+ 28,
188
+ 0
189
+ ],
190
+ [
191
+ 2497,
192
+ 32,
193
+ 29,
194
+ 0
195
+ ],
196
+ [
197
+ 2209,
198
+ 33,
199
+ 30,
200
+ 0
201
+ ],
202
+ [
203
+ 1313,
204
+ 34,
205
+ 31,
206
+ 0
207
+ ],
208
+ [
209
+ 1089,
210
+ 35,
211
+ 32,
212
+ 0
213
+ ],
214
+ [
215
+ 673,
216
+ 36,
217
+ 33,
218
+ 0
219
+ ],
220
+ [
221
+ 545,
222
+ 37,
223
+ 34,
224
+ 0
225
+ ],
226
+ [
227
+ 321,
228
+ 38,
229
+ 35,
230
+ 0
231
+ ],
232
+ [
233
+ 273,
234
+ 39,
235
+ 36,
236
+ 0
237
+ ],
238
+ [
239
+ 133,
240
+ 40,
241
+ 37,
242
+ 0
243
+ ],
244
+ [
245
+ 73,
246
+ 41,
247
+ 38,
248
+ 0
249
+ ],
250
+ [
251
+ 37,
252
+ 42,
253
+ 39,
254
+ 0
255
+ ],
256
+ [
257
+ 21,
258
+ 43,
259
+ 40,
260
+ 0
261
+ ],
262
+ [
263
+ 9,
264
+ 44,
265
+ 41,
266
+ 0
267
+ ],
268
+ [
269
+ 5,
270
+ 45,
271
+ 42,
272
+ 0
273
+ ],
274
+ [
275
+ 1,
276
+ 45,
277
+ 43,
278
+ 0
279
+ ],
280
+ [
281
+ 22017,
282
+ 46,
283
+ 46,
284
+ 0
285
+ ]
286
+ ];
287
+ const QE_VALUE = Uint16Array.from(QE_STATES, (row) => row[0]);
288
+ const QE_NMPS = Uint8Array.from(QE_STATES, (row) => row[1]);
289
+ const QE_NLPS = Uint8Array.from(QE_STATES, (row) => row[2]);
290
+ const QE_SWITCH = Uint8Array.from(QE_STATES, (row) => row[3]);
291
+ function createArithContexts(contextBits) {
292
+ return new Uint8Array(1 << contextBits);
293
+ }
294
+ const A_INITIAL = 32768;
295
+ const C_INITIAL_SHIFT = 16;
296
+ const INITDEC_C_SHIFT = 7;
297
+ const PAST_END_BYTE = 255;
298
+ var MqDecoder = class {
299
+ data;
300
+ start;
301
+ end;
302
+ bp;
303
+ c = 0;
304
+ a = 0;
305
+ ct = 0;
306
+ constructor(data, start = 0, end = data.length) {
307
+ this.data = data;
308
+ this.start = start;
309
+ this.end = end;
310
+ this.bp = start;
311
+ this.c = this.byteAt(this.bp) << C_INITIAL_SHIFT >>> 0;
312
+ this.byteIn();
313
+ this.c = this.c << INITDEC_C_SHIFT >>> 0;
314
+ this.ct -= INITDEC_C_SHIFT;
315
+ this.a = A_INITIAL;
316
+ }
317
+ byteAt(index) {
318
+ return index >= this.start && index < this.end ? this.data[index] ?? PAST_END_BYTE : PAST_END_BYTE;
319
+ }
320
+ byteIn() {
321
+ if (this.byteAt(this.bp) === 255) {
322
+ if (this.byteAt(this.bp + 1) > 143) {
323
+ this.c = this.c + 65280 >>> 0;
324
+ this.ct = 8;
325
+ return;
326
+ }
327
+ this.bp++;
328
+ this.c = this.c + (this.byteAt(this.bp) << 9) >>> 0;
329
+ this.ct = 7;
330
+ return;
331
+ }
332
+ this.bp++;
333
+ this.c = this.c + (this.byteAt(this.bp) << 8) >>> 0;
334
+ this.ct = 8;
335
+ }
336
+ renormalise() {
337
+ do {
338
+ if (this.ct === 0) this.byteIn();
339
+ this.a = this.a << 1 & 65535;
340
+ this.c = this.c << 1 >>> 0;
341
+ this.ct--;
342
+ } while ((this.a & A_INITIAL) === 0);
343
+ }
344
+ decode(contexts, contextIndex) {
345
+ const state = contexts[contextIndex] ?? 0;
346
+ let index = state >> 1;
347
+ let mps = state & 1;
348
+ const qe = QE_VALUE[index] ?? 0;
349
+ this.a -= qe;
350
+ let decision;
351
+ if (this.c >>> 16 < qe) {
352
+ if (this.a < qe) {
353
+ decision = mps;
354
+ index = QE_NMPS[index] ?? 0;
355
+ } else {
356
+ decision = 1 - mps;
357
+ if (QE_SWITCH[index] === 1) mps = 1 - mps;
358
+ index = QE_NLPS[index] ?? 0;
359
+ }
360
+ this.a = qe;
361
+ } else {
362
+ this.c = this.c - (qe << 16) >>> 0;
363
+ if ((this.a & A_INITIAL) !== 0) return mps;
364
+ if (this.a < qe) {
365
+ decision = 1 - mps;
366
+ if (QE_SWITCH[index] === 1) mps = 1 - mps;
367
+ index = QE_NLPS[index] ?? 0;
368
+ } else {
369
+ decision = mps;
370
+ index = QE_NMPS[index] ?? 0;
371
+ }
372
+ }
373
+ this.renormalise();
374
+ contexts[contextIndex] = index << 1 | mps;
375
+ return decision;
376
+ }
377
+ };
378
+ const INTEGER_CONTEXT_BITS = 9;
379
+ function createIntegerContexts() {
380
+ return createArithContexts(INTEGER_CONTEXT_BITS);
381
+ }
382
+ const INTEGER_RANGES = [
383
+ [2, 0],
384
+ [4, 4],
385
+ [6, 20],
386
+ [8, 84],
387
+ [12, 340],
388
+ [32, 4436]
389
+ ];
390
+ function decodeInteger(mq, contexts) {
391
+ let prev = 1;
392
+ const nextBit = () => {
393
+ const bit = mq.decode(contexts, prev);
394
+ prev = prev < 256 ? prev << 1 | bit : (prev << 1 | bit) & 511 | 256;
395
+ return bit;
396
+ };
397
+ const readBits = (count) => {
398
+ let value = 0;
399
+ for (let i = 0; i < count; i++) value = value * 2 + nextBit();
400
+ return value;
401
+ };
402
+ const sign = nextBit();
403
+ let magnitude = 0;
404
+ let matched = false;
405
+ for (let i = 0; i < INTEGER_RANGES.length - 1; i++) if (nextBit() === 0) {
406
+ const [bits, offset] = INTEGER_RANGES[i] ?? [0, 0];
407
+ magnitude = readBits(bits) + offset;
408
+ matched = true;
409
+ break;
410
+ }
411
+ if (!matched) {
412
+ const [bits, offset] = INTEGER_RANGES[INTEGER_RANGES.length - 1] ?? [0, 0];
413
+ magnitude = readBits(bits) + offset;
414
+ }
415
+ if (sign === 1) return magnitude === 0 ? void 0 : -magnitude;
416
+ return magnitude;
417
+ }
418
+ function createSymbolIdContexts(codeLength) {
419
+ return createArithContexts(codeLength + 1);
420
+ }
421
+ function decodeSymbolId(mq, contexts, codeLength) {
422
+ let prev = 1;
423
+ for (let i = 0; i < codeLength; i++) prev = prev << 1 | mq.decode(contexts, prev);
424
+ return prev - (1 << codeLength);
425
+ }
426
+ //#endregion
427
+ exports.MqDecoder = MqDecoder;
428
+ exports.createArithContexts = createArithContexts;
429
+ exports.createIntegerContexts = createIntegerContexts;
430
+ exports.createSymbolIdContexts = createSymbolIdContexts;
431
+ exports.decodeInteger = decodeInteger;
432
+ exports.decodeSymbolId = decodeSymbolId;