pdf-parser.js 3.0.8 → 4.5.1

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 (240) hide show
  1. package/README.md +105 -54
  2. package/dist/{afm-widths-Dxucrg7D.js → afm-widths-BTu0IDp2.cjs} +1517 -4
  3. package/dist/{afm-widths-DyDq56Ph.d.cts → afm-widths-CneRyu5l.d.cts} +1 -1
  4. package/dist/{afm-widths-DyDq56Ph.d.ts → afm-widths-CneRyu5l.d.ts} +1 -1
  5. package/dist/{afm-widths-BoeTOK2r.cjs → afm-widths-De_QMWgC.js} +1416 -51
  6. package/dist/afm-widths.cjs +1 -1
  7. package/dist/afm-widths.d.cts +1 -1
  8. package/dist/afm-widths.d.ts +1 -1
  9. package/dist/afm-widths.js +1 -1
  10. package/dist/annotations.cjs +104 -0
  11. package/dist/annotations.d.cts +9 -0
  12. package/dist/annotations.d.ts +9 -0
  13. package/dist/annotations.js +103 -0
  14. package/dist/attachments.cjs +65 -0
  15. package/dist/attachments.d.cts +8 -0
  16. package/dist/attachments.d.ts +8 -0
  17. package/dist/attachments.js +64 -0
  18. package/dist/builtin-encoding.cjs +221 -0
  19. package/dist/builtin-encoding.d.cts +8 -0
  20. package/dist/builtin-encoding.d.ts +8 -0
  21. package/dist/builtin-encoding.js +220 -0
  22. package/dist/bytes/flate.cjs +1 -1
  23. package/dist/bytes/flate.js +1 -1
  24. package/dist/cff.cjs +14 -0
  25. package/dist/cff.d.cts +4 -1
  26. package/dist/cff.d.ts +4 -1
  27. package/dist/cff.js +12 -1
  28. package/dist/cmap-table.cjs +76 -13
  29. package/dist/cmap-table.d.cts +9 -1
  30. package/dist/cmap-table.d.ts +9 -1
  31. package/dist/cmap-table.js +77 -15
  32. package/dist/codec.cjs +1 -1
  33. package/dist/codec.d.cts +134 -0
  34. package/dist/codec.d.ts +134 -0
  35. package/dist/codec.js +1 -1
  36. package/dist/content-read.cjs +1 -1
  37. package/dist/content-read.d.cts +3 -3
  38. package/dist/content-read.d.ts +3 -3
  39. package/dist/content-read.js +1 -1
  40. package/dist/content-write.cjs +32 -10
  41. package/dist/content-write.d.cts +12 -5
  42. package/dist/content-write.d.ts +12 -5
  43. package/dist/content-write.js +32 -10
  44. package/dist/crypto/random.cjs +9 -0
  45. package/dist/crypto/random.d.cts +4 -0
  46. package/dist/crypto/random.d.ts +4 -0
  47. package/dist/crypto/random.js +8 -0
  48. package/dist/diagnostics.d.cts +1 -1
  49. package/dist/diagnostics.d.ts +1 -1
  50. package/dist/document.cjs +12 -3
  51. package/dist/document.d.cts +3 -1
  52. package/dist/document.d.ts +3 -1
  53. package/dist/document.js +12 -3
  54. package/dist/{embedded-font-fREdbxnr.d.ts → embedded-font-B4p9a3O3.d.ts} +3 -1
  55. package/dist/{embedded-font-BU6Jgcof.d.cts → embedded-font-oc65VGlr.d.cts} +3 -1
  56. package/dist/embedded-font-write.cjs +1 -1
  57. package/dist/embedded-font-write.d.cts +3 -3
  58. package/dist/embedded-font-write.d.ts +3 -3
  59. package/dist/embedded-font-write.js +1 -1
  60. package/dist/embedded-font.cjs +46 -15
  61. package/dist/embedded-font.d.cts +1 -1
  62. package/dist/embedded-font.d.ts +1 -1
  63. package/dist/embedded-font.js +46 -15
  64. package/dist/encoding.cjs +10 -1
  65. package/dist/encoding.d.cts +10 -1
  66. package/dist/encoding.d.ts +10 -1
  67. package/dist/encoding.js +2 -2
  68. package/dist/encrypt-write.cjs +234 -0
  69. package/dist/encrypt-write.d.cts +31 -0
  70. package/dist/encrypt-write.d.ts +31 -0
  71. package/dist/encrypt-write.js +231 -0
  72. package/dist/encrypt.cjs +51 -21
  73. package/dist/encrypt.d.cts +19 -3
  74. package/dist/encrypt.d.ts +19 -3
  75. package/dist/encrypt.js +36 -22
  76. package/dist/filters.cjs +18 -14
  77. package/dist/filters.d.cts +1 -1
  78. package/dist/filters.d.ts +1 -1
  79. package/dist/filters.js +18 -14
  80. package/dist/font-read.cjs +68 -13
  81. package/dist/font-read.d.cts +1 -1
  82. package/dist/font-read.d.ts +1 -1
  83. package/dist/font-read.js +69 -14
  84. package/dist/font-registry.cjs +1 -1
  85. package/dist/font-registry.d.cts +4 -4
  86. package/dist/font-registry.d.ts +4 -4
  87. package/dist/font-registry.js +1 -1
  88. package/dist/font-substitutes.d.cts +1 -1
  89. package/dist/font-substitutes.d.ts +1 -1
  90. package/dist/font-tables.cjs +31 -0
  91. package/dist/font-tables.d.cts +3 -1
  92. package/dist/font-tables.d.ts +3 -1
  93. package/dist/font-tables.js +31 -2
  94. package/dist/fonts.d.cts +2 -2
  95. package/dist/fonts.d.ts +2 -2
  96. package/dist/form.cjs +138 -0
  97. package/dist/form.d.cts +9 -0
  98. package/dist/form.d.ts +9 -0
  99. package/dist/form.js +137 -0
  100. package/dist/gsub-table-BRTQ8EUW.d.ts +10 -0
  101. package/dist/gsub-table-URczLd85.d.cts +10 -0
  102. package/dist/gsub-table.cjs +225 -0
  103. package/dist/gsub-table.d.cts +2 -0
  104. package/dist/gsub-table.d.ts +2 -0
  105. package/dist/gsub-table.js +224 -0
  106. package/dist/image/ccitt-encode.cjs +119 -0
  107. package/dist/image/ccitt-encode.d.cts +9 -0
  108. package/dist/image/ccitt-encode.d.ts +9 -0
  109. package/dist/image/ccitt-encode.js +118 -0
  110. package/dist/image/ccitt.cjs +3 -0
  111. package/dist/image/ccitt.d.cts +4 -1
  112. package/dist/image/ccitt.d.ts +4 -1
  113. package/dist/image/ccitt.js +1 -1
  114. package/dist/image/jbig2-bitmap.d.cts +1 -1
  115. package/dist/image/jbig2-bitmap.d.ts +1 -1
  116. package/dist/image/jbig2.cjs +3 -1
  117. package/dist/image/jbig2.js +3 -1
  118. package/dist/image/jp2-boxes.d.cts +1 -1
  119. package/dist/image/jp2-boxes.d.ts +1 -1
  120. package/dist/image/jpeg2000-codestream.d.cts +3 -3
  121. package/dist/image/jpeg2000-codestream.d.ts +3 -3
  122. package/dist/image/jpeg2000-t1.d.cts +1 -1
  123. package/dist/image/jpeg2000-t1.d.ts +1 -1
  124. package/dist/image/jpeg2000.cjs +1 -0
  125. package/dist/image/jpeg2000.d.cts +3 -0
  126. package/dist/image/jpeg2000.d.ts +3 -0
  127. package/dist/image/jpeg2000.js +1 -0
  128. package/dist/image/png-decode.cjs +1 -1
  129. package/dist/image/png-decode.js +1 -1
  130. package/dist/image/png-filter.d.cts +1 -1
  131. package/dist/image/png-filter.d.ts +1 -1
  132. package/dist/images-read.cjs +18 -12
  133. package/dist/images-read.d.cts +2 -2
  134. package/dist/images-read.d.ts +2 -2
  135. package/dist/images-read.js +15 -9
  136. package/dist/index.cjs +17 -4
  137. package/dist/index.d.cts +7 -6
  138. package/dist/index.d.ts +7 -6
  139. package/dist/index.js +6 -5
  140. package/dist/interpret.cjs +178 -56
  141. package/dist/interpret.d.cts +27 -12
  142. package/dist/interpret.d.ts +27 -12
  143. package/dist/interpret.js +178 -56
  144. package/dist/layout.cjs +149 -2
  145. package/dist/layout.d.cts +394 -1
  146. package/dist/layout.d.ts +394 -1
  147. package/dist/layout.js +140 -4
  148. package/dist/lexer.d.cts +9 -9
  149. package/dist/lexer.d.ts +9 -9
  150. package/dist/math-content-write.cjs +1 -1
  151. package/dist/math-content-write.js +1 -1
  152. package/dist/math-font-write.cjs +1 -1
  153. package/dist/math-font-write.d.cts +1 -1
  154. package/dist/math-font-write.d.ts +1 -1
  155. package/dist/math-font-write.js +1 -1
  156. package/dist/math-font.cjs +2 -2
  157. package/dist/math-font.d.cts +1 -1
  158. package/dist/math-font.d.ts +1 -1
  159. package/dist/math-font.js +2 -2
  160. package/dist/{math-stretch-a_rHNRvc.d.ts → math-stretch-BbC2o4Br.d.ts} +1 -1
  161. package/dist/{math-stretch-E26z6byT.d.cts → math-stretch-C2JanDAz.d.cts} +1 -1
  162. package/dist/math-stretch.d.cts +1 -1
  163. package/dist/math-stretch.d.ts +1 -1
  164. package/dist/measure.cjs +1 -1
  165. package/dist/measure.d.cts +1 -1
  166. package/dist/measure.d.ts +1 -1
  167. package/dist/measure.js +1 -1
  168. package/dist/names.cjs +41 -0
  169. package/dist/names.d.cts +11 -0
  170. package/dist/names.d.ts +11 -0
  171. package/dist/names.js +40 -0
  172. package/dist/navigation.cjs +210 -0
  173. package/dist/navigation.d.cts +18 -0
  174. package/dist/navigation.d.ts +18 -0
  175. package/dist/navigation.js +207 -0
  176. package/dist/notes-annotation-author.cjs +5 -0
  177. package/dist/notes-annotation-author.d.cts +4 -0
  178. package/dist/notes-annotation-author.d.ts +4 -0
  179. package/dist/notes-annotation-author.js +4 -0
  180. package/dist/objects-B7HdMeWS.d.cts +59 -0
  181. package/dist/objects-B7HdMeWS.d.ts +59 -0
  182. package/dist/objects.d.cts +1 -58
  183. package/dist/objects.d.ts +1 -58
  184. package/dist/optional-content.cjs +63 -0
  185. package/dist/optional-content.d.cts +12 -0
  186. package/dist/optional-content.d.ts +12 -0
  187. package/dist/optional-content.js +62 -0
  188. package/dist/parse.cjs +1 -1
  189. package/dist/parse.d.cts +2 -2
  190. package/dist/parse.d.ts +2 -2
  191. package/dist/parse.js +1 -1
  192. package/dist/pdf-text.cjs +21 -0
  193. package/dist/pdf-text.d.cts +5 -0
  194. package/dist/pdf-text.d.ts +5 -0
  195. package/dist/pdf-text.js +19 -0
  196. package/dist/predictors.d.cts +1 -1
  197. package/dist/predictors.d.ts +1 -1
  198. package/dist/read.cjs +287 -72
  199. package/dist/read.d.cts +2 -4
  200. package/dist/read.d.ts +2 -4
  201. package/dist/read.js +284 -67
  202. package/dist/serialize.cjs +5 -1
  203. package/dist/serialize.d.cts +3 -2
  204. package/dist/serialize.d.ts +3 -2
  205. package/dist/serialize.js +5 -2
  206. package/dist/sfnt-subset.cjs +10 -3
  207. package/dist/sfnt-subset.d.cts +1 -1
  208. package/dist/sfnt-subset.d.ts +1 -1
  209. package/dist/sfnt-subset.js +10 -3
  210. package/dist/structure.cjs +184 -0
  211. package/dist/structure.d.cts +12 -0
  212. package/dist/structure.d.ts +12 -0
  213. package/dist/structure.js +183 -0
  214. package/dist/tounicode.cjs +8 -3
  215. package/dist/tounicode.d.cts +2 -2
  216. package/dist/tounicode.d.ts +2 -2
  217. package/dist/tounicode.js +8 -3
  218. package/dist/util/base64.cjs +4 -4
  219. package/dist/util/base64.js +4 -4
  220. package/dist/winansi.cjs +1 -1
  221. package/dist/winansi.d.cts +1 -1
  222. package/dist/winansi.d.ts +1 -1
  223. package/dist/winansi.js +1 -1
  224. package/dist/write.cjs +464 -21
  225. package/dist/write.d.cts +4 -3
  226. package/dist/write.d.ts +4 -3
  227. package/dist/write.js +464 -20
  228. package/dist/xmp.cjs +46 -0
  229. package/dist/xmp.d.cts +14 -0
  230. package/dist/xmp.d.ts +14 -0
  231. package/dist/xmp.js +45 -0
  232. package/dist/xref.cjs +2 -2
  233. package/dist/xref.d.cts +3 -3
  234. package/dist/xref.d.ts +3 -3
  235. package/dist/xref.js +2 -2
  236. package/package.json +46 -31
  237. package/dist/image/png-encode.cjs +0 -64
  238. package/dist/image/png-encode.d.cts +0 -8
  239. package/dist/image/png-encode.d.ts +0 -8
  240. package/dist/image/png-encode.js +0 -63
