@pdfme/pdf-lib 6.0.3 → 6.0.5-dev.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 (449) hide show
  1. package/{src/api/Embeddable.ts → dist/api/Embeddable.d.ts} +1 -1
  2. package/dist/api/PDFDocument.d.ts +778 -0
  3. package/dist/api/PDFDocumentOptions.d.ts +38 -0
  4. package/dist/api/PDFEmbeddedFile.d.ts +38 -0
  5. package/dist/api/PDFEmbeddedPage.d.ts +73 -0
  6. package/dist/api/PDFFont.d.ts +94 -0
  7. package/dist/api/PDFImage.d.ts +95 -0
  8. package/dist/api/PDFJavaScript.d.ts +38 -0
  9. package/dist/api/PDFPage.d.ts +910 -0
  10. package/dist/api/PDFPageOptions.d.ts +172 -0
  11. package/dist/api/StandardFonts.d.ts +16 -0
  12. package/dist/api/colors.d.ts +34 -0
  13. package/dist/api/errors.d.ts +42 -0
  14. package/dist/api/form/PDFButton.d.ts +137 -0
  15. package/dist/api/form/PDFCheckBox.d.ts +142 -0
  16. package/dist/api/form/PDFDropdown.d.ts +402 -0
  17. package/dist/api/form/PDFField.d.ts +203 -0
  18. package/dist/api/form/PDFForm.d.ts +411 -0
  19. package/dist/api/form/PDFOptionList.d.ts +335 -0
  20. package/dist/api/form/PDFRadioGroup.d.ts +252 -0
  21. package/dist/api/form/PDFSignature.d.ts +29 -0
  22. package/dist/api/form/PDFTextField.d.ts +537 -0
  23. package/dist/api/form/appearances.d.ts +41 -0
  24. package/dist/api/image/alignment.d.ts +5 -0
  25. package/dist/api/objects.d.ts +4 -0
  26. package/dist/api/operations.d.ts +226 -0
  27. package/dist/api/operators.d.ts +90 -0
  28. package/dist/api/rotations.d.ts +38 -0
  29. package/dist/api/sizes.d.ts +52 -0
  30. package/dist/api/svg.d.ts +70 -0
  31. package/dist/api/svgPath.d.ts +2 -0
  32. package/dist/api/text/alignment.d.ts +5 -0
  33. package/dist/api/text/layout.d.ts +54 -0
  34. package/dist/core/PDFContext.d.ts +84 -0
  35. package/dist/core/PDFObjectCopier.d.ts +37 -0
  36. package/dist/core/acroform/PDFAcroButton.d.ts +21 -0
  37. package/dist/core/acroform/PDFAcroCheckBox.d.ts +13 -0
  38. package/dist/core/acroform/PDFAcroChoice.d.ts +20 -0
  39. package/dist/core/acroform/PDFAcroComboBox.d.ts +9 -0
  40. package/dist/core/acroform/PDFAcroField.d.ts +36 -0
  41. package/dist/core/acroform/PDFAcroForm.d.ts +20 -0
  42. package/dist/core/acroform/PDFAcroListBox.d.ts +9 -0
  43. package/dist/core/acroform/PDFAcroNonTerminal.d.ts +13 -0
  44. package/dist/core/acroform/PDFAcroPushButton.d.ts +9 -0
  45. package/dist/core/acroform/PDFAcroRadioButton.d.ts +13 -0
  46. package/{src/core/acroform/PDFAcroSignature.ts → dist/core/acroform/PDFAcroSignature.d.ts} +2 -4
  47. package/dist/core/acroform/PDFAcroTerminal.d.ts +16 -0
  48. package/dist/core/acroform/PDFAcroText.d.ts +22 -0
  49. package/dist/core/acroform/flags.d.ts +141 -0
  50. package/dist/core/acroform/utils.d.ts +6 -0
  51. package/dist/core/annotation/AppearanceCharacteristics.d.ts +33 -0
  52. package/dist/core/annotation/BorderStyle.d.ts +11 -0
  53. package/dist/core/annotation/PDFAnnotation.d.ts +51 -0
  54. package/dist/core/annotation/PDFWidgetAnnotation.d.ts +26 -0
  55. package/dist/core/annotation/flags.d.ts +79 -0
  56. package/dist/core/crypto.d.ts +95 -0
  57. package/dist/core/document/PDFCrossRefSection.d.ts +27 -0
  58. package/dist/core/document/PDFHeader.d.ts +10 -0
  59. package/dist/core/document/PDFTrailer.d.ts +9 -0
  60. package/dist/core/document/PDFTrailerDict.d.ts +10 -0
  61. package/dist/core/embedders/CMap.d.ts +3 -0
  62. package/dist/core/embedders/CustomFontEmbedder.d.ts +44 -0
  63. package/dist/core/embedders/CustomFontSubsetEmbedder.d.ts +20 -0
  64. package/dist/core/embedders/FileEmbedder.d.ts +33 -0
  65. package/dist/core/embedders/FontFlags.d.ts +13 -0
  66. package/dist/core/embedders/JavaScriptEmbedder.d.ts +10 -0
  67. package/dist/core/embedders/JpegEmbedder.d.ts +23 -0
  68. package/dist/core/embedders/PDFPageEmbedder.d.ts +37 -0
  69. package/dist/core/embedders/PngEmbedder.d.ts +19 -0
  70. package/dist/core/embedders/StandardFontEmbedder.d.ts +36 -0
  71. package/dist/core/errors.d.ts +94 -0
  72. package/{src/core/index.ts → dist/core/index.d.ts} +1 -17
  73. package/dist/core/interactive/ViewerPreferences.d.ts +347 -0
  74. package/dist/core/objects/PDFArray.d.ts +63 -0
  75. package/dist/core/objects/PDFBool.d.ts +13 -0
  76. package/dist/core/objects/PDFDict.d.ts +62 -0
  77. package/dist/core/objects/PDFHexString.d.ts +16 -0
  78. package/dist/core/objects/PDFInvalidObject.d.ts +11 -0
  79. package/dist/core/objects/PDFName.d.ts +41 -0
  80. package/dist/core/objects/PDFNull.d.ts +10 -0
  81. package/dist/core/objects/PDFNumber.d.ts +15 -0
  82. package/dist/core/objects/PDFObject.d.ts +8 -0
  83. package/dist/core/objects/PDFRawStream.d.ts +16 -0
  84. package/dist/core/objects/PDFRef.d.ts +13 -0
  85. package/dist/core/objects/PDFStream.d.ts +16 -0
  86. package/dist/core/objects/PDFString.d.ts +16 -0
  87. package/dist/core/operators/PDFOperator.d.ts +19 -0
  88. package/dist/core/operators/PDFOperatorNames.d.ts +76 -0
  89. package/dist/core/parser/BaseParser.d.ts +14 -0
  90. package/dist/core/parser/ByteStream.d.ts +26 -0
  91. package/dist/core/parser/PDFObjectParser.d.ts +31 -0
  92. package/dist/core/parser/PDFObjectStreamParser.d.ts +13 -0
  93. package/dist/core/parser/PDFParser.d.ts +46 -0
  94. package/dist/core/parser/PDFXRefStreamParser.d.ts +21 -0
  95. package/dist/core/streams/Ascii85Stream.d.ts +9 -0
  96. package/dist/core/streams/AsciiHexStream.d.ts +9 -0
  97. package/dist/core/streams/DecodeStream.d.ts +26 -0
  98. package/dist/core/streams/DecryptStream.d.ts +12 -0
  99. package/dist/core/streams/FlateStream.d.ts +13 -0
  100. package/dist/core/streams/LZWStream.d.ts +12 -0
  101. package/dist/core/streams/RunLengthStream.d.ts +8 -0
  102. package/dist/core/streams/Stream.d.ts +34 -0
  103. package/dist/core/streams/decode.d.ts +3 -0
  104. package/dist/core/structures/PDFCatalog.d.ts +27 -0
  105. package/dist/core/structures/PDFContentStream.d.ts +15 -0
  106. package/dist/core/structures/PDFCrossRefStream.d.ts +53 -0
  107. package/dist/core/structures/PDFFlateStream.d.ts +13 -0
  108. package/dist/core/structures/PDFObjectStream.d.ts +20 -0
  109. package/dist/core/structures/PDFPageLeaf.d.ts +54 -0
  110. package/dist/core/structures/PDFPageTree.d.ts +41 -0
  111. package/dist/core/syntax/CharCodes.d.ts +61 -0
  112. package/dist/core/syntax/Delimiters.d.ts +1 -0
  113. package/dist/core/syntax/Irregular.d.ts +1 -0
  114. package/dist/core/syntax/Keywords.d.ts +22 -0
  115. package/dist/core/syntax/Numeric.d.ts +3 -0
  116. package/dist/core/syntax/Whitespace.d.ts +1 -0
  117. package/dist/core/writers/PDFStreamWriter.d.ts +19 -0
  118. package/dist/core/writers/PDFWriter.d.ts +29 -0
  119. package/dist/index.js +19124 -0
  120. package/dist/index.js.map +1 -0
  121. package/dist/types/fontkit.d.ts +597 -0
  122. package/{src/types/index.ts → dist/types/index.d.ts} +8 -13
  123. package/{src/types/matrix.ts → dist/types/matrix.d.ts} +1 -2
  124. package/dist/utils/Cache.d.ts +10 -0
  125. package/dist/utils/arrays.d.ts +16 -0
  126. package/dist/utils/async.d.ts +5 -0
  127. package/dist/utils/base64.d.ts +10 -0
  128. package/dist/utils/elements/Arc.d.ts +22 -0
  129. package/dist/utils/elements/Circle.d.ts +14 -0
  130. package/dist/utils/elements/Ellipse.d.ts +20 -0
  131. package/dist/utils/elements/GraphElement.d.ts +6 -0
  132. package/dist/utils/elements/Line.d.ts +23 -0
  133. package/dist/utils/elements/Plot.d.ts +11 -0
  134. package/dist/utils/elements/Point.d.ts +18 -0
  135. package/dist/utils/elements/Rectangle.d.ts +21 -0
  136. package/dist/utils/elements/Segment.d.ts +19 -0
  137. package/dist/utils/errors.d.ts +1 -0
  138. package/dist/utils/intersections.d.ts +9 -0
  139. package/dist/utils/maths.d.ts +45 -0
  140. package/dist/utils/numbers.d.ts +23 -0
  141. package/dist/utils/objects.d.ts +15 -0
  142. package/dist/utils/pdfDocEncoding.d.ts +7 -0
  143. package/dist/utils/png.d.ts +17 -0
  144. package/dist/utils/rng.d.ts +13 -0
  145. package/dist/utils/strings.d.ts +25 -0
  146. package/{src/utils/unicode.ts → dist/utils/unicode.d.ts} +8 -195
  147. package/dist/utils/validators.d.ts +26 -0
  148. package/package.json +6 -1
  149. package/__tests__/api/PDFDocument.spec.ts +0 -576
  150. package/__tests__/api/PDFImage.spec.ts +0 -60
  151. package/__tests__/api/PDFPage.spec.ts +0 -151
  152. package/__tests__/api/form/PDFCheckBox.spec.ts +0 -71
  153. package/__tests__/api/form/PDFDropdown.spec.ts +0 -118
  154. package/__tests__/api/form/PDFForm.spec.ts +0 -370
  155. package/__tests__/api/form/PDFOptionList.spec.ts +0 -104
  156. package/__tests__/api/form/PDFRadioGroup.spec.ts +0 -183
  157. package/__tests__/api/form/PDFTextField.spec.ts +0 -148
  158. package/__tests__/api/svgPath.spec.ts +0 -153
  159. package/__tests__/api/text/layout.spec.ts +0 -166
  160. package/__tests__/core/PDFContext.spec.ts +0 -194
  161. package/__tests__/core/PDFObjectCopier.spec.ts +0 -421
  162. package/__tests__/core/acroform/PDFAcroField.spec.ts +0 -98
  163. package/__tests__/core/acroform/PDFAcroTerminal.spec.ts +0 -39
  164. package/__tests__/core/annotation/PDFWidgetAnnotation.spec.ts +0 -40
  165. package/__tests__/core/document/PDFCrossRefSection.spec.ts +0 -88
  166. package/__tests__/core/document/PDFHeader.spec.ts +0 -22
  167. package/__tests__/core/document/PDFTrailer.spec.ts +0 -28
  168. package/__tests__/core/document/PDFTrailerDict.spec.ts +0 -24
  169. package/__tests__/core/embedders/CMap.spec.ts +0 -47
  170. package/__tests__/core/embedders/CustomFontEmbedder.spec.ts +0 -96
  171. package/__tests__/core/embedders/CustomFontSubsetEmbedder.spec.ts +0 -62
  172. package/__tests__/core/embedders/FileEmbedder.spec.ts +0 -54
  173. package/__tests__/core/embedders/JpegEmbedder.spec.ts +0 -67
  174. package/__tests__/core/embedders/PDFPageEmbedder.spec.ts +0 -65
  175. package/__tests__/core/embedders/PngEmbedder.spec.ts +0 -87
  176. package/__tests__/core/embedders/StandardFontEmbedder.spec.ts +0 -79
  177. package/__tests__/core/embedders/data/SourceHanSerifJP-Regular.otf.cmap +0 -16096
  178. package/__tests__/core/embedders/data/Ubuntu-R.ttf.cmap +0 -1211
  179. package/__tests__/core/objects/PDFArray.spec.ts +0 -134
  180. package/__tests__/core/objects/PDFBool.spec.ts +0 -42
  181. package/__tests__/core/objects/PDFDict.spec.ts +0 -195
  182. package/__tests__/core/objects/PDFHexString.spec.ts +0 -168
  183. package/__tests__/core/objects/PDFInvalidObject.spec.ts +0 -32
  184. package/__tests__/core/objects/PDFName.spec.ts +0 -122
  185. package/__tests__/core/objects/PDFNull.spec.ts +0 -30
  186. package/__tests__/core/objects/PDFNumber.spec.ts +0 -50
  187. package/__tests__/core/objects/PDFObject.spec.ts +0 -29
  188. package/__tests__/core/objects/PDFRawStream.spec.ts +0 -45
  189. package/__tests__/core/objects/PDFRef.spec.ts +0 -60
  190. package/__tests__/core/objects/PDFString.spec.ts +0 -237
  191. package/__tests__/core/operators/PDFOperator.spec.ts +0 -77
  192. package/__tests__/core/parser/PDFObjectParser.spec.ts +0 -730
  193. package/__tests__/core/parser/PDFObjectStreamParser.spec.ts +0 -158
  194. package/__tests__/core/parser/PDFParser.spec.ts +0 -398
  195. package/__tests__/core/parser/PDFXRefStreamParser.spec.ts +0 -187
  196. package/__tests__/core/parser/data/object-stream-invalid +0 -2
  197. package/__tests__/core/parser/data/object-stream1 +0 -16
  198. package/__tests__/core/parser/data/object-stream2 +0 -10
  199. package/__tests__/core/parser/data/object-stream3 +0 -0
  200. package/__tests__/core/parser/data/object-stream4 +0 -0
  201. package/__tests__/core/parser/data/xref-stream1 +0 -0
  202. package/__tests__/core/parser/data/xref-stream2 +0 -0
  203. package/__tests__/core/parser/data/xref-stream3 +0 -0
  204. package/__tests__/core/parser/data/xref-stream4 +0 -0
  205. package/__tests__/core/streams/Ascii85Stream.spec.ts +0 -20
  206. package/__tests__/core/streams/AsciiHexStream.spec.ts +0 -20
  207. package/__tests__/core/streams/FlateStream.spec.ts +0 -20
  208. package/__tests__/core/streams/LZWStream.spec.ts +0 -20
  209. package/__tests__/core/streams/RunLengthStream.spec.ts +0 -20
  210. package/__tests__/core/streams/Stream.spec.ts +0 -128
  211. package/__tests__/core/streams/data/ascii85/1.decoded +0 -0
  212. package/__tests__/core/streams/data/ascii85/1.encoded +0 -43
  213. package/__tests__/core/streams/data/asciihex/1.decoded +0 -1
  214. package/__tests__/core/streams/data/asciihex/1.encoded +0 -1
  215. package/__tests__/core/streams/data/asciihex/2.decoded +0 -7
  216. package/__tests__/core/streams/data/asciihex/2.encoded +0 -1
  217. package/__tests__/core/streams/data/flate/1.corrupt.encoded +0 -1
  218. package/__tests__/core/streams/data/flate/1.decoded +0 -0
  219. package/__tests__/core/streams/data/flate/1.encoded +0 -2
  220. package/__tests__/core/streams/data/flate/2.decoded +0 -33
  221. package/__tests__/core/streams/data/flate/2.encoded +0 -0
  222. package/__tests__/core/streams/data/flate/3.decoded +0 -15
  223. package/__tests__/core/streams/data/flate/3.encoded +0 -0
  224. package/__tests__/core/streams/data/flate/4.decoded +0 -16
  225. package/__tests__/core/streams/data/flate/4.encoded +0 -0
  226. package/__tests__/core/streams/data/flate/5.decoded +0 -0
  227. package/__tests__/core/streams/data/flate/5.encoded +0 -0
  228. package/__tests__/core/streams/data/flate/6.decoded +0 -17
  229. package/__tests__/core/streams/data/flate/6.encoded +0 -0
  230. package/__tests__/core/streams/data/flate/7.decoded +0 -20
  231. package/__tests__/core/streams/data/flate/7.encoded +0 -1
  232. package/__tests__/core/streams/data/lzw/1.decoded +0 -0
  233. package/__tests__/core/streams/data/lzw/1.encoded +0 -0
  234. package/__tests__/core/streams/data/lzw/2.decoded +0 -0
  235. package/__tests__/core/streams/data/lzw/2.encoded +0 -0
  236. package/__tests__/core/streams/data/lzw/3.decoded +0 -14
  237. package/__tests__/core/streams/data/lzw/3.encoded +0 -2
  238. package/__tests__/core/streams/data/lzw/4.decoded +0 -14
  239. package/__tests__/core/streams/data/lzw/4.encoded +0 -2
  240. package/__tests__/core/streams/data/runlength/1.decoded +0 -1
  241. package/__tests__/core/streams/data/runlength/1.encoded +0 -1
  242. package/__tests__/core/streams/data/runlength/2.decoded +0 -1
  243. package/__tests__/core/streams/data/runlength/2.encoded +0 -1
  244. package/__tests__/core/streams/data/runlength/3.decoded +0 -0
  245. package/__tests__/core/streams/data/runlength/3.encoded +0 -0
  246. package/__tests__/core/streams/data/runlength/4.decoded +0 -1
  247. package/__tests__/core/streams/data/runlength/4.encoded +0 -1
  248. package/__tests__/core/streams/data/runlength/5.decoded +0 -1
  249. package/__tests__/core/streams/data/runlength/5.encoded +0 -1
  250. package/__tests__/core/streams/data/runlength/empty.encoded +0 -1
  251. package/__tests__/core/structures/PDFCatalog.spec.ts +0 -108
  252. package/__tests__/core/structures/PDFContentStream.spec.ts +0 -117
  253. package/__tests__/core/structures/PDFCrossRefStream.spec.ts +0 -145
  254. package/__tests__/core/structures/PDFObjectStream.spec.ts +0 -138
  255. package/__tests__/core/structures/PDFPageLeaf.spec.ts +0 -355
  256. package/__tests__/core/structures/PDFPageTree.spec.ts +0 -592
  257. package/__tests__/core/writers/PDFStreamWriter.spec.ts +0 -71
  258. package/__tests__/core/writers/PDFWriter.spec.ts +0 -144
  259. package/__tests__/core/writers/data/stream-writer-1.pdf +0 -0
  260. package/__tests__/index.test.ts +0 -12
  261. package/__tests__/utils/base64.spec.ts +0 -61
  262. package/__tests__/utils/data/simple.pdf +0 -201
  263. package/__tests__/utils/data/simple.pdf.base64 +0 -1
  264. package/__tests__/utils/pdfDocEncoding.spec.ts +0 -82
  265. package/__tests__/utils/png.spec.ts +0 -53
  266. package/__tests__/utils/rng.spec.ts +0 -14
  267. package/__tests__/utils/strings.spec.ts +0 -98
  268. package/__tests__/utils/unicode.spec.ts +0 -337
  269. package/assets/fonts/source_hans_jp/SourceHanSerifJP-Regular.otf +0 -0
  270. package/assets/fonts/ubuntu/Ubuntu-B.ttf +0 -0
  271. package/assets/fonts/ubuntu/Ubuntu-R.ttf +0 -0
  272. package/assets/images/cat_riding_unicorn.jpg +0 -0
  273. package/assets/images/cmyk_colorspace.jpg +0 -0
  274. package/assets/images/greyscale_bird.png +0 -0
  275. package/assets/images/minions_banana_alpha.png +0 -0
  276. package/assets/images/minions_banana_no_alpha.png +0 -0
  277. package/assets/images/minions_laughing.jpg +0 -0
  278. package/assets/pdfs/bixby_guide.pdf +0 -0
  279. package/assets/pdfs/encrypted_new.pdf +0 -0
  280. package/assets/pdfs/encrypted_old.pdf +0 -0
  281. package/assets/pdfs/fancy_fields.pdf +0 -0
  282. package/assets/pdfs/giraffe.pdf +0 -0
  283. package/assets/pdfs/invalid_root_ref.pdf +0 -0
  284. package/assets/pdfs/just_metadata.pdf +0 -49
  285. package/assets/pdfs/missing_endobj_keyword.pdf +0 -70
  286. package/assets/pdfs/missing_xref_trailer_dict.pdf +0 -141
  287. package/assets/pdfs/normal.pdf +0 -0
  288. package/assets/pdfs/pdf20examples/PDF 2.0 with offset start.pdf +0 -179
  289. package/assets/pdfs/stuff_following_header.pdf +0 -0
  290. package/assets/pdfs/us_constitution.pdf +0 -0
  291. package/assets/pdfs/with_comments.pdf +0 -0
  292. package/assets/pdfs/with_invalid_objects.pdf +0 -53
  293. package/assets/pdfs/with_invalid_stream_EOL.pdf +0 -0
  294. package/assets/pdfs/with_null_parent_entry.pdf +0 -0
  295. package/assets/pdfs/with_signature.pdf +0 -0
  296. package/assets/pdfs/with_update_sections.pdf +0 -0
  297. package/assets/pdfs/with_viewer_prefs.pdf +0 -0
  298. package/assets/pdfs/with_xfa_fields.pdf +0 -0
  299. package/src/api/PDFDocument.ts +0 -1389
  300. package/src/api/PDFDocumentOptions.ts +0 -45
  301. package/src/api/PDFEmbeddedFile.ts +0 -87
  302. package/src/api/PDFEmbeddedPage.ts +0 -100
  303. package/src/api/PDFFont.ts +0 -149
  304. package/src/api/PDFImage.ts +0 -143
  305. package/src/api/PDFJavaScript.ts +0 -75
  306. package/src/api/PDFPage.ts +0 -1604
  307. package/src/api/PDFPageOptions.ts +0 -175
  308. package/src/api/StandardFonts.ts +0 -16
  309. package/src/api/colors.ts +0 -109
  310. package/src/api/errors.ts +0 -110
  311. package/src/api/form/PDFButton.ts +0 -242
  312. package/src/api/form/PDFCheckBox.ts +0 -247
  313. package/src/api/form/PDFDropdown.ts +0 -637
  314. package/src/api/form/PDFField.ts +0 -491
  315. package/src/api/form/PDFForm.ts +0 -842
  316. package/src/api/form/PDFOptionList.ts +0 -555
  317. package/src/api/form/PDFRadioGroup.ts +0 -455
  318. package/src/api/form/PDFSignature.ts +0 -44
  319. package/src/api/form/PDFTextField.ts +0 -811
  320. package/src/api/form/appearances.ts +0 -655
  321. package/src/api/image/alignment.ts +0 -5
  322. package/src/api/objects.ts +0 -10
  323. package/src/api/operations.ts +0 -873
  324. package/src/api/operators.ts +0 -335
  325. package/src/api/rotations.ts +0 -84
  326. package/src/api/sizes.ts +0 -52
  327. package/src/api/svg.ts +0 -888
  328. package/src/api/svgPath.ts +0 -460
  329. package/src/api/text/alignment.ts +0 -5
  330. package/src/api/text/layout.ts +0 -328
  331. package/src/core/PDFContext.ts +0 -274
  332. package/src/core/PDFObjectCopier.ts +0 -142
  333. package/src/core/acroform/PDFAcroButton.ts +0 -104
  334. package/src/core/acroform/PDFAcroCheckBox.ts +0 -48
  335. package/src/core/acroform/PDFAcroChoice.ts +0 -143
  336. package/src/core/acroform/PDFAcroComboBox.ts +0 -21
  337. package/src/core/acroform/PDFAcroField.ts +0 -168
  338. package/src/core/acroform/PDFAcroForm.ts +0 -96
  339. package/src/core/acroform/PDFAcroListBox.ts +0 -19
  340. package/src/core/acroform/PDFAcroNonTerminal.ts +0 -33
  341. package/src/core/acroform/PDFAcroPushButton.ts +0 -21
  342. package/src/core/acroform/PDFAcroRadioButton.ts +0 -57
  343. package/src/core/acroform/PDFAcroTerminal.ts +0 -70
  344. package/src/core/acroform/PDFAcroText.ts +0 -76
  345. package/src/core/acroform/flags.ts +0 -162
  346. package/src/core/acroform/utils.ts +0 -129
  347. package/src/core/annotation/AppearanceCharacteristics.ts +0 -133
  348. package/src/core/annotation/BorderStyle.ts +0 -31
  349. package/src/core/annotation/PDFAnnotation.ts +0 -148
  350. package/src/core/annotation/PDFWidgetAnnotation.ts +0 -111
  351. package/src/core/annotation/flags.ts +0 -90
  352. package/src/core/crypto.ts +0 -1844
  353. package/src/core/document/PDFCrossRefSection.ts +0 -161
  354. package/src/core/document/PDFHeader.ts +0 -48
  355. package/src/core/document/PDFTrailer.ts +0 -48
  356. package/src/core/document/PDFTrailerDict.ts +0 -39
  357. package/src/core/embedders/CMap.ts +0 -65
  358. package/src/core/embedders/CustomFontEmbedder.ts +0 -237
  359. package/src/core/embedders/CustomFontSubsetEmbedder.ts +0 -89
  360. package/src/core/embedders/FileEmbedder.ts +0 -77
  361. package/src/core/embedders/FontFlags.ts +0 -45
  362. package/src/core/embedders/JavaScriptEmbedder.ts +0 -34
  363. package/src/core/embedders/JpegEmbedder.ts +0 -118
  364. package/src/core/embedders/PDFPageEmbedder.ts +0 -139
  365. package/src/core/embedders/PngEmbedder.ts +0 -69
  366. package/src/core/embedders/StandardFontEmbedder.ts +0 -121
  367. package/src/core/errors.ts +0 -226
  368. package/src/core/interactive/ViewerPreferences.ts +0 -565
  369. package/src/core/objects/PDFArray.ts +0 -179
  370. package/src/core/objects/PDFBool.ts +0 -53
  371. package/src/core/objects/PDFDict.ts +0 -220
  372. package/src/core/objects/PDFHexString.ts +0 -94
  373. package/src/core/objects/PDFInvalidObject.ts +0 -34
  374. package/src/core/objects/PDFName.ts +0 -152
  375. package/src/core/objects/PDFNull.ts +0 -30
  376. package/src/core/objects/PDFNumber.ts +0 -44
  377. package/src/core/objects/PDFObject.ts +0 -22
  378. package/src/core/objects/PDFRawStream.ts +0 -41
  379. package/src/core/objects/PDFRef.ts +0 -51
  380. package/src/core/objects/PDFStream.ts +0 -87
  381. package/src/core/objects/PDFString.ts +0 -118
  382. package/src/core/operators/PDFOperator.ts +0 -72
  383. package/src/core/operators/PDFOperatorNames.ts +0 -92
  384. package/src/core/parser/BaseParser.ts +0 -119
  385. package/src/core/parser/ByteStream.ts +0 -76
  386. package/src/core/parser/PDFObjectParser.ts +0 -302
  387. package/src/core/parser/PDFObjectStreamParser.ts +0 -65
  388. package/src/core/parser/PDFParser.ts +0 -363
  389. package/src/core/parser/PDFXRefStreamParser.ts +0 -129
  390. package/src/core/streams/Ascii85Stream.ts +0 -97
  391. package/src/core/streams/AsciiHexStream.ts +0 -77
  392. package/src/core/streams/DecodeStream.ts +0 -188
  393. package/src/core/streams/DecryptStream.ts +0 -49
  394. package/src/core/streams/FlateStream.ts +0 -397
  395. package/src/core/streams/LZWStream.ts +0 -157
  396. package/src/core/streams/RunLengthStream.ts +0 -55
  397. package/src/core/streams/Stream.ts +0 -126
  398. package/src/core/streams/decode.ts +0 -70
  399. package/src/core/structures/PDFCatalog.ts +0 -81
  400. package/src/core/structures/PDFContentStream.ts +0 -58
  401. package/src/core/structures/PDFCrossRefStream.ts +0 -238
  402. package/src/core/structures/PDFFlateStream.ts +0 -40
  403. package/src/core/structures/PDFObjectStream.ts +0 -91
  404. package/src/core/structures/PDFPageLeaf.ts +0 -244
  405. package/src/core/structures/PDFPageTree.ts +0 -192
  406. package/src/core/syntax/CharCodes.ts +0 -62
  407. package/src/core/syntax/Delimiters.ts +0 -14
  408. package/src/core/syntax/Irregular.ts +0 -10
  409. package/src/core/syntax/Keywords.ts +0 -57
  410. package/src/core/syntax/Numeric.ts +0 -26
  411. package/src/core/syntax/Whitespace.ts +0 -10
  412. package/src/core/writers/PDFStreamWriter.ts +0 -114
  413. package/src/core/writers/PDFWriter.ts +0 -146
  414. package/src/types/fontkit.ts +0 -643
  415. package/src/utils/Cache.ts +0 -26
  416. package/src/utils/arrays.ts +0 -153
  417. package/src/utils/async.ts +0 -8
  418. package/src/utils/base64.ts +0 -98
  419. package/src/utils/elements/Arc.ts +0 -97
  420. package/src/utils/elements/Circle.ts +0 -47
  421. package/src/utils/elements/Ellipse.ts +0 -117
  422. package/src/utils/elements/GraphElement.ts +0 -14
  423. package/src/utils/elements/Line.ts +0 -83
  424. package/src/utils/elements/Plot.ts +0 -50
  425. package/src/utils/elements/Point.ts +0 -37
  426. package/src/utils/elements/Rectangle.ts +0 -65
  427. package/src/utils/elements/Segment.ts +0 -81
  428. package/src/utils/errors.ts +0 -3
  429. package/src/utils/intersections.ts +0 -237
  430. package/src/utils/maths.ts +0 -96
  431. package/src/utils/numbers.ts +0 -55
  432. package/src/utils/objects.ts +0 -13
  433. package/src/utils/pdfDocEncoding.ts +0 -69
  434. package/src/utils/png.ts +0 -100
  435. package/src/utils/rng.ts +0 -21
  436. package/src/utils/strings.ts +0 -191
  437. package/src/utils/validators.ts +0 -192
  438. package/tsconfig.build.json +0 -14
  439. package/tsconfig.json +0 -15
  440. package/vite.config.mts +0 -39
  441. /package/{src/api/form/index.ts → dist/api/form/index.d.ts} +0 -0
  442. /package/{src/api/image/index.ts → dist/api/image/index.d.ts} +0 -0
  443. /package/{src/api/index.ts → dist/api/index.d.ts} +0 -0
  444. /package/{src/api/text/index.ts → dist/api/text/index.d.ts} +0 -0
  445. /package/{src/core/acroform/index.ts → dist/core/acroform/index.d.ts} +0 -0
  446. /package/{src/core/annotation/index.ts → dist/core/annotation/index.d.ts} +0 -0
  447. /package/{src/index.ts → dist/index.d.ts} +0 -0
  448. /package/{src/utils/elements/index.ts → dist/utils/elements/index.d.ts} +0 -0
  449. /package/{src/utils/index.ts → dist/utils/index.d.ts} +0 -0
