modern-pdf-lib 0.26.0 → 0.28.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 (110) hide show
  1. package/README.md +16 -3
  2. package/dist/{batchOptimize-C1W3O68Q.cjs → batchOptimize-CXC9gNqD.cjs} +55 -55
  3. package/dist/{batchOptimize-BCJEEN8J.mjs → batchOptimize-CjLGD5ie.mjs} +25 -25
  4. package/dist/{bridge-DMEuGtfn.cjs → bridge-ByvzPu5h.cjs} +29 -31
  5. package/dist/{bridge-DaS-gzEd.mjs → bridge-ZD6O6QQa.mjs} +4 -5
  6. package/dist/browser.cjs +245 -154
  7. package/dist/browser.d.cts +166 -166
  8. package/dist/browser.d.cts.map +1 -1
  9. package/dist/browser.d.mts +166 -166
  10. package/dist/browser.d.mts.map +1 -1
  11. package/dist/browser.mjs +15 -19
  12. package/dist/cli/index.cjs +7 -7
  13. package/dist/cli/index.mjs +8 -8
  14. package/dist/{compressionAnalysis-CwknBtqx.mjs → compressionAnalysis-BgKy45pA.mjs} +55 -69
  15. package/dist/{compressionAnalysis-Ch7t-HXn.d.mts → compressionAnalysis-CDOp_vPr.d.mts} +136 -136
  16. package/dist/compressionAnalysis-CDOp_vPr.d.mts.map +1 -0
  17. package/dist/{compressionAnalysis-B-FPzgzw.cjs → compressionAnalysis-Djv-Zvcd.cjs} +85 -99
  18. package/dist/{compressionAnalysis-Dgv1TtHJ.d.cts → compressionAnalysis-UfmonqbM.d.cts} +136 -136
  19. package/dist/compressionAnalysis-UfmonqbM.d.cts.map +1 -0
  20. package/dist/create.cjs +21 -23
  21. package/dist/create.d.cts +2 -2
  22. package/dist/create.d.mts +2 -2
  23. package/dist/create.mjs +3 -5
  24. package/dist/{deduplicateImages-DIon68zB.mjs → deduplicateImages-BTCyAPfJ.mjs} +4 -5
  25. package/dist/{deduplicateImages-cKsnD6Ep.cjs → deduplicateImages-CaGgaqyS.cjs} +14 -15
  26. package/dist/{fieldAppearance-C8PoLFSc.d.mts → fieldAppearance-Df1262CT.d.cts} +44 -44
  27. package/dist/fieldAppearance-Df1262CT.d.cts.map +1 -0
  28. package/dist/{fieldAppearance-CdiGFG5e.d.cts → fieldAppearance-_CZdoUCD.d.mts} +44 -44
  29. package/dist/fieldAppearance-_CZdoUCD.d.mts.map +1 -0
  30. package/dist/fontEmbed-DGiZS0h2.d.cts +677 -0
  31. package/dist/fontEmbed-DGiZS0h2.d.cts.map +1 -0
  32. package/dist/fontEmbed-DtA_riGC.d.mts +677 -0
  33. package/dist/fontEmbed-DtA_riGC.d.mts.map +1 -0
  34. package/dist/forms.cjs +3 -4
  35. package/dist/forms.d.cts +2 -2
  36. package/dist/forms.d.mts +2 -2
  37. package/dist/forms.mjs +2 -3
  38. package/dist/{grayscaleDetect-C6kFF3dk.mjs → grayscaleDetect-6GJrgBRT.mjs} +3 -3
  39. package/dist/{grayscaleDetect-C2m-eEXR.cjs → grayscaleDetect-DAUqxjgR.cjs} +13 -14
  40. package/dist/{imageExtract-zEb1gnkb.cjs → imageExtract-DT50Hp_g.cjs} +13 -14
  41. package/dist/{imageExtract-Dnk_Ssv7.mjs → imageExtract-Dapir-ux.mjs} +3 -4
  42. package/dist/index-C1lZe66f.d.mts +8682 -0
  43. package/dist/index-C1lZe66f.d.mts.map +1 -0
  44. package/dist/index-D1SvXWSI.d.cts +8682 -0
  45. package/dist/index-D1SvXWSI.d.cts.map +1 -0
  46. package/dist/index.cjs +245 -153
  47. package/dist/index.d.cts +7 -7
  48. package/dist/index.d.mts +7 -7
  49. package/dist/index.mjs +14 -17
  50. package/dist/{layout-DQh05VP-.cjs → layout-C4vbTlBW.cjs} +184 -134
  51. package/dist/{layout-CrqeJBMI.mjs → layout-lO4x64kY.mjs} +50 -12
  52. package/dist/{loader-CVB-c_3Z.mjs → loader-B1Ix7ozU.mjs} +248 -12
  53. package/dist/{loader-DYCH3n7d.cjs → loader-DR7H0XOf.cjs} +332 -66
  54. package/dist/parse.cjs +7 -8
  55. package/dist/parse.d.cts +3 -3
  56. package/dist/parse.d.mts +3 -3
  57. package/dist/parse.mjs +6 -7
  58. package/dist/pdfDocument-CH2E4UCc.d.mts +5160 -0
  59. package/dist/pdfDocument-CH2E4UCc.d.mts.map +1 -0
  60. package/dist/{pdfDocument-D9uYNSb-.cjs → pdfDocument-C_7mrBCL.cjs} +22409 -11624
  61. package/dist/pdfDocument-CzOipXnw.d.cts +5160 -0
  62. package/dist/pdfDocument-CzOipXnw.d.cts.map +1 -0
  63. package/dist/{pdfDocument-D7aFSQEY.mjs → pdfDocument-DRbT6HZw.mjs} +10830 -855
  64. package/dist/{pdfForm-BpqDGp29.cjs → pdfForm-BVS_do95.cjs} +112 -107
  65. package/dist/pdfForm-Ca86NDWn.d.cts +897 -0
  66. package/dist/pdfForm-Ca86NDWn.d.cts.map +1 -0
  67. package/dist/pdfForm-Ca86NDWn.d.mts +897 -0
  68. package/dist/pdfForm-Ca86NDWn.d.mts.map +1 -0
  69. package/dist/{pdfForm-C3mC9FoQ.mjs → pdfForm-CfLnlsj-.mjs} +22 -17
  70. package/dist/{pdfObjects-1veop1_d.cjs → pdfObjects-BcPlSI0a.cjs} +62 -53
  71. package/dist/{pdfObjects-uEsWlfzU.mjs → pdfObjects-CB7TEdbW.mjs} +12 -2
  72. package/dist/rolldown-runtime-ak5kbic3.cjs +18 -0
  73. package/dist/{src-lFqJHb1C.cjs → src-C-IDXuvi.cjs} +8692 -1916
  74. package/dist/{src-QZWP21qF.mjs → src-DJaD-bJ2.mjs} +7278 -982
  75. package/dist/{streamDecode-Bj568Nc9.mjs → streamDecode-BamENT3k.mjs} +129 -150
  76. package/dist/{streamDecode-CvgErkFu.cjs → streamDecode-DcaZz309.cjs} +139 -160
  77. package/package.json +25 -22
  78. package/dist/compressionAnalysis-Ch7t-HXn.d.mts.map +0 -1
  79. package/dist/compressionAnalysis-Dgv1TtHJ.d.cts.map +0 -1
  80. package/dist/fflateAdapter-DuNiByKx.mjs +0 -196
  81. package/dist/fflateAdapter-LTAeAhaD.cjs +0 -207
  82. package/dist/fieldAppearance-C8PoLFSc.d.mts.map +0 -1
  83. package/dist/fieldAppearance-CdiGFG5e.d.cts.map +0 -1
  84. package/dist/fontEmbed-3YhUPLFj.d.cts +0 -659
  85. package/dist/fontEmbed-3YhUPLFj.d.cts.map +0 -1
  86. package/dist/fontEmbed-DlVnVCZU.d.mts +0 -659
  87. package/dist/fontEmbed-DlVnVCZU.d.mts.map +0 -1
  88. package/dist/fontSubset-5SLWMmEw.cjs +0 -518
  89. package/dist/fontSubset-BGFDIMmT.mjs +0 -495
  90. package/dist/index-B4S61WjK.d.mts +0 -6507
  91. package/dist/index-B4S61WjK.d.mts.map +0 -1
  92. package/dist/index-xfJP6Ycm.d.cts +0 -6507
  93. package/dist/index-xfJP6Ycm.d.cts.map +0 -1
  94. package/dist/libdeflateWasm-CcA1W04G.mjs +0 -220
  95. package/dist/libdeflateWasm-DLw-I1CY.cjs +0 -237
  96. package/dist/pdfCatalog-Bqq4FiLn.cjs +0 -174
  97. package/dist/pdfCatalog-CnKMAtIo.mjs +0 -139
  98. package/dist/pdfDocument-Bc_vAO74.d.cts +0 -4758
  99. package/dist/pdfDocument-Bc_vAO74.d.cts.map +0 -1
  100. package/dist/pdfDocument-Bi-NoyXv.d.mts +0 -4758
  101. package/dist/pdfDocument-Bi-NoyXv.d.mts.map +0 -1
  102. package/dist/pdfForm-BiyNtYem.d.mts +0 -905
  103. package/dist/pdfForm-BiyNtYem.d.mts.map +0 -1
  104. package/dist/pdfForm-SOXJ72LW.d.cts +0 -905
  105. package/dist/pdfForm-SOXJ72LW.d.cts.map +0 -1
  106. package/dist/pdfPage-BJIE5hc6.mjs +0 -8180
  107. package/dist/pdfPage-C_tjEjj1.cjs +0 -8893
  108. package/dist/pngEmbed-CGi7cym7.mjs +0 -552
  109. package/dist/pngEmbed-CTn9IeNB.cjs +0 -563
  110. package/dist/rolldown-runtime-CKhH4XqG.cjs +0 -24