@@ -1,5 +1,5 @@
1
1
  import { PdfDiagnosticSink } from "./diagnostics.js";
2
- import { PdfDict } from "./objects.js";
2
+ import { n as PdfDict } from "./objects-B7HdMeWS.js";
3
3
  import { FontMetricsPort, PdfObjectResolver } from "./interpret.js";
4
4
  //#region src/font-read.d.ts
5
5
  interface PdfFont {
package/dist/font-read.js CHANGED
@@ -1,10 +1,12 @@
1
- import { a as winAnsiGlyphName, i as glyphNameToUnicode, n as widthOfCode } from "./afm-widths-Dxucrg7D.js";
2
- import { parseToUnicodeCMap } from "./cmap.js";
3
- import { asArray, asName, asNumber, dictGet } from "./objects.js";
1
+ import { c as glyphNameToUnicode, f as symbolGlyphName, m as zapfDingbatsGlyphName, n as widthOfCode, p as winAnsiGlyphName, u as namedEncodingGlyphName } from "./afm-widths-De_QMWgC.js";
2
+ import { asArray, asName, asNumber, dictGet, isName } from "./objects.js";
4
3
  import { decodeStream } from "./filters.js";
4
+ import { readFontProgramEncoding } from "./builtin-encoding.js";
5
+ import { parseToUnicodeCMap } from "./cmap.js";
5
6
  import { resolveStandardFont } from "./fonts.js";
6
7
  import { styleFromBaseFontName } from "./font-style.js";
7
8
  //#region src/font-read.ts
9
+ const SYMBOLIC_FLAG_BIT = 4;
8
10
  const ITALIC_FLAG_BIT = 64;
9
11
  const FORCE_BOLD_FLAG_BIT = 1 << 18;
10
12
  const REPLACEMENT_CHARACTER = "�";
@@ -13,14 +15,34 @@ function styleFlagsFromDescriptor(descriptor) {
13
15
  return {
14
16
  forceBold: flags !== void 0 ? (flags & FORCE_BOLD_FLAG_BIT) !== 0 : void 0,
15
17
  italicFlag: flags !== void 0 ? (flags & ITALIC_FLAG_BIT) !== 0 : void 0,
16
- italicAngle: descriptor !== void 0 ? asNumber(dictGet(descriptor, "ItalicAngle")) : void 0
18
+ italicAngle: descriptor !== void 0 ? asNumber(dictGet(descriptor, "ItalicAngle")) : void 0,
19
+ symbolic: flags !== void 0 ? (flags & SYMBOLIC_FLAG_BIT) !== 0 : void 0
17
20
  };
18
21
  }
19
- function glyphNameToUnicodeWithUniFallback(name) {
20
- const direct = glyphNameToUnicode(name);
21
- if (direct !== void 0) return direct;
22
- const uniMatch = /^uni([0-9A-Fa-f]{4,6})$/.exec(name);
23
- return uniMatch?.[1] !== void 0 ? Number.parseInt(uniMatch[1], 16) : void 0;
22
+ function builtinSymbolGlyphNameLookup(baseFamily) {
23
+ if (baseFamily === "Symbol") return symbolGlyphName;
24
+ if (baseFamily === "ZapfDingbats") return zapfDingbatsGlyphName;
25
+ }
26
+ function readFontProgram(descriptor, context) {
27
+ if (descriptor === void 0) return;
28
+ for (const key of [
29
+ "FontFile2",
30
+ "FontFile3",
31
+ "FontFile"
32
+ ]) {
33
+ const stream = context.resolver.resolve(dictGet(descriptor, key));
34
+ if (stream?.kind !== "stream") continue;
35
+ const decoded = decodeStream(stream.raw, stream.dict, context.sink);
36
+ const encoding = readFontProgramEncoding(decoded.bytes);
37
+ if (encoding !== void 0) return encoding;
38
+ }
39
+ }
40
+ function lazyFontProgram(descriptor, context) {
41
+ let read;
42
+ return () => {
43
+ read ??= { encoding: readFontProgram(descriptor, context) };
44
+ return read.encoding;
45
+ };
24
46
  }
25
47
  function readDifferencesMap(differences) {
26
48
  const map = /* @__PURE__ */ new Map();
@@ -42,7 +64,10 @@ function readToUnicodeCMap(fontDict, context) {
42
64
  function buildSimpleFont(fontDict, context) {
43
65
  const baseFont = asName(dictGet(fontDict, "BaseFont")) ?? "Helvetica";
44
66
  const descriptor = context.resolver.resolveDict(dictGet(fontDict, "FontDescriptor"));
45
- const { baseFamily, bold, italic } = styleFromBaseFontName(baseFont, styleFlagsFromDescriptor(descriptor));
67
+ const styleFlags = styleFlagsFromDescriptor(descriptor);
68
+ const { baseFamily, bold, italic } = styleFromBaseFontName(baseFont, styleFlags);
69
+ const symbolic = styleFlags.symbolic ?? false;
70
+ const builtinGlyphName = builtinSymbolGlyphNameLookup(baseFamily);
46
71
  const widthsArr = asArray(dictGet(fontDict, "Widths"));
47
72
  const firstChar = asNumber(dictGet(fontDict, "FirstChar")) ?? 0;
48
73
  const missingWidth = (descriptor !== void 0 ? asNumber(dictGet(descriptor, "MissingWidth")) : void 0) ?? 0;
@@ -61,12 +86,36 @@ function buildSimpleFont(fontDict, context) {
61
86
  const encodingObj = dictGet(fontDict, "Encoding");
62
87
  const encodingDict = context.resolver.resolveDict(encodingObj);
63
88
  const baseEncodingName = asName(encodingDict !== void 0 ? dictGet(encodingDict, "BaseEncoding") : encodingObj);
64
- if (baseEncodingName !== void 0 && baseEncodingName !== "WinAnsiEncoding") context.sink({
89
+ const namedBaseGlyphName = baseEncodingName !== void 0 ? namedEncodingGlyphName(baseEncodingName) : void 0;
90
+ if (baseEncodingName !== void 0 && namedBaseGlyphName === void 0) context.sink({
65
91
  code: "char/encoding-approximated",
66
92
  severity: "info",
67
93
  message: `base encoding "${baseEncodingName}" has no dedicated table here and is approximated as WinAnsiEncoding`
68
94
  });
69
95
  const differencesMap = readDifferencesMap(encodingDict !== void 0 ? asArray(dictGet(encodingDict, "Differences")) : void 0);
96
+ const programEncoding = lazyFontProgram(descriptor, context);
97
+ const symbolEncoded = symbolic || builtinGlyphName !== void 0;
98
+ const byGlyphName = (source) => (code) => {
99
+ const name = source(code);
100
+ return name === void 0 ? void 0 : glyphNameToUnicode(name);
101
+ };
102
+ const fromProgram = (code) => programEncoding()?.codeToUnicode(code);
103
+ const namedBase = namedBaseGlyphName === void 0 ? void 0 : byGlyphName(namedBaseGlyphName);
104
+ const resolvers = [byGlyphName((code) => differencesMap.get(code)), ...symbolEncoded ? [
105
+ fromProgram,
106
+ builtinGlyphName === void 0 ? void 0 : byGlyphName(builtinGlyphName),
107
+ namedBase
108
+ ] : [
109
+ namedBase,
110
+ fromProgram,
111
+ byGlyphName(winAnsiGlyphName)
112
+ ]].filter((resolver) => resolver !== void 0);
113
+ const unicodeForCode = (code) => {
114
+ for (const resolve of resolvers) {
115
+ const unicode = resolve(code);
116
+ if (unicode !== void 0) return unicode;
117
+ }
118
+ };
70
119
  const decodeToUnicode = (codes) => {
71
120
  let out = "";
72
121
  let unmapped = 0;
@@ -76,10 +125,9 @@ function buildSimpleFont(fontDict, context) {
76
125
  out += viaToUnicode;
77
126
  continue;
78
127
  }
79
- const name = differencesMap.get(code) ?? winAnsiGlyphName(code);
80
- const unicode = name !== void 0 ? glyphNameToUnicodeWithUniFallback(name) : void 0;
128
+ const unicode = unicodeForCode(code);
81
129
  if (unicode !== void 0) {
82
- out += String.fromCharCode(unicode);
130
+ out += String.fromCodePoint(unicode);
83
131
  continue;
84
132
  }
85
133
  unmapped++;
@@ -138,6 +186,8 @@ function buildCompositeFont(fontDict, context) {
138
186
  const widthMap = readCidWidths(descendantDict !== void 0 ? asArray(dictGet(descendantDict, "W")) : void 0);
139
187
  const widthOf = (cid) => widthMap.get(cid) ?? dw;
140
188
  const toUnicode = readToUnicodeCMap(fontDict, context);
189
+ const cidToGidMap = descendantDict !== void 0 ? dictGet(descendantDict, "CIDToGIDMap") : void 0;
190
+ const programEncoding = isName(dictGet(fontDict, "Encoding"), "Identity-H") && (cidToGidMap === void 0 || isName(cidToGidMap, "Identity")) ? lazyFontProgram(descriptor, context) : void 0;
141
191
  const decodeToUnicode = (codes) => {
142
192
  let out = "";
143
193
  let glyphCount = 0;
@@ -150,6 +200,11 @@ function buildCompositeFont(fontDict, context) {
150
200
  out += mapped;
151
201
  continue;
152
202
  }
203
+ const fromProgram = programEncoding?.()?.glyphIdToUnicode(cid);
204
+ if (fromProgram !== void 0) {
205
+ out += String.fromCodePoint(fromProgram);
206
+ continue;
207
+ }
153
208
  unmapped++;
154
209
  out += REPLACEMENT_CHARACTER;
155
210
  }
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_sfnt = require("./sfnt.cjs");
3
2
  const require_util_base64 = require("./util/base64.cjs");
3
+ const require_sfnt = require("./sfnt.cjs");
4
4
  const require_fonts = require("./fonts.cjs");
5
5
  const require_embedded_font = require("./embedded-font.cjs");
6
6
  const require_assets_caladea_bold = require("./assets/caladea-bold.cjs");
@@ -1,12 +1,12 @@
1
- import { r as StandardFontName } from "./afm-widths-DyDq56Ph.cjs";
2
- import { t as EmbeddedFace } from "./embedded-font-BU6Jgcof.cjs";
1
+ import { r as StandardFontName } from "./afm-widths-CneRyu5l.cjs";
2
+ import { t as EmbeddedFace } from "./embedded-font-oc65VGlr.cjs";
3
3
  import { FontRegistryOptions, LayoutFont } from "document-schema.js";
4
4
  //#region src/font-registry.d.ts
5
5
  type ResolvedFace = {
6
- readonly kind: 'embedded';
6
+ readonly kind: "embedded";
7
7
  readonly face: EmbeddedFace;
8
8
  } | {
9
- readonly kind: 'standard';
9
+ readonly kind: "standard";
10
10
  readonly standardName: StandardFontName;
11
11
  readonly matched: boolean;
12
12
  };
@@ -1,12 +1,12 @@
1
- import { r as StandardFontName } from "./afm-widths-DyDq56Ph.js";
2
- import { t as EmbeddedFace } from "./embedded-font-fREdbxnr.js";
1
+ import { r as StandardFontName } from "./afm-widths-CneRyu5l.js";
2
+ import { t as EmbeddedFace } from "./embedded-font-B4p9a3O3.js";
3
3
  import { FontRegistryOptions, LayoutFont } from "document-schema.js";
4
4
  //#region src/font-registry.d.ts
5
5
  type ResolvedFace = {
6
- readonly kind: 'embedded';
6
+ readonly kind: "embedded";
7
7
  readonly face: EmbeddedFace;
8
8
  } | {
9
- readonly kind: 'standard';
9
+ readonly kind: "standard";
10
10
  readonly standardName: StandardFontName;
11
11
  readonly matched: boolean;
12
12
  };
@@ -1,5 +1,5 @@
1
- import { parseSfnt } from "./sfnt.js";
2
1
  import { base64ToBytes } from "./util/base64.js";
2
+ import { parseSfnt } from "./sfnt.js";
3
3
  import { normalizeFamilyName, resolveStandardFont } from "./fonts.js";
4
4
  import { loadEmbeddedFace } from "./embedded-font.js";
5
5
  import { CALADEA_BOLD_FONT_DEFLATED_BASE64 } from "./assets/caladea-bold.js";
@@ -1,5 +1,5 @@
1
1
  //#region src/font-substitutes.d.ts
2
- type VendoredFamily = 'carlito' | 'caladea';
2
+ type VendoredFamily = "carlito" | "caladea";
3
3
  declare function resolveVendoredSubstituteFamily(rawFamily: string): VendoredFamily | undefined;
4
4
  //#endregion
5
5
  export { VendoredFamily, resolveVendoredSubstituteFamily };
@@ -1,5 +1,5 @@
1
1
  //#region src/font-substitutes.d.ts
2
- type VendoredFamily = 'carlito' | 'caladea';
2
+ type VendoredFamily = "carlito" | "caladea";
3
3
  declare function resolveVendoredSubstituteFamily(rawFamily: string): VendoredFamily | undefined;
4
4
  //#endregion
5
5
  export { VendoredFamily, resolveVendoredSubstituteFamily };
@@ -64,6 +64,35 @@ function parsePost(font) {
64
64
  underlineThickness: require_sfnt.i16(bytes, 10)
65
65
  };
66
66
  }
67
+ const MAC_STANDARD_GLYPH_ORDER = ".notdef .null nonmarkingreturn space exclam quotedbl numbersign dollar percent ampersand quotesingle parenleft parenright asterisk plus comma hyphen period slash zero one two three four five six seven eight nine colon semicolon less equal greater question at A B C D E F G H I J K L M N O P Q R S T U V W X Y Z bracketleft backslash bracketright asciicircum underscore grave a b c d e f g h i j k l m n o p q r s t u v w x y z braceleft bar braceright asciitilde Adieresis Aring Ccedilla Eacute Ntilde Odieresis Udieresis aacute agrave acircumflex adieresis atilde aring ccedilla eacute egrave ecircumflex edieresis iacute igrave icircumflex idieresis ntilde oacute ograve ocircumflex odieresis otilde uacute ugrave ucircumflex udieresis dagger degree cent sterling section bullet paragraph germandbls registered copyright trademark acute dieresis notequal AE Oslash infinity plusminus lessequal greaterequal yen mu partialdiff summation product pi integral ordfeminine ordmasculine Omega ae oslash questiondown exclamdown logicalnot radical florin approxequal Delta guillemotleft guillemotright ellipsis nonbreakingspace Agrave Atilde Otilde OE oe endash emdash quotedblleft quotedblright quoteleft quoteright divide lozenge ydieresis Ydieresis fraction currency guilsinglleft guilsinglright fi fl daggerdbl periodcentered quotesinglbase quotedblbase perthousand Acircumflex Ecircumflex Aacute Edieresis Egrave Iacute Icircumflex Idieresis Igrave Oacute Ocircumflex apple Ograve Uacute Ucircumflex Ugrave dotlessi circumflex tilde macron breve dotaccent ring cedilla hungarumlaut ogonek caron Lslash lslash Scaron scaron Zcaron zcaron brokenbar Eth eth Yacute yacute Thorn thorn minus multiply onesuperior twosuperior threesuperior onehalf onequarter threequarters franc Gbreve gbreve Idotaccent Scedilla scedilla Cacute cacute Ccaron ccaron dcroat".split(" ");
68
+ const POST_VERSION_MAC_STANDARD_ORDER = 65536;
69
+ const POST_VERSION_CUSTOM_NAMES = 131072;
70
+ function parsePostGlyphNames(font) {
71
+ const bytes = require_sfnt.sfntTableBytes(font, "post");
72
+ if (bytes === void 0 || !require_sfnt.hasBytes(bytes, 0, POST_HEADER_SIZE)) return;
73
+ const version = require_sfnt.u32(bytes, 0);
74
+ if (version === POST_VERSION_MAC_STANDARD_ORDER) return (glyphId) => MAC_STANDARD_GLYPH_ORDER[glyphId];
75
+ if (version !== POST_VERSION_CUSTOM_NAMES) return;
76
+ if (!require_sfnt.hasBytes(bytes, POST_HEADER_SIZE, 2)) return;
77
+ const numGlyphs = require_sfnt.u16(bytes, POST_HEADER_SIZE);
78
+ const indicesOffset = 34;
79
+ if (!require_sfnt.hasBytes(bytes, indicesOffset, numGlyphs * 2)) return;
80
+ const names = [];
81
+ let cursor = indicesOffset + numGlyphs * 2;
82
+ while (require_sfnt.hasBytes(bytes, cursor, 1)) {
83
+ const length = require_sfnt.u8(bytes, cursor);
84
+ if (!require_sfnt.hasBytes(bytes, cursor + 1, length)) break;
85
+ let name = "";
86
+ for (let i = 0; i < length; i++) name += String.fromCharCode(require_sfnt.u8(bytes, cursor + 1 + i));
87
+ names.push(name);
88
+ cursor += 1 + length;
89
+ }
90
+ return (glyphId) => {
91
+ if (glyphId < 0 || glyphId >= numGlyphs) return;
92
+ const index = require_sfnt.u16(bytes, indicesOffset + glyphId * 2);
93
+ return index < MAC_STANDARD_GLYPH_ORDER.length ? MAC_STANDARD_GLYPH_ORDER[index] : names[index - MAC_STANDARD_GLYPH_ORDER.length];
94
+ };
95
+ }
67
96
  const NAME_HEADER_SIZE = 6;
68
97
  const NAME_RECORD_SIZE = 12;
69
98
  const NAME_ID_FAMILY = 1;
@@ -121,8 +150,10 @@ function parseName(font) {
121
150
  };
122
151
  }
123
152
  //#endregion
153
+ exports.MAC_STANDARD_GLYPH_ORDER = MAC_STANDARD_GLYPH_ORDER;
124
154
  exports.parseHead = parseHead;
125
155
  exports.parseMaxp = parseMaxp;
126
156
  exports.parseName = parseName;
127
157
  exports.parseOs2 = parseOs2;
128
158
  exports.parsePost = parsePost;
159
+ exports.parsePostGlyphNames = parsePostGlyphNames;
@@ -35,10 +35,12 @@ interface PostTable {
35
35
  readonly underlineThickness: number;
36
36
  }
37
37
  declare function parsePost(font: SfntFont): PostTable | undefined;
38
+ declare const MAC_STANDARD_GLYPH_ORDER: readonly string[];
39
+ declare function parsePostGlyphNames(font: SfntFont): ((glyphId: number) => string | undefined) | undefined;
38
40
  interface NameTable {
39
41
  readonly postScriptName: string | undefined;
40
42
  readonly familyName: string | undefined;
41
43
  }
42
44
  declare function parseName(font: SfntFont): NameTable | undefined;
43
45
  //#endregion
44
- export { HeadTable, MaxpTable, NameTable, Os2Table, PostTable, parseHead, parseMaxp, parseName, parseOs2, parsePost };
46
+ export { HeadTable, MAC_STANDARD_GLYPH_ORDER, MaxpTable, NameTable, Os2Table, PostTable, parseHead, parseMaxp, parseName, parseOs2, parsePost, parsePostGlyphNames };
@@ -35,10 +35,12 @@ interface PostTable {
35
35
  readonly underlineThickness: number;
36
36
  }
37
37
  declare function parsePost(font: SfntFont): PostTable | undefined;
38
+ declare const MAC_STANDARD_GLYPH_ORDER: readonly string[];
39
+ declare function parsePostGlyphNames(font: SfntFont): ((glyphId: number) => string | undefined) | undefined;
38
40
  interface NameTable {
39
41
  readonly postScriptName: string | undefined;
40
42
  readonly familyName: string | undefined;
41
43
  }
42
44
  declare function parseName(font: SfntFont): NameTable | undefined;
43
45
  //#endregion
44
- export { HeadTable, MaxpTable, NameTable, Os2Table, PostTable, parseHead, parseMaxp, parseName, parseOs2, parsePost };
46
+ export { HeadTable, MAC_STANDARD_GLYPH_ORDER, MaxpTable, NameTable, Os2Table, PostTable, parseHead, parseMaxp, parseName, parseOs2, parsePost, parsePostGlyphNames };
@@ -1,4 +1,4 @@
1
- import { hasBytes, i16, i32, sfntTableBytes, u16, u32 } from "./sfnt.js";
1
+ import { hasBytes, i16, i32, sfntTableBytes, u16, u32, u8 } from "./sfnt.js";
2
2
  //#region src/font-tables.ts
3
3
  const HEAD_TABLE_SIZE = 54;
4
4
  const HEAD_MAGIC_NUMBER = 1594834165;
@@ -63,6 +63,35 @@ function parsePost(font) {
63
63
  underlineThickness: i16(bytes, 10)
64
64
  };
65
65
  }
66
+ const MAC_STANDARD_GLYPH_ORDER = ".notdef .null nonmarkingreturn space exclam quotedbl numbersign dollar percent ampersand quotesingle parenleft parenright asterisk plus comma hyphen period slash zero one two three four five six seven eight nine colon semicolon less equal greater question at A B C D E F G H I J K L M N O P Q R S T U V W X Y Z bracketleft backslash bracketright asciicircum underscore grave a b c d e f g h i j k l m n o p q r s t u v w x y z braceleft bar braceright asciitilde Adieresis Aring Ccedilla Eacute Ntilde Odieresis Udieresis aacute agrave acircumflex adieresis atilde aring ccedilla eacute egrave ecircumflex edieresis iacute igrave icircumflex idieresis ntilde oacute ograve ocircumflex odieresis otilde uacute ugrave ucircumflex udieresis dagger degree cent sterling section bullet paragraph germandbls registered copyright trademark acute dieresis notequal AE Oslash infinity plusminus lessequal greaterequal yen mu partialdiff summation product pi integral ordfeminine ordmasculine Omega ae oslash questiondown exclamdown logicalnot radical florin approxequal Delta guillemotleft guillemotright ellipsis nonbreakingspace Agrave Atilde Otilde OE oe endash emdash quotedblleft quotedblright quoteleft quoteright divide lozenge ydieresis Ydieresis fraction currency guilsinglleft guilsinglright fi fl daggerdbl periodcentered quotesinglbase quotedblbase perthousand Acircumflex Ecircumflex Aacute Edieresis Egrave Iacute Icircumflex Idieresis Igrave Oacute Ocircumflex apple Ograve Uacute Ucircumflex Ugrave dotlessi circumflex tilde macron breve dotaccent ring cedilla hungarumlaut ogonek caron Lslash lslash Scaron scaron Zcaron zcaron brokenbar Eth eth Yacute yacute Thorn thorn minus multiply onesuperior twosuperior threesuperior onehalf onequarter threequarters franc Gbreve gbreve Idotaccent Scedilla scedilla Cacute cacute Ccaron ccaron dcroat".split(" ");
67
+ const POST_VERSION_MAC_STANDARD_ORDER = 65536;
68
+ const POST_VERSION_CUSTOM_NAMES = 131072;
69
+ function parsePostGlyphNames(font) {
70
+ const bytes = sfntTableBytes(font, "post");
71
+ if (bytes === void 0 || !hasBytes(bytes, 0, POST_HEADER_SIZE)) return;
72
+ const version = u32(bytes, 0);
73
+ if (version === POST_VERSION_MAC_STANDARD_ORDER) return (glyphId) => MAC_STANDARD_GLYPH_ORDER[glyphId];
74
+ if (version !== POST_VERSION_CUSTOM_NAMES) return;
75
+ if (!hasBytes(bytes, POST_HEADER_SIZE, 2)) return;
76
+ const numGlyphs = u16(bytes, POST_HEADER_SIZE);
77
+ const indicesOffset = 34;
78
+ if (!hasBytes(bytes, indicesOffset, numGlyphs * 2)) return;
79
+ const names = [];
80
+ let cursor = indicesOffset + numGlyphs * 2;
81
+ while (hasBytes(bytes, cursor, 1)) {
82
+ const length = u8(bytes, cursor);
83
+ if (!hasBytes(bytes, cursor + 1, length)) break;
84
+ let name = "";
85
+ for (let i = 0; i < length; i++) name += String.fromCharCode(u8(bytes, cursor + 1 + i));
86
+ names.push(name);
87
+ cursor += 1 + length;
88
+ }
89
+ return (glyphId) => {
90
+ if (glyphId < 0 || glyphId >= numGlyphs) return;
91
+ const index = u16(bytes, indicesOffset + glyphId * 2);
92
+ return index < MAC_STANDARD_GLYPH_ORDER.length ? MAC_STANDARD_GLYPH_ORDER[index] : names[index - MAC_STANDARD_GLYPH_ORDER.length];
93
+ };
94
+ }
66
95
  const NAME_HEADER_SIZE = 6;
67
96
  const NAME_RECORD_SIZE = 12;
68
97
  const NAME_ID_FAMILY = 1;
@@ -120,4 +149,4 @@ function parseName(font) {
120
149
  };
121
150
  }
122
151
  //#endregion
123
- export { parseHead, parseMaxp, parseName, parseOs2, parsePost };
152
+ export { MAC_STANDARD_GLYPH_ORDER, parseHead, parseMaxp, parseName, parseOs2, parsePost, parsePostGlyphNames };
package/dist/fonts.d.cts CHANGED
@@ -1,6 +1,6 @@
1
- import { r as StandardFontName } from "./afm-widths-DyDq56Ph.cjs";
1
+ import { r as StandardFontName } from "./afm-widths-CneRyu5l.cjs";
2
2
  //#region src/fonts.d.ts
3
- type StandardFamily = 'helvetica' | 'times' | 'courier';
3
+ type StandardFamily = "helvetica" | "times" | "courier";
4
4
  declare function normalizeFamilyName(raw: string): string;
5
5
  interface FontFamilyResolution {
6
6
  readonly family: StandardFamily;
package/dist/fonts.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { r as StandardFontName } from "./afm-widths-DyDq56Ph.js";
1
+ import { r as StandardFontName } from "./afm-widths-CneRyu5l.js";
2
2
  //#region src/fonts.d.ts
3
- type StandardFamily = 'helvetica' | 'times' | 'courier';
3
+ type StandardFamily = "helvetica" | "times" | "courier";
4
4
  declare function normalizeFamilyName(raw: string): string;
5
5
  interface FontFamilyResolution {
6
6
  readonly family: StandardFamily;
package/dist/form.cjs ADDED
@@ -0,0 +1,138 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_objects = require("./objects.cjs");
3
+ const require_pdf_text = require("./pdf-text.cjs");
4
+ //#region src/form.ts
5
+ const FLAG_READ_ONLY = 1;
6
+ const FLAG_PUSHBUTTON = 4;
7
+ const FLAG_RADIO = 32768;
8
+ const FLAG_COMBO = 131072;
9
+ function readAcroForm(catalog, resolver, pageIndex, sink) {
10
+ const acroForm = resolver.resolveDict(require_objects.dictGet(catalog, "AcroForm"));
11
+ if (acroForm === void 0) return [];
12
+ const fields = [];
13
+ const visited = /* @__PURE__ */ new Set();
14
+ for (const fieldRef of require_objects.asArray(resolver.resolve(require_objects.dictGet(acroForm, "Fields"))) ?? []) {
15
+ const fieldDict = resolver.resolveDict(fieldRef);
16
+ if (fieldDict !== void 0) readField(fieldDict, "", resolver, pageIndex, sink, fields, visited);
17
+ }
18
+ return fields;
19
+ }
20
+ function readField(node, parentName, resolver, pageIndex, sink, out, visited) {
21
+ if (visited.has(node)) {
22
+ sink({
23
+ code: "pdf/form-field-cycle",
24
+ severity: "warning",
25
+ message: "the AcroForm field tree contains a cycle; stopping descent at the repeated field"
26
+ });
27
+ return;
28
+ }
29
+ visited.add(node);
30
+ const ownName = annotText(node, "T");
31
+ const name = ownName === void 0 ? parentName : parentName.length > 0 ? `${parentName}.${ownName}` : ownName;
32
+ const fieldObj = require_objects.dictGet(node, "FT");
33
+ const fieldType = require_objects.asName(fieldObj);
34
+ if (fieldType === void 0) {
35
+ const children = [];
36
+ for (const kidRef of require_objects.asArray(resolver.resolve(require_objects.dictGet(node, "Kids"))) ?? []) {
37
+ const kid = resolver.resolveDict(kidRef);
38
+ if (kid !== void 0) readField(kid, name, resolver, pageIndex, sink, children, visited);
39
+ }
40
+ out.push({
41
+ name,
42
+ fieldType: "group",
43
+ widgets: [],
44
+ children
45
+ });
46
+ return;
47
+ }
48
+ const flags = require_objects.asNumber(resolver.resolve(require_objects.dictGet(node, "Ff"))) ?? 0;
49
+ const value = fieldValue(node, resolver);
50
+ const options = fieldOptions(node, resolver);
51
+ const alias = annotText(node, "TU");
52
+ const widgets = [];
53
+ for (const kidRef of require_objects.asArray(resolver.resolve(require_objects.dictGet(node, "Kids"))) ?? []) {
54
+ const kid = resolver.resolveDict(kidRef);
55
+ if (kid === void 0 || require_objects.dictGet(kid, "FT") !== void 0) continue;
56
+ const widget = widgetPlacement(kid, pageIndex);
57
+ if (widget !== void 0) widgets.push(widget);
58
+ }
59
+ if (widgets.length === 0 && require_objects.dictGet(node, "Rect") !== void 0) {
60
+ const widget = widgetPlacement(node, pageIndex);
61
+ if (widget !== void 0) widgets.push(widget);
62
+ }
63
+ out.push({
64
+ name,
65
+ fieldType: mapFieldType(fieldType, flags),
66
+ ...valueFields(fieldType, value),
67
+ ...options !== void 0 ? { options } : {},
68
+ ...alias !== void 0 ? { alias } : {},
69
+ ...(flags & FLAG_READ_ONLY) !== 0 ? { readOnly: true } : {},
70
+ widgets,
71
+ children: []
72
+ });
73
+ }
74
+ function mapFieldType(fieldType, flags) {
75
+ if (fieldType === "Tx") return "text";
76
+ if (fieldType === "Btn") {
77
+ if ((flags & FLAG_PUSHBUTTON) !== 0) return "button";
78
+ if ((flags & FLAG_RADIO) !== 0) return "radio";
79
+ return "checkbox";
80
+ }
81
+ if (fieldType === "Ch") return (flags & FLAG_COMBO) !== 0 ? "combobox" : "listbox";
82
+ return "signature";
83
+ }
84
+ function valueFields(fieldType, value) {
85
+ if (value === void 0) return {};
86
+ if (fieldType === "Btn") return {
87
+ checked: value !== "Off",
88
+ ...value !== "Off" ? { value } : {}
89
+ };
90
+ if (fieldType === "Sig") return {};
91
+ return { value };
92
+ }
93
+ function fieldValue(node, resolver) {
94
+ const value = resolver.resolve(require_objects.dictGet(node, "V"));
95
+ if (value?.kind === "string") return require_pdf_text.decodePdfString(value.bytes);
96
+ if (value?.kind === "name") return value.name;
97
+ if (value?.kind === "number") return String(value.value);
98
+ }
99
+ function fieldOptions(node, resolver) {
100
+ const opts = require_objects.asArray(resolver.resolve(require_objects.dictGet(node, "Opt")));
101
+ if (opts === void 0) return;
102
+ const values = [];
103
+ for (const opt of opts) {
104
+ const resolved = resolver.resolve(opt);
105
+ if (resolved?.kind === "string") values.push(require_pdf_text.decodePdfString(resolved.bytes));
106
+ else if (resolved?.kind === "array") {
107
+ const first = resolved.items[0];
108
+ const exportValue = first?.kind === "string" ? require_pdf_text.decodePdfString(first.bytes) : first?.kind === "name" ? first.name : void 0;
109
+ if (exportValue !== void 0) values.push(exportValue);
110
+ }
111
+ }
112
+ return values.length > 0 ? values : void 0;
113
+ }
114
+ function widgetPlacement(widget, pageIndex) {
115
+ const pageNo = pageIndex(require_objects.dictGet(widget, "P"));
116
+ if (pageNo === void 0) return;
117
+ return rectWidget(require_objects.asArray(require_objects.dictGet(widget, "Rect")), pageNo);
118
+ }
119
+ function rectWidget(rect, pageNo) {
120
+ if (rect === void 0) return;
121
+ const x1 = require_objects.asNumber(rect[0]) ?? 0;
122
+ const y1 = require_objects.asNumber(rect[1]) ?? 0;
123
+ const x2 = require_objects.asNumber(rect[2]) ?? 0;
124
+ const y2 = require_objects.asNumber(rect[3]) ?? 0;
125
+ return {
126
+ pageIndex: pageNo,
127
+ xPt: Math.min(x1, x2),
128
+ yPt: Math.min(y1, y2),
129
+ widthPt: Math.abs(x2 - x1),
130
+ heightPt: Math.abs(y2 - y1)
131
+ };
132
+ }
133
+ function annotText(dict, key) {
134
+ const obj = require_objects.dictGet(dict, key);
135
+ return obj?.kind === "string" ? require_pdf_text.decodePdfString(obj.bytes) : void 0;
136
+ }
137
+ //#endregion
138
+ exports.readAcroForm = readAcroForm;
@@ -0,0 +1,9 @@
1
+ import { PdfDiagnosticSink } from "./diagnostics.cjs";
2
+ import { n as PdfDict } from "./objects-B7HdMeWS.cjs";
3
+ import { PdfObjectResolver } from "./interpret.cjs";
4
+ import { LayoutFormField } from "./layout.cjs";
5
+ import { PageIndexLookup } from "./navigation.cjs";
6
+ //#region src/form.d.ts
7
+ declare function readAcroForm(catalog: PdfDict, resolver: PdfObjectResolver, pageIndex: PageIndexLookup, sink: PdfDiagnosticSink): LayoutFormField[];
8
+ //#endregion
9
+ export { readAcroForm };
package/dist/form.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ import { PdfDiagnosticSink } from "./diagnostics.js";
2
+ import { n as PdfDict } from "./objects-B7HdMeWS.js";
3
+ import { PdfObjectResolver } from "./interpret.js";
4
+ import { LayoutFormField } from "./layout.js";
5
+ import { PageIndexLookup } from "./navigation.js";
6
+ //#region src/form.d.ts
7
+ declare function readAcroForm(catalog: PdfDict, resolver: PdfObjectResolver, pageIndex: PageIndexLookup, sink: PdfDiagnosticSink): LayoutFormField[];
8
+ //#endregion
9
+ export { readAcroForm };