@@ -1,161 +0,0 @@
1
- import PDFRef from '../objects/PDFRef';
2
- import CharCodes from '../syntax/CharCodes';
3
- import { copyStringIntoBuffer, padStart } from '../../utils';
4
-
5
- export interface Entry {
6
- ref: PDFRef;
7
- offset: number;
8
- deleted: boolean;
9
- }
10
-
11
- /**
12
- * Entries should be added using the [[addEntry]] and [[addDeletedEntry]]
13
- * methods **in order of ascending object number**.
14
- */
15
- class PDFCrossRefSection {
16
- static create = () =>
17
- new PDFCrossRefSection({
18
- ref: PDFRef.of(0, 65535),
19
- offset: 0,
20
- deleted: true,
21
- });
22
-
23
- static createEmpty = () => new PDFCrossRefSection();
24
-
25
- private subsections: Entry[][];
26
- private chunkIdx: number;
27
- private chunkLength: number;
28
-
29
- private constructor(firstEntry: Entry | void) {
30
- this.subsections = firstEntry ? [[firstEntry]] : [];
31
- this.chunkIdx = 0;
32
- this.chunkLength = firstEntry ? 1 : 0;
33
- }
34
-
35
- addEntry(ref: PDFRef, offset: number): void {
36
- this.append({ ref, offset, deleted: false });
37
- }
38
-
39
- addDeletedEntry(ref: PDFRef, nextFreeObjectNumber: number): void {
40
- this.append({ ref, offset: nextFreeObjectNumber, deleted: true });
41
- }
42
-
43
- toString(): string {
44
- let section = `xref\n`;
45
-
46
- for (let rangeIdx = 0, rangeLen = this.subsections.length; rangeIdx < rangeLen; rangeIdx++) {
47
- const range = this.subsections[rangeIdx];
48
- section += `${range[0].ref.objectNumber} ${range.length}\n`;
49
- for (let entryIdx = 0, entryLen = range.length; entryIdx < entryLen; entryIdx++) {
50
- const entry = range[entryIdx];
51
- section += padStart(String(entry.offset), 10, '0');
52
- section += ' ';
53
- section += padStart(String(entry.ref.generationNumber), 5, '0');
54
- section += ' ';
55
- section += entry.deleted ? 'f' : 'n';
56
- section += ' \n';
57
- }
58
- }
59
-
60
- return section;
61
- }
62
-
63
- sizeInBytes(): number {
64
- let size = 5;
65
- for (let idx = 0, len = this.subsections.length; idx < len; idx++) {
66
- const subsection = this.subsections[idx];
67
- const subsectionLength = subsection.length;
68
- const [firstEntry] = subsection;
69
- size += 2;
70
- size += String(firstEntry.ref.objectNumber).length;
71
- size += String(subsectionLength).length;
72
- size += 20 * subsectionLength;
73
- }
74
- return size;
75
- }
76
-
77
- copyBytesInto(buffer: Uint8Array, offset: number): number {
78
- const initialOffset = offset;
79
-
80
- buffer[offset++] = CharCodes.x;
81
- buffer[offset++] = CharCodes.r;
82
- buffer[offset++] = CharCodes.e;
83
- buffer[offset++] = CharCodes.f;
84
- buffer[offset++] = CharCodes.Newline;
85
-
86
- offset += this.copySubsectionsIntoBuffer(this.subsections, buffer, offset);
87
-
88
- return offset - initialOffset;
89
- }
90
-
91
- private copySubsectionsIntoBuffer(
92
- subsections: Entry[][],
93
- buffer: Uint8Array,
94
- offset: number,
95
- ): number {
96
- const initialOffset = offset;
97
- const length = subsections.length;
98
-
99
- for (let idx = 0; idx < length; idx++) {
100
- const subsection = this.subsections[idx];
101
-
102
- const firstObjectNumber = String(subsection[0].ref.objectNumber);
103
- offset += copyStringIntoBuffer(firstObjectNumber, buffer, offset);
104
- buffer[offset++] = CharCodes.Space;
105
-
106
- const rangeLength = String(subsection.length);
107
- offset += copyStringIntoBuffer(rangeLength, buffer, offset);
108
- buffer[offset++] = CharCodes.Newline;
109
-
110
- offset += this.copyEntriesIntoBuffer(subsection, buffer, offset);
111
- }
112
-
113
- return offset - initialOffset;
114
- }
115
-
116
- private copyEntriesIntoBuffer(entries: Entry[], buffer: Uint8Array, offset: number): number {
117
- const length = entries.length;
118
-
119
- for (let idx = 0; idx < length; idx++) {
120
- const entry = entries[idx];
121
-
122
- const entryOffset = padStart(String(entry.offset), 10, '0');
123
- offset += copyStringIntoBuffer(entryOffset, buffer, offset);
124
- buffer[offset++] = CharCodes.Space;
125
-
126
- const entryGen = padStart(String(entry.ref.generationNumber), 5, '0');
127
- offset += copyStringIntoBuffer(entryGen, buffer, offset);
128
- buffer[offset++] = CharCodes.Space;
129
-
130
- buffer[offset++] = entry.deleted ? CharCodes.f : CharCodes.n;
131
-
132
- buffer[offset++] = CharCodes.Space;
133
- buffer[offset++] = CharCodes.Newline;
134
- }
135
-
136
- return 20 * length;
137
- }
138
-
139
- private append(currEntry: Entry): void {
140
- if (this.chunkLength === 0) {
141
- this.subsections.push([currEntry]);
142
- this.chunkIdx = 0;
143
- this.chunkLength = 1;
144
- return;
145
- }
146
-
147
- const chunk = this.subsections[this.chunkIdx];
148
- const prevEntry = chunk[this.chunkLength - 1];
149
-
150
- if (currEntry.ref.objectNumber - prevEntry.ref.objectNumber > 1) {
151
- this.subsections.push([currEntry]);
152
- this.chunkIdx += 1;
153
- this.chunkLength = 1;
154
- } else {
155
- chunk.push(currEntry);
156
- this.chunkLength += 1;
157
- }
158
- }
159
- }
160
-
161
- export default PDFCrossRefSection;
@@ -1,48 +0,0 @@
1
- import CharCodes from '../syntax/CharCodes';
2
- import { charFromCode, copyStringIntoBuffer } from '../../utils';
3
-
4
- class PDFHeader {
5
- static forVersion = (major: number, minor: number) => new PDFHeader(major, minor);
6
-
7
- private readonly major: string;
8
- private readonly minor: string;
9
-
10
- private constructor(major: number, minor: number) {
11
- this.major = String(major);
12
- this.minor = String(minor);
13
- }
14
-
15
- toString(): string {
16
- const bc = charFromCode(129);
17
- return `%PDF-${this.major}.${this.minor}\n%${bc}${bc}${bc}${bc}`;
18
- }
19
-
20
- sizeInBytes(): number {
21
- return 12 + this.major.length + this.minor.length;
22
- }
23
-
24
- copyBytesInto(buffer: Uint8Array, offset: number): number {
25
- const initialOffset = offset;
26
-
27
- buffer[offset++] = CharCodes.Percent;
28
- buffer[offset++] = CharCodes.P;
29
- buffer[offset++] = CharCodes.D;
30
- buffer[offset++] = CharCodes.F;
31
- buffer[offset++] = CharCodes.Dash;
32
-
33
- offset += copyStringIntoBuffer(this.major, buffer, offset);
34
- buffer[offset++] = CharCodes.Period;
35
- offset += copyStringIntoBuffer(this.minor, buffer, offset);
36
- buffer[offset++] = CharCodes.Newline;
37
-
38
- buffer[offset++] = CharCodes.Percent;
39
- buffer[offset++] = 129;
40
- buffer[offset++] = 129;
41
- buffer[offset++] = 129;
42
- buffer[offset++] = 129;
43
-
44
- return offset - initialOffset;
45
- }
46
- }
47
-
48
- export default PDFHeader;
@@ -1,48 +0,0 @@
1
- import CharCodes from '../syntax/CharCodes';
2
- import { copyStringIntoBuffer } from '../../utils';
3
-
4
- class PDFTrailer {
5
- static forLastCrossRefSectionOffset = (offset: number) => new PDFTrailer(offset);
6
-
7
- private readonly lastXRefOffset: string;
8
-
9
- private constructor(lastXRefOffset: number) {
10
- this.lastXRefOffset = String(lastXRefOffset);
11
- }
12
-
13
- toString(): string {
14
- return `startxref\n${this.lastXRefOffset}\n%%EOF`;
15
- }
16
-
17
- sizeInBytes(): number {
18
- return 16 + this.lastXRefOffset.length;
19
- }
20
-
21
- copyBytesInto(buffer: Uint8Array, offset: number): number {
22
- const initialOffset = offset;
23
-
24
- buffer[offset++] = CharCodes.s;
25
- buffer[offset++] = CharCodes.t;
26
- buffer[offset++] = CharCodes.a;
27
- buffer[offset++] = CharCodes.r;
28
- buffer[offset++] = CharCodes.t;
29
- buffer[offset++] = CharCodes.x;
30
- buffer[offset++] = CharCodes.r;
31
- buffer[offset++] = CharCodes.e;
32
- buffer[offset++] = CharCodes.f;
33
- buffer[offset++] = CharCodes.Newline;
34
-
35
- offset += copyStringIntoBuffer(this.lastXRefOffset, buffer, offset);
36
-
37
- buffer[offset++] = CharCodes.Newline;
38
- buffer[offset++] = CharCodes.Percent;
39
- buffer[offset++] = CharCodes.Percent;
40
- buffer[offset++] = CharCodes.E;
41
- buffer[offset++] = CharCodes.O;
42
- buffer[offset++] = CharCodes.F;
43
-
44
- return offset - initialOffset;
45
- }
46
- }
47
-
48
- export default PDFTrailer;
@@ -1,39 +0,0 @@
1
- import PDFDict from '../objects/PDFDict';
2
- import CharCodes from '../syntax/CharCodes';
3
-
4
- class PDFTrailerDict {
5
- static of = (dict: PDFDict) => new PDFTrailerDict(dict);
6
-
7
- readonly dict: PDFDict;
8
-
9
- private constructor(dict: PDFDict) {
10
- this.dict = dict;
11
- }
12
-
13
- toString(): string {
14
- return `trailer\n${this.dict.toString()}`;
15
- }
16
-
17
- sizeInBytes(): number {
18
- return 8 + this.dict.sizeInBytes();
19
- }
20
-
21
- copyBytesInto(buffer: Uint8Array, offset: number): number {
22
- const initialOffset = offset;
23
-
24
- buffer[offset++] = CharCodes.t;
25
- buffer[offset++] = CharCodes.r;
26
- buffer[offset++] = CharCodes.a;
27
- buffer[offset++] = CharCodes.i;
28
- buffer[offset++] = CharCodes.l;
29
- buffer[offset++] = CharCodes.e;
30
- buffer[offset++] = CharCodes.r;
31
- buffer[offset++] = CharCodes.Newline;
32
-
33
- offset += this.dict.copyBytesInto(buffer, offset);
34
-
35
- return offset - initialOffset;
36
- }
37
- }
38
-
39
- export default PDFTrailerDict;
@@ -1,65 +0,0 @@
1
- import { Glyph } from '../../types/fontkit';
2
-
3
- import { toHexString, toHexStringOfMinLength } from '../../utils';
4
- import { hasSurrogates, highSurrogate, isWithinBMP, lowSurrogate } from '../../utils/unicode';
5
-
6
- /** [fontId, codePoint] */
7
- type BfChar = [string, string];
8
-
9
- /** `glyphs` should be an array of unique glyphs */
10
- export const createCmap = (glyphs: Glyph[], glyphId: (g?: Glyph) => number) => {
11
- const bfChars: BfChar[] = Array(glyphs.length);
12
- for (let idx = 0, len = glyphs.length; idx < len; idx++) {
13
- const glyph = glyphs[idx];
14
- const id = cmapHexFormat(cmapHexString(glyphId(glyph)));
15
- const unicode = cmapHexFormat(...glyph.codePoints.map(cmapCodePointFormat));
16
- bfChars[idx] = [id, unicode];
17
- }
18
-
19
- return fillCmapTemplate(bfChars);
20
- };
21
-
22
- /* =============================== Templates ================================ */
23
-
24
- const fillCmapTemplate = (bfChars: BfChar[]) => `\
25
- /CIDInit /ProcSet findresource begin
26
- 12 dict begin
27
- begincmap
28
- /CIDSystemInfo <<
29
- /Registry (Adobe)
30
- /Ordering (UCS)
31
- /Supplement 0
32
- >> def
33
- /CMapName /Adobe-Identity-UCS def
34
- /CMapType 2 def
35
- 1 begincodespacerange
36
- <0000><ffff>
37
- endcodespacerange
38
- ${bfChars.length} beginbfchar
39
- ${bfChars.map(([glyphId, codePoint]) => `${glyphId} ${codePoint}`).join('\n')}
40
- endbfchar
41
- endcmap
42
- CMapName currentdict /CMap defineresource pop
43
- end
44
- end\
45
- `;
46
-
47
- /* =============================== Utilities ================================ */
48
-
49
- const cmapHexFormat = (...values: string[]) => `<${values.join('')}>`;
50
-
51
- const cmapHexString = (value: number) => toHexStringOfMinLength(value, 4);
52
-
53
- const cmapCodePointFormat = (codePoint: number) => {
54
- if (isWithinBMP(codePoint)) return cmapHexString(codePoint);
55
-
56
- if (hasSurrogates(codePoint)) {
57
- const hs = highSurrogate(codePoint);
58
- const ls = lowSurrogate(codePoint);
59
- return `${cmapHexString(hs)}${cmapHexString(ls)}`;
60
- }
61
-
62
- const hex = toHexString(codePoint);
63
- const msg = `0x${hex} is not a valid UTF-8 or UTF-16 codepoint.`;
64
- throw new Error(msg);
65
- };
@@ -1,237 +0,0 @@
1
- import { Font, Fontkit, Glyph, TypeFeatures } from '../../types/fontkit';
2
-
3
- import { createCmap } from './CMap';
4
- import { deriveFontFlags } from './FontFlags';
5
- import PDFHexString from '../objects/PDFHexString';
6
- import PDFRef from '../objects/PDFRef';
7
- import PDFString from '../objects/PDFString';
8
- import PDFContext from '../PDFContext';
9
- import { byAscendingId, Cache, sortedUniq, toHexStringOfMinLength } from '../../utils';
10
-
11
- /**
12
- * A note of thanks to the developers of https://github.com/foliojs/pdfkit, as
13
- * this class borrows from:
14
- * https://github.com/devongovett/pdfkit/blob/e71edab0dd4657b5a767804ba86c94c58d01fbca/lib/image/jpeg.coffee
15
- */
16
- class CustomFontEmbedder {
17
- static async for(
18
- fontkit: Fontkit,
19
- fontData: Uint8Array,
20
- customName?: string,
21
- fontFeatures?: TypeFeatures,
22
- ) {
23
- const font = fontkit.create(fontData);
24
- return new CustomFontEmbedder(font, fontData, customName, fontFeatures);
25
- }
26
-
27
- readonly font: Font;
28
- readonly scale: number;
29
- readonly fontData: Uint8Array;
30
- readonly fontName: string;
31
- readonly customName: string | undefined;
32
- readonly fontFeatures: TypeFeatures | undefined;
33
-
34
- protected baseFontName: string;
35
- protected glyphCache: Cache<Glyph[]>;
36
-
37
- protected constructor(
38
- font: Font,
39
- fontData: Uint8Array,
40
- customName?: string,
41
- fontFeatures?: TypeFeatures,
42
- ) {
43
- this.font = font;
44
- this.scale = 1000 / this.font.unitsPerEm;
45
- this.fontData = fontData;
46
- this.fontName = this.font.postscriptName || 'Font';
47
- this.customName = customName;
48
- this.fontFeatures = fontFeatures;
49
-
50
- this.baseFontName = '';
51
- this.glyphCache = Cache.populatedBy(this.allGlyphsInFontSortedById);
52
- }
53
-
54
- /**
55
- * Encode the JavaScript string into this font. (JavaScript encodes strings in
56
- * Unicode, but embedded fonts use their own custom encodings)
57
- */
58
- encodeText(text: string): PDFHexString {
59
- const { glyphs } = this.font.layout(text, this.fontFeatures);
60
- const hexCodes = Array(glyphs.length);
61
- for (let idx = 0, len = glyphs.length; idx < len; idx++) {
62
- hexCodes[idx] = toHexStringOfMinLength(glyphs[idx].id, 4);
63
- }
64
- return PDFHexString.of(hexCodes.join(''));
65
- }
66
-
67
- // The advanceWidth takes into account kerning automatically, so we don't
68
- // have to do that manually like we do for the standard fonts.
69
- widthOfTextAtSize(text: string, size: number): number {
70
- const { glyphs } = this.font.layout(text, this.fontFeatures);
71
- let totalWidth = 0;
72
- for (let idx = 0, len = glyphs.length; idx < len; idx++) {
73
- totalWidth += glyphs[idx].advanceWidth * this.scale;
74
- }
75
- const scale = size / 1000;
76
- return totalWidth * scale;
77
- }
78
-
79
- heightOfFontAtSize(size: number, options: { descender?: boolean } = {}): number {
80
- const { descender = true } = options;
81
-
82
- const { ascent, descent, bbox } = this.font;
83
- const yTop = (ascent || bbox.maxY) * this.scale;
84
- const yBottom = (descent || bbox.minY) * this.scale;
85
-
86
- let height = yTop - yBottom;
87
- if (!descender) height -= Math.abs(descent) || 0;
88
-
89
- return (height / 1000) * size;
90
- }
91
-
92
- sizeOfFontAtHeight(height: number): number {
93
- const { ascent, descent, bbox } = this.font;
94
- const yTop = (ascent || bbox.maxY) * this.scale;
95
- const yBottom = (descent || bbox.minY) * this.scale;
96
- return (1000 * height) / (yTop - yBottom);
97
- }
98
-
99
- embedIntoContext(context: PDFContext, ref?: PDFRef): Promise<PDFRef> {
100
- this.baseFontName = this.customName || context.addRandomSuffix(this.fontName);
101
- return this.embedFontDict(context, ref);
102
- }
103
-
104
- protected async embedFontDict(context: PDFContext, ref?: PDFRef): Promise<PDFRef> {
105
- const cidFontDictRef = await this.embedCIDFontDict(context);
106
- const unicodeCMapRef = this.embedUnicodeCmap(context);
107
-
108
- const fontDict = context.obj({
109
- Type: 'Font',
110
- Subtype: 'Type0',
111
- BaseFont: this.baseFontName,
112
- Encoding: 'Identity-H',
113
- DescendantFonts: [cidFontDictRef],
114
- ToUnicode: unicodeCMapRef,
115
- });
116
-
117
- if (ref) {
118
- context.assign(ref, fontDict);
119
- return ref;
120
- } else {
121
- return context.register(fontDict);
122
- }
123
- }
124
-
125
- protected isCFF(): boolean {
126
- return this.font.cff;
127
- }
128
-
129
- protected async embedCIDFontDict(context: PDFContext): Promise<PDFRef> {
130
- const fontDescriptorRef = await this.embedFontDescriptor(context);
131
-
132
- const cidFontDict = context.obj({
133
- Type: 'Font',
134
- Subtype: this.isCFF() ? 'CIDFontType0' : 'CIDFontType2',
135
- CIDToGIDMap: 'Identity',
136
- BaseFont: this.baseFontName,
137
- CIDSystemInfo: {
138
- Registry: PDFString.of('Adobe'),
139
- Ordering: PDFString.of('Identity'),
140
- Supplement: 0,
141
- },
142
- FontDescriptor: fontDescriptorRef,
143
- W: this.computeWidths(),
144
- });
145
-
146
- return context.register(cidFontDict);
147
- }
148
-
149
- protected async embedFontDescriptor(context: PDFContext): Promise<PDFRef> {
150
- const fontStreamRef = await this.embedFontStream(context);
151
-
152
- const { scale } = this;
153
- const { italicAngle, ascent, descent, capHeight, xHeight } = this.font;
154
- const { minX, minY, maxX, maxY } = this.font.bbox;
155
-
156
- const fontDescriptor = context.obj({
157
- Type: 'FontDescriptor',
158
- FontName: this.baseFontName,
159
- Flags: deriveFontFlags(this.font),
160
- FontBBox: [minX * scale, minY * scale, maxX * scale, maxY * scale],
161
- ItalicAngle: italicAngle,
162
- Ascent: ascent * scale,
163
- Descent: descent * scale,
164
- CapHeight: (capHeight || ascent) * scale,
165
- XHeight: (xHeight || 0) * scale,
166
-
167
- // Not sure how to compute/find this, nor is anybody else really:
168
- // https://stackoverflow.com/questions/35485179/stemv-value-of-the-truetype-font
169
- StemV: 0,
170
-
171
- [this.isCFF() ? 'FontFile3' : 'FontFile2']: fontStreamRef,
172
- });
173
-
174
- return context.register(fontDescriptor);
175
- }
176
-
177
- protected async serializeFont(): Promise<Uint8Array> {
178
- return this.fontData;
179
- }
180
-
181
- protected async embedFontStream(context: PDFContext): Promise<PDFRef> {
182
- const fontStream = context.flateStream(await this.serializeFont(), {
183
- Subtype: this.isCFF() ? 'CIDFontType0C' : undefined,
184
- });
185
- return context.register(fontStream);
186
- }
187
-
188
- protected embedUnicodeCmap(context: PDFContext): PDFRef {
189
- const cmap = createCmap(this.glyphCache.access(), this.glyphId.bind(this));
190
- const cmapStream = context.flateStream(cmap);
191
- return context.register(cmapStream);
192
- }
193
-
194
- protected glyphId(glyph?: Glyph): number {
195
- return glyph ? glyph.id : -1;
196
- }
197
-
198
- protected computeWidths(): (number | number[])[] {
199
- const glyphs = this.glyphCache.access();
200
-
201
- const widths: (number | number[])[] = [];
202
- let currSection: number[] = [];
203
-
204
- for (let idx = 0, len = glyphs.length; idx < len; idx++) {
205
- const currGlyph = glyphs[idx];
206
- const prevGlyph = glyphs[idx - 1];
207
-
208
- const currGlyphId = this.glyphId(currGlyph);
209
- const prevGlyphId = this.glyphId(prevGlyph);
210
-
211
- if (idx === 0) {
212
- widths.push(currGlyphId);
213
- } else if (currGlyphId - prevGlyphId !== 1) {
214
- widths.push(currSection);
215
- widths.push(currGlyphId);
216
- currSection = [];
217
- }
218
-
219
- currSection.push(currGlyph.advanceWidth * this.scale);
220
- }
221
-
222
- widths.push(currSection);
223
-
224
- return widths;
225
- }
226
-
227
- private allGlyphsInFontSortedById = (): Glyph[] => {
228
- const glyphs: Glyph[] = Array(this.font.characterSet.length);
229
- for (let idx = 0, len = glyphs.length; idx < len; idx++) {
230
- const codePoint = this.font.characterSet[idx];
231
- glyphs[idx] = this.font.glyphForCodePoint(codePoint);
232
- }
233
- return sortedUniq(glyphs.sort(byAscendingId), (g) => g.id);
234
- };
235
- }
236
-
237
- export default CustomFontEmbedder;
@@ -1,89 +0,0 @@
1
- import { Font, Fontkit, Glyph, Subset, TypeFeatures } from '../../types/fontkit';
2
-
3
- import CustomFontEmbedder from './CustomFontEmbedder';
4
- import PDFHexString from '../objects/PDFHexString';
5
- import { Cache, mergeUint8Arrays, toHexStringOfMinLength } from '../../utils';
6
-
7
- /**
8
- * A note of thanks to the developers of https://github.com/foliojs/pdfkit, as
9
- * this class borrows from:
10
- * https://github.com/devongovett/pdfkit/blob/e71edab0dd4657b5a767804ba86c94c58d01fbca/lib/image/jpeg.coffee
11
- */
12
- class CustomFontSubsetEmbedder extends CustomFontEmbedder {
13
- static async for(
14
- fontkit: Fontkit,
15
- fontData: Uint8Array,
16
- customFontName?: string,
17
- fontFeatures?: TypeFeatures,
18
- ) {
19
- const font = fontkit.create(fontData);
20
- return new CustomFontSubsetEmbedder(font, fontData, customFontName, fontFeatures);
21
- }
22
-
23
- private readonly subset: Subset;
24
- private readonly glyphs: Glyph[];
25
- private readonly glyphIdMap: Map<number, number>;
26
-
27
- private constructor(
28
- font: Font,
29
- fontData: Uint8Array,
30
- customFontName?: string,
31
- fontFeatures?: TypeFeatures,
32
- ) {
33
- super(font, fontData, customFontName, fontFeatures);
34
-
35
- this.subset = this.font.createSubset();
36
- this.glyphs = [];
37
- this.glyphCache = Cache.populatedBy(() => this.glyphs);
38
- this.glyphIdMap = new Map();
39
- }
40
-
41
- encodeText(text: string): PDFHexString {
42
- const { glyphs } = this.font.layout(text, this.fontFeatures);
43
- const hexCodes = Array(glyphs.length);
44
-
45
- for (let idx = 0, len = glyphs.length; idx < len; idx++) {
46
- const glyph = glyphs[idx];
47
- const subsetGlyphId = this.subset.includeGlyph(glyph);
48
-
49
- this.glyphs[subsetGlyphId - 1] = glyph;
50
- this.glyphIdMap.set(glyph.id, subsetGlyphId);
51
-
52
- hexCodes[idx] = toHexStringOfMinLength(subsetGlyphId, 4);
53
- }
54
-
55
- this.glyphCache.invalidate();
56
- return PDFHexString.of(hexCodes.join(''));
57
- }
58
-
59
- protected isCFF(): boolean {
60
- return (this.subset as any).cff;
61
- }
62
-
63
- protected glyphId(glyph?: Glyph): number {
64
- return glyph ? this.glyphIdMap.get(glyph.id)! : -1;
65
- }
66
-
67
- protected serializeFont(): Promise<Uint8Array> {
68
- return new Promise((resolve, reject) => {
69
- if ('encodeStream' in this.subset) {
70
- const parts: Uint8Array[] = [];
71
- this.subset
72
- .encodeStream()
73
- .on('data', (bytes) => parts.push(bytes))
74
- .on('end', () => resolve(mergeUint8Arrays(parts)))
75
- .on('error' as any, (err) => reject(err));
76
- } else if ('encode' in this.subset) {
77
- try {
78
- resolve(this.subset.encode());
79
- } catch (err) {
80
- reject(err);
81
- }
82
- } else {
83
- reject(new Error('Subset does not have an encode method'));
84
- }
85
- });
86
- }
87
- }
88
-
89
- export default CustomFontSubsetEmbedder;