@@ -1,659 +0,0 @@
1
- import { at as FontRef, lt as PdfPage, n as PdfDocument, st as PageSize } from "./pdfDocument-Bc_vAO74.cjs";
2
- import { b as PdfNumber, v as PdfName, x as PdfObject } from "./pdfForm-SOXJ72LW.cjs";
3
-
4
- //#region src/utils/pdfValueHelpers.d.ts
5
- /**
6
- * Create a {@link PdfName} from a string.
7
- *
8
- * @param value The name value (with or without leading `/`).
9
- */
10
- declare function asPDFName(value: string): PdfName;
11
- /**
12
- * Create a {@link PdfNumber} from a numeric value.
13
- *
14
- * @param value The number.
15
- */
16
- declare function asPDFNumber(value: number): PdfNumber;
17
- /**
18
- * Extract a numeric value from a {@link PdfObject}.
19
- *
20
- * Returns `undefined` if the object is not a PdfNumber.
21
- *
22
- * @param obj The PDF object to inspect.
23
- */
24
- declare function asNumber(obj: PdfObject): number | undefined;
25
- //#endregion
26
- //#region src/core/pageManipulation.d.ts
27
- /**
28
- * A rectangular crop box defined by its coordinates.
29
- *
30
- * All values are in PDF points (1/72 of an inch).
31
- */
32
- interface CropBox {
33
- /** Lower-left x coordinate. */
34
- readonly x: number;
35
- /** Lower-left y coordinate. */
36
- readonly y: number;
37
- /** Width of the crop box. */
38
- readonly width: number;
39
- /** Height of the crop box. */
40
- readonly height: number;
41
- }
42
- /**
43
- * Insert a new blank page into the document at the specified position.
44
- *
45
- * All existing pages at `index` and beyond are shifted to make room.
46
- *
47
- * @param doc The PdfDocument to modify.
48
- * @param index Zero-based position at which to insert the page.
49
- * Must be in the range `[0, pageCount]`.
50
- * @param size Optional page size. Defaults to A4.
51
- * @returns The newly created PdfPage.
52
- *
53
- * @example
54
- * ```ts
55
- * import { createPdf, insertPage, PageSizes } from 'modern-pdf-lib';
56
- *
57
- * const doc = createPdf();
58
- * doc.addPage();
59
- * const newPage = insertPage(doc, 0, PageSizes.Letter); // insert at front
60
- * ```
61
- */
62
- declare function insertPage(doc: PdfDocument, index: number, size?: PageSize): PdfPage;
63
- /**
64
- * Remove a page from the document by its zero-based index.
65
- *
66
- * @param doc The PdfDocument to modify.
67
- * @param index Zero-based index of the page to remove.
68
- * @throws RangeError if the index is out of bounds.
69
- *
70
- * @example
71
- * ```ts
72
- * removePage(doc, 0); // Remove the first page
73
- * ```
74
- */
75
- declare function removePage(doc: PdfDocument, index: number): void;
76
- /**
77
- * Move a page from one position to another within the document.
78
- *
79
- * The page at `fromIndex` is removed and then inserted at `toIndex`
80
- * (computed after the removal).
81
- *
82
- * @param doc The PdfDocument to modify.
83
- * @param fromIndex Current zero-based index of the page to move.
84
- * @param toIndex Target zero-based index. Must be in range
85
- * `[0, pageCount - 1]` after removal.
86
- * @throws RangeError if either index is out of bounds.
87
- *
88
- * @example
89
- * ```ts
90
- * movePage(doc, 2, 0); // Move page 2 to the front
91
- * ```
92
- */
93
- declare function movePage(doc: PdfDocument, fromIndex: number, toIndex: number): void;
94
- /**
95
- * Rotate a page by the specified angle.
96
- *
97
- * The angle is cumulative with any existing rotation set on the page.
98
- * The page's `/Rotate` entry in the page dictionary will be set when
99
- * the document is saved.
100
- *
101
- * @param doc The PdfDocument to modify.
102
- * @param index Zero-based index of the page to rotate.
103
- * @param angle Rotation angle in degrees. Must be a multiple of 90.
104
- * Common values: 90, 180, 270, -90.
105
- * @throws RangeError if the index is out of bounds.
106
- * @throws Error if the angle is not a multiple of 90.
107
- *
108
- * @example
109
- * ```ts
110
- * rotatePage(doc, 0, 90); // Rotate first page 90 degrees clockwise
111
- * ```
112
- */
113
- declare function rotatePage(doc: PdfDocument, index: number, angle: number): void;
114
- /**
115
- * Set a crop box on a page.
116
- *
117
- * The crop box defines the visible region of the page when displayed
118
- * or printed. It defaults to the media box if not set.
119
- *
120
- * @param doc The PdfDocument to modify.
121
- * @param index Zero-based index of the page.
122
- * @param cropBox The crop box rectangle.
123
- * @throws RangeError if the index is out of bounds.
124
- *
125
- * @example
126
- * ```ts
127
- * cropPage(doc, 0, { x: 50, y: 50, width: 495, height: 742 });
128
- * ```
129
- */
130
- declare function cropPage(doc: PdfDocument, index: number, cropBox: CropBox): void;
131
- /**
132
- * Get the size of a page.
133
- *
134
- * @param doc The PdfDocument.
135
- * @param index Zero-based page index.
136
- * @returns A `{ width, height }` object in PDF points.
137
- */
138
- declare function getPageSize(doc: PdfDocument, index: number): {
139
- width: number;
140
- height: number;
141
- };
142
- /**
143
- * Resize a page by setting its media box.
144
- *
145
- * Note: This changes the page dimensions but does not scale existing
146
- * content. Content that was drawn at coordinates beyond the new
147
- * dimensions may be clipped.
148
- *
149
- * @param doc The PdfDocument to modify.
150
- * @param index Zero-based page index.
151
- * @param size New page size.
152
- */
153
- declare function resizePage(doc: PdfDocument, index: number, size: PageSize): void;
154
- /**
155
- * Reverse the page order of the entire document.
156
- *
157
- * @param doc The PdfDocument to modify.
158
- */
159
- declare function reversePages(doc: PdfDocument): void;
160
- /**
161
- * Remove multiple pages at once, given their zero-based indices.
162
- *
163
- * Indices are processed in descending order to avoid shifting issues.
164
- *
165
- * @param doc The PdfDocument to modify.
166
- * @param indices Array of zero-based page indices to remove.
167
- * @throws RangeError if any index is out of bounds.
168
- */
169
- declare function removePages(doc: PdfDocument, indices: number[]): void;
170
- /**
171
- * Rotate all pages in the document by the specified angle.
172
- *
173
- * @param doc The PdfDocument to modify.
174
- * @param angle Rotation angle in degrees (must be a multiple of 90).
175
- */
176
- declare function rotateAllPages(doc: PdfDocument, angle: number): void;
177
- //#endregion
178
- //#region src/core/documentMerge.d.ts
179
- /**
180
- * Copy pages from a source document to a target document.
181
- *
182
- * @param sourceDoc The source document.
183
- * @param targetDoc The target document.
184
- * @param indices Zero-based page indices to copy from the source.
185
- * @returns Array of new PdfPage objects added to the target.
186
- */
187
- declare function copyPages(sourceDoc: PdfDocument, targetDoc: PdfDocument, indices: number[]): PdfPage[];
188
- /**
189
- * Merge multiple PDF documents into a single document.
190
- *
191
- * Pages from each source document are appended in order. Resources
192
- * are deduplicated: if two source documents contain the same font file
193
- * (byte-identical), only one copy is kept in the merged output.
194
- *
195
- * @param documents Array of PdfDocument objects to merge.
196
- * @returns A new PdfDocument containing all pages.
197
- *
198
- * @example
199
- * ```ts
200
- * import { PdfDocument, mergePdfs } from 'modern-pdf-lib';
201
- *
202
- * const doc1 = await PdfDocument.load(bytes1);
203
- * const doc2 = await PdfDocument.load(bytes2);
204
- * const merged = await mergePdfs([doc1, doc2]);
205
- * const mergedBytes = await merged.save();
206
- * ```
207
- */
208
- declare function mergePdfs(documents: PdfDocument[]): Promise<PdfDocument>;
209
- /**
210
- * A page range for splitting, specified as `[startIndex, endIndex]`.
211
- * Both indices are zero-based and inclusive.
212
- *
213
- * For example, `[0, 2]` means pages 0, 1, and 2.
214
- */
215
- type PageRange = [start: number, end: number];
216
- /**
217
- * Split a PDF document into multiple documents by page ranges.
218
- *
219
- * Each range produces a new PdfDocument containing only the pages
220
- * in that range. Pages can appear in multiple ranges (they are
221
- * independently copied).
222
- *
223
- * @param document The source document to split.
224
- * @param ranges Array of `[start, end]` ranges (zero-based, inclusive).
225
- * @returns Array of new PdfDocument objects, one per range.
226
- *
227
- * @example
228
- * ```ts
229
- * import { PdfDocument, splitPdf } from 'modern-pdf-lib';
230
- *
231
- * const doc = await PdfDocument.load(bytes);
232
- * // Split into first 3 pages and remaining pages
233
- * const [part1, part2] = await splitPdf(doc, [[0, 2], [3, doc.getPageCount() - 1]]);
234
- * ```
235
- */
236
- declare function splitPdf(document: PdfDocument, ranges: PageRange[]): Promise<PdfDocument[]>;
237
- //#endregion
238
- //#region src/core/layout.d.ts
239
- interface LayoutMultilineOptions {
240
- font: FontRef;
241
- fontSize: number;
242
- maxWidth: number;
243
- lineHeight?: number | undefined;
244
- wordBreaks?: string[] | undefined;
245
- }
246
- interface LayoutMultilineResult {
247
- lines: Array<{
248
- text: string;
249
- width: number;
250
- }>;
251
- height: number;
252
- }
253
- /**
254
- * Break text into lines that fit within `maxWidth`, measuring each line's
255
- * width. Explicit newlines (`\n`) are always honoured.
256
- *
257
- * The returned `height` is the total vertical extent: one line's ascent
258
- * plus `(n-1) * lineHeight`.
259
- */
260
- declare function layoutMultilineText(text: string, options: LayoutMultilineOptions): LayoutMultilineResult;
261
- interface LayoutCombedOptions {
262
- font: FontRef;
263
- fontSize: number;
264
- cellCount: number;
265
- cellWidth: number;
266
- }
267
- /**
268
- * Layout text into evenly-spaced cells for combed text fields.
269
- *
270
- * Each character is centred within its cell. Characters beyond
271
- * `cellCount` are silently truncated.
272
- */
273
- declare function layoutCombedText(text: string, options: LayoutCombedOptions): Array<{
274
- char: string;
275
- x: number;
276
- width: number;
277
- }>;
278
- interface ComputeFontSizeOptions {
279
- font: FontRef;
280
- maxWidth: number;
281
- maxHeight?: number | undefined;
282
- lineHeight?: number | undefined;
283
- minSize?: number | undefined;
284
- maxSize?: number | undefined;
285
- wordBreaks?: string[] | undefined;
286
- }
287
- /**
288
- * Compute the largest font size (in points) at which `text` fits within
289
- * the given width (and optionally height) constraints.
290
- *
291
- * Uses binary search between `minSize` (default 4) and `maxSize`
292
- * (default 500), converging to within 0.1 pt.
293
- */
294
- declare function computeFontSize(text: string, options: ComputeFontSizeOptions): number;
295
- /**
296
- * Options for {@link layoutSinglelineText}.
297
- */
298
- interface LayoutSinglelineOptions {
299
- /** The font to use for measurement. */
300
- font: FontRef;
301
- /** Font size in points. */
302
- fontSize: number;
303
- /** Bounds width for alignment (optional). */
304
- bounds?: {
305
- width: number;
306
- height: number;
307
- } | undefined;
308
- /** Text alignment within bounds. Default: 'left'. */
309
- alignment?: 0 | 1 | 2 | undefined;
310
- }
311
- /**
312
- * Result of {@link layoutSinglelineText}.
313
- */
314
- interface LayoutSinglelineResult {
315
- /** The text line with its measured width. */
316
- line: {
317
- text: string;
318
- width: number;
319
- height: number;
320
- };
321
- /** The x offset after alignment (0 for left-aligned). */
322
- x: number;
323
- /** The y offset for the text baseline. */
324
- y: number;
325
- }
326
- /**
327
- * Layout a single line of text with optional alignment within bounds.
328
- *
329
- * Unlike {@link layoutMultilineText}, this does not perform any wrapping.
330
- * It simply measures the text, computes alignment offsets, and returns
331
- * the positioned line.
332
- *
333
- * @param text The text to lay out (single line, no newlines).
334
- * @param options Font, size, bounds, alignment.
335
- * @returns The measured line and its position offsets.
336
- */
337
- declare function layoutSinglelineText(text: string, options: LayoutSinglelineOptions): LayoutSinglelineResult;
338
- //#endregion
339
- //#region src/assets/font/fontMetrics.d.ts
340
- /**
341
- * @module assets/font/fontMetrics
342
- *
343
- * Pure TypeScript glyph metrics extraction from TrueType / OpenType fonts.
344
- * Parses the binary TTF tables (head, hhea, OS/2, cmap, hmtx, maxp, name,
345
- * post) using `DataView` to extract the data needed for text measurement
346
- * and PDF font embedding.
347
- *
348
- * No external dependencies. No Buffer — uses Uint8Array and DataView
349
- * exclusively.
350
- *
351
- * Reference: Apple TrueType Reference, OpenType spec §§ head, hhea,
352
- * hmtx, cmap, OS/2, maxp, name, post.
353
- */
354
- /**
355
- * Complete font metrics extracted from a TrueType / OpenType font file.
356
- *
357
- * All values are in font design units (typically 1000 or 2048 per em)
358
- * unless otherwise noted.
359
- */
360
- interface FontMetrics {
361
- /** Units per em square (from `head` table). */
362
- readonly unitsPerEm: number;
363
- /** Typographic ascender (from `OS/2` sTypoAscender, or `hhea` ascent). */
364
- readonly ascender: number;
365
- /** Typographic descender — negative value (from `OS/2` or `hhea`). */
366
- readonly descender: number;
367
- /** Line gap (from `OS/2` sTypoLineGap, or `hhea` lineGap). */
368
- readonly lineGap: number;
369
- /** Cap height (from `OS/2` sCapHeight, or estimated). */
370
- readonly capHeight: number;
371
- /** x-height (from `OS/2` sxHeight, or estimated). */
372
- readonly xHeight: number;
373
- /** Italic angle in degrees (from `post` table). */
374
- readonly italicAngle: number;
375
- /** Number of glyphs in the font (from `maxp`). */
376
- readonly numGlyphs: number;
377
- /** Default advance width for glyphs not in {@link glyphWidths}. */
378
- readonly defaultWidth: number;
379
- /**
380
- * Map of glyph ID to advance width in font design units.
381
- * Extracted from the `hmtx` table.
382
- */
383
- readonly glyphWidths: Map<number, number>;
384
- /**
385
- * Map of Unicode codepoint to glyph ID. Extracted from the `cmap`
386
- * table (platform 3 / encoding 1 — Windows BMP, or platform 0).
387
- */
388
- readonly cmapTable: Map<number, number>;
389
- /** Font bounding box [xMin, yMin, xMax, yMax] from `head` table. */
390
- readonly bbox: readonly [number, number, number, number];
391
- /** StemV estimate for PDF FontDescriptor (or 0 if unknown). */
392
- readonly stemV: number;
393
- /** Font flags for PDF FontDescriptor. */
394
- readonly flags: number;
395
- /** Font family name from the `name` table, if available. */
396
- readonly familyName: string;
397
- /** PostScript name from the `name` table, if available. */
398
- readonly postScriptName: string;
399
- }
400
- /**
401
- * Extract font metrics from raw TrueType / OpenType font bytes.
402
- *
403
- * Parses the `head`, `hhea`, `hmtx`, `cmap`, `maxp`, `OS/2`, `name`,
404
- * and `post` tables to produce a complete {@link FontMetrics} object.
405
- *
406
- * @param fontData - The raw TTF or OTF file as a Uint8Array.
407
- * @returns Parsed font metrics.
408
- * @throws If required tables are missing or the data is corrupt.
409
- */
410
- declare function extractMetrics(fontData: Uint8Array): FontMetrics;
411
- //#endregion
412
- //#region src/assets/font/fontSubset.d.ts
413
- /**
414
- * @module assets/font/fontSubset
415
- *
416
- * Font subsetting — removes unused glyphs from a TrueType font to
417
- * reduce file size. Offers WASM-accelerated subsetting with a pure
418
- * JS subsetter as the default.
419
- *
420
- * The JS subsetter replaces unused glyph outlines with zero-length
421
- * entries in the `glyf` table, preserving all glyph ID slots so that
422
- * `CIDToGIDMap /Identity` continues to work without changes to the
423
- * PDF embedding pipeline. Composite glyph dependencies are resolved
424
- * automatically.
425
- *
426
- * Also builds CMap streams for the subset encoding, mapping CIDs to
427
- * Unicode codepoints (required for PDF text extraction / copy-paste).
428
- *
429
- * No Buffer — uses Uint8Array exclusively.
430
- * No fs — no file system access.
431
- * No require() — ESM import only.
432
- */
433
- /**
434
- * The result of subsetting a font.
435
- */
436
- interface SubsetResult {
437
- /** The subsetted font file bytes (TrueType). */
438
- readonly fontData: Uint8Array;
439
- /**
440
- * Mapping from new glyph ID (sequential, starting at 0) to original
441
- * glyph ID. Index = new GID, value = old GID.
442
- */
443
- readonly newToOldGid: readonly number[];
444
- /**
445
- * Mapping from original glyph ID to new glyph ID.
446
- * Only contains entries for glyphs that were retained.
447
- */
448
- readonly oldToNewGid: ReadonlyMap<number, number>;
449
- }
450
- /**
451
- * A CMap mapping from CIDs (Character IDs, which correspond to new GIDs
452
- * in the subset) to Unicode codepoints.
453
- */
454
- interface SubsetCmap {
455
- /**
456
- * The CMap as a PDF stream body string, ready to be wrapped in a
457
- * `/ToUnicode` stream object.
458
- */
459
- readonly cmapStream: string;
460
- /**
461
- * Map from new GID to the Unicode codepoint(s) it represents.
462
- * For most glyphs this is a single codepoint; for ligatures it may
463
- * be multiple.
464
- */
465
- readonly cidToUnicode: ReadonlyMap<number, number[]>;
466
- }
467
- //#endregion
468
- //#region src/assets/font/fontEmbed.d.ts
469
- /**
470
- * Represents a TrueType / OpenType font that has been loaded for
471
- * embedding in a PDF document.
472
- *
473
- * Tracks which glyphs have been used so that subsetting can be
474
- * performed at save time, and provides text measurement methods.
475
- *
476
- * Create via `PdfDocument.embedFont()`.
477
- */
478
- declare class EmbeddedFont {
479
- /** The raw font file bytes. */
480
- readonly fontData: Uint8Array;
481
- /** Extracted font metrics. */
482
- readonly metrics: FontMetrics;
483
- /** Set of glyph IDs that have been used (for subsetting). */
484
- private readonly usedGlyphs;
485
- /** @internal */
486
- constructor(fontData: Uint8Array, metrics: FontMetrics);
487
- /**
488
- * Compute the width of a text string at the given font size.
489
- *
490
- * This also records all glyph IDs used by the text for subsetting.
491
- *
492
- * @param text - The text string to measure.
493
- * @param fontSize - The font size in points.
494
- * @returns The total advance width in points.
495
- */
496
- widthOfTextAtSize(text: string, fontSize: number): number;
497
- /**
498
- * Compute the height of the font at the given size.
499
- *
500
- * Returns the distance from the descender to the ascender line,
501
- * which is the "em height" scaled to the font size.
502
- *
503
- * @param fontSize - The font size in points.
504
- * @returns The font height in points.
505
- */
506
- heightAtSize(fontSize: number): number;
507
- /**
508
- * Compute the ascender height at the given font size.
509
- *
510
- * @param fontSize - The font size in points.
511
- * @returns The ascender height in points (positive).
512
- */
513
- ascentAtSize(fontSize: number): number;
514
- /**
515
- * Compute the descender depth at the given font size.
516
- *
517
- * @param fontSize - The font size in points.
518
- * @returns The descender depth in points (negative).
519
- */
520
- descentAtSize(fontSize: number): number;
521
- /**
522
- * Compute the cap height at the given font size.
523
- *
524
- * @param fontSize - The font size in points.
525
- * @returns The cap height in points.
526
- */
527
- capHeightAtSize(fontSize: number): number;
528
- /**
529
- * Compute the line height (ascent - descent + lineGap) at size.
530
- *
531
- * @param fontSize - The font size in points.
532
- * @returns The default line height in points.
533
- */
534
- lineHeightAtSize(fontSize: number): number;
535
- /**
536
- * Mark a Unicode codepoint as used (records its glyph ID for subsetting).
537
- *
538
- * @param codepoint - The Unicode codepoint.
539
- */
540
- markCodepointUsed(codepoint: number): void;
541
- /**
542
- * Mark a glyph ID as used directly.
543
- *
544
- * @param glyphId - The glyph ID.
545
- */
546
- markGlyphUsed(glyphId: number): void;
547
- /**
548
- * Mark all codepoints in a text string as used.
549
- *
550
- * @param text - The text string.
551
- */
552
- markTextUsed(text: string): void;
553
- /**
554
- * Get the set of all glyph IDs that have been used.
555
- */
556
- getUsedGlyphs(): ReadonlySet<number>;
557
- /**
558
- * Encode a text string as hex-encoded CID bytes for use in PDF
559
- * content stream `Tj` / `TJ` operators.
560
- *
561
- * For a CIDFont Type 2 with Identity-H encoding, each character is
562
- * mapped to its glyph ID and encoded as a 2-byte big-endian value.
563
- *
564
- * @param text - The text to encode.
565
- * @returns Hex string (e.g. `"00480065006C006C006F"` for "Hello").
566
- */
567
- encodeText(text: string): string;
568
- /**
569
- * Build the complete set of PDF dictionary data needed to embed this
570
- * font. This performs subsetting (if WASM is available) and generates
571
- * all required dictionaries.
572
- *
573
- * Call this at document save time, after all text has been drawn.
574
- *
575
- * @returns The embedding result containing all PDF object data.
576
- */
577
- buildEmbedding(): FontEmbeddingResult;
578
- }
579
- /**
580
- * Data for the `/CIDSystemInfo` dictionary.
581
- */
582
- interface CIDSystemInfoData {
583
- readonly registry: string;
584
- readonly ordering: string;
585
- readonly supplement: number;
586
- }
587
- /**
588
- * Data for the `/FontDescriptor` dictionary.
589
- */
590
- interface FontDescriptorData {
591
- readonly fontName: string;
592
- readonly flags: number;
593
- readonly bbox: readonly [number, number, number, number];
594
- readonly italicAngle: number;
595
- readonly ascent: number;
596
- readonly descent: number;
597
- readonly capHeight: number;
598
- readonly stemV: number;
599
- }
600
- /**
601
- * Data for the CIDFont (DescendantFont) dictionary.
602
- */
603
- interface CIDFontData {
604
- readonly subtype: 'CIDFontType2';
605
- readonly baseFont: string;
606
- readonly cidSystemInfo: CIDSystemInfoData;
607
- /**
608
- * The /W (widths) array entries. Each entry is either:
609
- * - `[cid, [w1, w2, ...]]` — individual widths starting at `cid`
610
- * - `[cidFirst, cidLast, width]` — range with uniform width
611
- */
612
- readonly wArray: readonly WidthEntry[];
613
- readonly defaultWidth: number;
614
- }
615
- /**
616
- * An entry in the CIDFont /W array.
617
- *
618
- * Format 1: `{ start, widths }` — individual widths for consecutive CIDs.
619
- * Format 2: `{ first, last, width }` — range with uniform width.
620
- */
621
- type WidthEntry = {
622
- readonly kind: 'individual';
623
- readonly start: number;
624
- readonly widths: readonly number[];
625
- } | {
626
- readonly kind: 'range';
627
- readonly first: number;
628
- readonly last: number;
629
- readonly width: number;
630
- };
631
- /**
632
- * Data for the top-level /Font (Type 0) dictionary.
633
- */
634
- interface Type0FontData {
635
- readonly baseFont: string;
636
- readonly encoding: string;
637
- }
638
- /**
639
- * The complete result of building a font embedding.
640
- */
641
- interface FontEmbeddingResult {
642
- /** Top-level Type 0 font dictionary data. */
643
- readonly type0Font: Type0FontData;
644
- /** CIDFont (DescendantFont) dictionary data. */
645
- readonly cidFont: CIDFontData;
646
- /** FontDescriptor dictionary data. */
647
- readonly fontDescriptor: FontDescriptorData;
648
- /** ToUnicode CMap stream body. */
649
- readonly toUnicodeCmap: string;
650
- /** Subsetted (or full) font program bytes. */
651
- readonly fontProgram: Uint8Array;
652
- /** Raw subset result for advanced use. */
653
- readonly subsetResult: SubsetResult;
654
- /** Raw CMap result for advanced use. */
655
- readonly cmapResult: SubsetCmap;
656
- }
657
- //#endregion
658
- export { movePage as A, copyPages as C, cropPage as D, CropBox as E, rotateAllPages as F, rotatePage as I, asNumber as L, removePages as M, resizePage as N, getPageSize as O, reversePages as P, asPDFName as R, PageRange as S, splitPdf as T, LayoutSinglelineResult as _, FontEmbeddingResult as a, layoutMultilineText as b, SubsetCmap as c, extractMetrics as d, ComputeFontSizeOptions as f, LayoutSinglelineOptions as g, LayoutMultilineResult as h, FontDescriptorData as i, removePage as j, insertPage as k, SubsetResult as l, LayoutMultilineOptions as m, CIDSystemInfoData as n, Type0FontData as o, LayoutCombedOptions as p, EmbeddedFont as r, WidthEntry as s, CIDFontData as t, FontMetrics as u, computeFontSize as v, mergePdfs as w, layoutSinglelineText as x, layoutCombedText as y, asPDFNumber as z };
659
- //# sourceMappingURL=fontEmbed-3YhUPLFj.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fontEmbed-3YhUPLFj.d.cts","names":[],"sources":["../src/utils/pdfValueHelpers.ts","../src/core/pageManipulation.ts","../src/core/documentMerge.ts","../src/core/layout.ts","../src/assets/font/fontMetrics.ts","../src/assets/font/fontSubset.ts","../src/assets/font/fontEmbed.ts"],"mappings":";;;;;AAwBA;;;;iBATgB,SAAA,CAAU,KAAA,WAAgB,OAAA;AAoB1C;;;;;AAAA,iBAXgB,WAAA,CAAY,KAAA,WAAgB,SAAA;;;ACsF5C;;;;;iBD3EgB,QAAA,CAAS,GAAA,EAAK,SAAA;;;AAA9B;;;;;AAAA,UC2EiB,OAAA;;WAEN,CAAA;EAFM;EAAA,SAIN,CAAA;;WAEA,KAAA;EAJA;EAAA,SAMA,MAAA;AAAA;;;;AA2BX;;;;;;;;;;;;;;;;AAkCA;iBAlCgB,UAAA,CACd,GAAA,EAAK,WAAA,EACL,KAAA,UAC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