pdf-parser.js 5.2.25 → 5.2.27

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 (149) hide show
  1. package/dist/afm-widths.cjs +1 -1
  2. package/dist/afm-widths.js +1 -1
  3. package/dist/annotations.d.cts +2 -2
  4. package/dist/annotations.d.ts +2 -2
  5. package/dist/attachments.d.cts +2 -2
  6. package/dist/attachments.d.ts +2 -2
  7. package/dist/builtin-encoding.cjs +1 -1
  8. package/dist/builtin-encoding.d.cts +2 -2
  9. package/dist/builtin-encoding.d.ts +2 -2
  10. package/dist/builtin-encoding.js +1 -1
  11. package/dist/cff-bounds.cjs +31 -21
  12. package/dist/cff-bounds.d.cts +1 -1
  13. package/dist/cff-bounds.d.ts +1 -1
  14. package/dist/cff-bounds.js +31 -21
  15. package/dist/cff.d.cts +1 -1
  16. package/dist/cff.d.ts +1 -1
  17. package/dist/cmap-table.d.cts +1 -1
  18. package/dist/cmap-table.d.ts +1 -1
  19. package/dist/cmap.d.cts +1 -1
  20. package/dist/cmap.d.ts +1 -1
  21. package/dist/content-read.d.cts +1 -1
  22. package/dist/content-read.d.ts +1 -1
  23. package/dist/content-write.cjs +19 -13
  24. package/dist/content-write.d.cts +3 -3
  25. package/dist/content-write.d.ts +3 -3
  26. package/dist/content-write.js +19 -13
  27. package/dist/document.cjs +17 -11
  28. package/dist/document.d.cts +5 -5
  29. package/dist/document.d.ts +5 -5
  30. package/dist/document.js +17 -11
  31. package/dist/{embedded-font-BRhZfEN2.d.ts → embedded-font-ByD7ZiQS.d.ts} +4 -4
  32. package/dist/{embedded-font-DJUn9kMH.d.cts → embedded-font-DgVBedw6.d.cts} +4 -4
  33. package/dist/embedded-font-write.d.cts +2 -2
  34. package/dist/embedded-font-write.d.ts +2 -2
  35. package/dist/embedded-font.cjs +1 -1
  36. package/dist/embedded-font.d.cts +1 -1
  37. package/dist/embedded-font.d.ts +1 -1
  38. package/dist/embedded-font.js +1 -1
  39. package/dist/encoding.cjs +1 -1
  40. package/dist/encoding.js +1 -1
  41. package/dist/encrypt-write.d.cts +3 -3
  42. package/dist/encrypt-write.d.ts +3 -3
  43. package/dist/encrypt.d.cts +3 -3
  44. package/dist/encrypt.d.ts +3 -3
  45. package/dist/filters.cjs +6 -6
  46. package/dist/filters.d.cts +1 -1
  47. package/dist/filters.d.ts +1 -1
  48. package/dist/filters.js +6 -6
  49. package/dist/font-read.cjs +1 -1
  50. package/dist/font-read.d.cts +3 -3
  51. package/dist/font-read.d.ts +3 -3
  52. package/dist/font-read.js +1 -1
  53. package/dist/font-registry.d.cts +3 -3
  54. package/dist/font-registry.d.ts +3 -3
  55. package/dist/form.cjs +13 -8
  56. package/dist/form.d.cts +2 -2
  57. package/dist/form.d.ts +2 -2
  58. package/dist/form.js +13 -8
  59. package/dist/gdef-table.d.cts +3 -3
  60. package/dist/gdef-table.d.ts +3 -3
  61. package/dist/{glyf-vMGtP1pb.d.ts → glyf-Bv1katwK.d.ts} +4 -4
  62. package/dist/{glyf-nXC-IDRW.d.cts → glyf-DFyknMrW.d.cts} +4 -4
  63. package/dist/{glyf-contours-OSdG6Edr.d.ts → glyf-contours-B1PsI9oA.d.ts} +2 -2
  64. package/dist/{glyf-contours-zRQbj-Yp.d.cts → glyf-contours-NHBpgks-.d.cts} +2 -2
  65. package/dist/glyf-contours.d.cts +1 -1
  66. package/dist/glyf-contours.d.ts +1 -1
  67. package/dist/glyf.d.cts +1 -1
  68. package/dist/glyf.d.ts +1 -1
  69. package/dist/gsub-table.cjs +13 -9
  70. package/dist/gsub-table.js +13 -9
  71. package/dist/hmtx-table.d.cts +1 -1
  72. package/dist/hmtx-table.d.ts +1 -1
  73. package/dist/image/jbig2-generic.cjs +2 -2
  74. package/dist/image/jbig2-generic.js +2 -2
  75. package/dist/image/jpeg2000-codestream.cjs +17 -8
  76. package/dist/image/jpeg2000-codestream.js +17 -8
  77. package/dist/image/jpeg2000-tagtree.cjs +1 -1
  78. package/dist/image/jpeg2000-tagtree.js +1 -1
  79. package/dist/images-read.d.cts +2 -2
  80. package/dist/images-read.d.ts +2 -2
  81. package/dist/index.cjs +1 -1
  82. package/dist/index.d.cts +1 -1
  83. package/dist/index.d.ts +1 -1
  84. package/dist/index.js +1 -1
  85. package/dist/interpret.cjs +31 -18
  86. package/dist/interpret.d.cts +5 -5
  87. package/dist/interpret.d.ts +5 -5
  88. package/dist/interpret.js +31 -18
  89. package/dist/math-content-write.cjs +3 -3
  90. package/dist/math-content-write.js +3 -3
  91. package/dist/math-font-write.d.cts +1 -1
  92. package/dist/math-font-write.d.ts +1 -1
  93. package/dist/math-font.d.cts +4 -4
  94. package/dist/math-font.d.ts +4 -4
  95. package/dist/measure.cjs +1 -1
  96. package/dist/measure.js +1 -1
  97. package/dist/names.cjs +7 -7
  98. package/dist/names.d.cts +2 -2
  99. package/dist/names.d.ts +2 -2
  100. package/dist/names.js +7 -7
  101. package/dist/navigation.cjs +6 -7
  102. package/dist/navigation.d.cts +5 -5
  103. package/dist/navigation.d.ts +5 -5
  104. package/dist/navigation.js +6 -7
  105. package/dist/{objects-B7HdMeWS.d.ts → objects-e2RS3-yT.d.cts} +3 -3
  106. package/dist/{objects-B7HdMeWS.d.cts → objects-e2RS3-yT.d.ts} +3 -3
  107. package/dist/objects.d.cts +1 -1
  108. package/dist/objects.d.ts +1 -1
  109. package/dist/optional-content.d.cts +2 -2
  110. package/dist/optional-content.d.ts +2 -2
  111. package/dist/ot-layout-common.cjs +18 -13
  112. package/dist/ot-layout-common.d.cts +2 -2
  113. package/dist/ot-layout-common.d.ts +2 -2
  114. package/dist/ot-layout-common.js +18 -13
  115. package/dist/parse.cjs +5 -0
  116. package/dist/parse.d.cts +3 -2
  117. package/dist/parse.d.ts +3 -2
  118. package/dist/parse.js +5 -1
  119. package/dist/predictors.d.cts +1 -1
  120. package/dist/predictors.d.ts +1 -1
  121. package/dist/raster.cjs +10 -40
  122. package/dist/raster.d.cts +11 -11
  123. package/dist/raster.d.ts +11 -11
  124. package/dist/raster.js +10 -40
  125. package/dist/read.cjs +12 -8
  126. package/dist/read.js +12 -8
  127. package/dist/serialize.d.cts +1 -1
  128. package/dist/serialize.d.ts +1 -1
  129. package/dist/sfnt-subset.d.cts +1 -1
  130. package/dist/sfnt-subset.d.ts +1 -1
  131. package/dist/structure.cjs +4 -4
  132. package/dist/structure.d.cts +2 -2
  133. package/dist/structure.d.ts +2 -2
  134. package/dist/structure.js +4 -4
  135. package/dist/text-layout.d.cts +1 -1
  136. package/dist/text-layout.d.ts +1 -1
  137. package/dist/tounicode.d.cts +1 -1
  138. package/dist/tounicode.d.ts +1 -1
  139. package/dist/winansi.cjs +1 -1
  140. package/dist/winansi.js +1 -1
  141. package/dist/write.cjs +4 -4
  142. package/dist/write.d.cts +1 -1
  143. package/dist/write.d.ts +1 -1
  144. package/dist/write.js +4 -4
  145. package/dist/xref.d.cts +1 -1
  146. package/dist/xref.d.ts +1 -1
  147. package/package.json +2 -2
  148. package/dist/{afm-widths-BTu0IDp2.cjs → afm-widths-BYiX2L9D.cjs} +1 -1
  149. package/dist/{afm-widths-De_QMWgC.js → afm-widths-blUDDjlI.js} +1 -1
@@ -1,4 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_afm_widths = require("./afm-widths-BTu0IDp2.cjs");
2
+ const require_afm_widths = require("./afm-widths-BYiX2L9D.cjs");
3
3
  exports.STANDARD_METRICS = require_afm_widths.STANDARD_METRICS;
4
4
  exports.widthOfCode = require_afm_widths.widthOfCode;
@@ -1,2 +1,2 @@
1
- import { n as widthOfCode, t as STANDARD_METRICS } from "./afm-widths-De_QMWgC.js";
1
+ import { n as widthOfCode, t as STANDARD_METRICS } from "./afm-widths-blUDDjlI.js";
2
2
  export { STANDARD_METRICS, widthOfCode };
@@ -1,9 +1,9 @@
1
1
  import { PdfDiagnosticSink } from "./diagnostics.cjs";
2
2
  import { r as Matrix } from "./matrix-B7_SBKQ5.cjs";
3
- import { n as PdfDict } from "./objects-B7HdMeWS.cjs";
3
+ import { n as PdfDict } from "./objects-e2RS3-yT.cjs";
4
4
  import { PdfObjectResolver } from "./interpret.cjs";
5
5
  import { LayoutAnnotation } from "./layout.cjs";
6
6
  //#region src/annotations.d.ts
7
- declare function readPageAnnotations(page: PdfDict, pageMatrix: Matrix, resolver: PdfObjectResolver, sink: PdfDiagnosticSink): LayoutAnnotation[];
7
+ declare function readPageAnnotations(page: PdfDict, pageMatrix: Matrix, resolver: Readonly<PdfObjectResolver>, sink: PdfDiagnosticSink): LayoutAnnotation[];
8
8
  //#endregion
9
9
  export { readPageAnnotations };
@@ -1,9 +1,9 @@
1
1
  import { PdfDiagnosticSink } from "./diagnostics.js";
2
2
  import { r as Matrix } from "./matrix-B7_SBKQ5.js";
3
- import { n as PdfDict } from "./objects-B7HdMeWS.js";
3
+ import { n as PdfDict } from "./objects-e2RS3-yT.js";
4
4
  import { PdfObjectResolver } from "./interpret.js";
5
5
  import { LayoutAnnotation } from "./layout.js";
6
6
  //#region src/annotations.d.ts
7
- declare function readPageAnnotations(page: PdfDict, pageMatrix: Matrix, resolver: PdfObjectResolver, sink: PdfDiagnosticSink): LayoutAnnotation[];
7
+ declare function readPageAnnotations(page: PdfDict, pageMatrix: Matrix, resolver: Readonly<PdfObjectResolver>, sink: PdfDiagnosticSink): LayoutAnnotation[];
8
8
  //#endregion
9
9
  export { readPageAnnotations };
@@ -1,8 +1,8 @@
1
1
  import { PdfDiagnosticSink } from "./diagnostics.cjs";
2
- import { n as PdfDict } from "./objects-B7HdMeWS.cjs";
2
+ import { n as PdfDict } from "./objects-e2RS3-yT.cjs";
3
3
  import { PdfObjectResolver } from "./interpret.cjs";
4
4
  import { LayoutAttachment } from "./layout.cjs";
5
5
  //#region src/attachments.d.ts
6
- declare function readAttachments(catalog: PdfDict, pages: readonly PdfDict[], resolver: PdfObjectResolver, sink: PdfDiagnosticSink): LayoutAttachment[];
6
+ declare function readAttachments(catalog: PdfDict, pages: readonly PdfDict[], resolver: Readonly<PdfObjectResolver>, sink: PdfDiagnosticSink): LayoutAttachment[];
7
7
  //#endregion
8
8
  export { readAttachments };
@@ -1,8 +1,8 @@
1
1
  import { PdfDiagnosticSink } from "./diagnostics.js";
2
- import { n as PdfDict } from "./objects-B7HdMeWS.js";
2
+ import { n as PdfDict } from "./objects-e2RS3-yT.js";
3
3
  import { PdfObjectResolver } from "./interpret.js";
4
4
  import { LayoutAttachment } from "./layout.js";
5
5
  //#region src/attachments.d.ts
6
- declare function readAttachments(catalog: PdfDict, pages: readonly PdfDict[], resolver: PdfObjectResolver, sink: PdfDiagnosticSink): LayoutAttachment[];
6
+ declare function readAttachments(catalog: PdfDict, pages: readonly PdfDict[], resolver: Readonly<PdfObjectResolver>, sink: PdfDiagnosticSink): LayoutAttachment[];
7
7
  //#endregion
8
8
  export { readAttachments };
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_afm_widths = require("./afm-widths-BTu0IDp2.cjs");
2
+ const require_afm_widths = require("./afm-widths-BYiX2L9D.cjs");
3
3
  const require_sfnt = require("./sfnt.cjs");
4
4
  const require_cff = require("./cff.cjs");
5
5
  const require_cmap_table = require("./cmap-table.cjs");
@@ -1,7 +1,7 @@
1
1
  //#region src/builtin-encoding.d.ts
2
2
  interface BuiltinEncoding {
3
- codeToUnicode(code: number): number | undefined;
4
- glyphIdToUnicode(glyphId: number): number | undefined;
3
+ codeToUnicode: (code: number) => number | undefined;
4
+ glyphIdToUnicode: (glyphId: number) => number | undefined;
5
5
  }
6
6
  declare function readFontProgramEncoding(program: Uint8Array<ArrayBuffer>): BuiltinEncoding | undefined;
7
7
  //#endregion
@@ -1,7 +1,7 @@
1
1
  //#region src/builtin-encoding.d.ts
2
2
  interface BuiltinEncoding {
3
- codeToUnicode(code: number): number | undefined;
4
- glyphIdToUnicode(glyphId: number): number | undefined;
3
+ codeToUnicode: (code: number) => number | undefined;
4
+ glyphIdToUnicode: (glyphId: number) => number | undefined;
5
5
  }
6
6
  declare function readFontProgramEncoding(program: Uint8Array<ArrayBuffer>): BuiltinEncoding | undefined;
7
7
  //#endregion
@@ -1,4 +1,4 @@
1
- import { c as glyphNameToUnicode, d as standardGlyphName } from "./afm-widths-De_QMWgC.js";
1
+ import { c as glyphNameToUnicode, d as standardGlyphName } from "./afm-widths-blUDDjlI.js";
2
2
  import { hasBytes, parseSfnt, sfntTableBytes, u16, u8 } from "./sfnt.js";
3
3
  import { cffStringForSid, parseCffDict, readCffIndex } from "./cff.js";
4
4
  import { readCmapSubtables } from "./cmap-table.js";
@@ -62,13 +62,31 @@ function subrBias(count) {
62
62
  if (count < SUBR_BIAS_MEDIUM_LIMIT) return SUBR_BIAS_MEDIUM;
63
63
  return SUBR_BIAS_LARGE;
64
64
  }
65
- function includePoint(box, x, y) {
66
- box.minX = Math.min(box.minX, x);
67
- box.minY = Math.min(box.minY, y);
68
- box.maxX = Math.max(box.maxX, x);
69
- box.maxY = Math.max(box.maxY, y);
70
- box.drawn = true;
71
- }
65
+ var BoundsBox = class {
66
+ minX = Infinity;
67
+ minY = Infinity;
68
+ maxX = -Infinity;
69
+ maxY = -Infinity;
70
+ drawn = false;
71
+ includePoint(x, y) {
72
+ this.minX = Math.min(this.minX, x);
73
+ this.minY = Math.min(this.minY, y);
74
+ this.maxX = Math.max(this.maxX, x);
75
+ this.maxY = Math.max(this.maxY, y);
76
+ this.drawn = true;
77
+ }
78
+ includeXExtent(value) {
79
+ this.minX = Math.min(this.minX, value);
80
+ this.maxX = Math.max(this.maxX, value);
81
+ }
82
+ includeYExtent(value) {
83
+ this.minY = Math.min(this.minY, value);
84
+ this.maxY = Math.max(this.maxY, value);
85
+ }
86
+ markDrawn() {
87
+ this.drawn = true;
88
+ }
89
+ };
72
90
  function cubicAt(p0, p1, p2, p3, t) {
73
91
  const s = 1 - t;
74
92
  return s * s * s * p0 + 3 * s * s * t * p1 + 3 * s * t * t * p2 + t * t * t * p3;
@@ -93,14 +111,12 @@ function includeCubicAxis(p0, p1, p2, p3, apply) {
93
111
  }
94
112
  function includeCubic(box, x0, y0, x1, y1, x2, y2, x3, y3) {
95
113
  includeCubicAxis(x0, x1, x2, x3, (value) => {
96
- box.minX = Math.min(box.minX, value);
97
- box.maxX = Math.max(box.maxX, value);
114
+ box.includeXExtent(value);
98
115
  });
99
116
  includeCubicAxis(y0, y1, y2, y3, (value) => {
100
- box.minY = Math.min(box.minY, value);
101
- box.maxY = Math.max(box.maxY, value);
117
+ box.includeYExtent(value);
102
118
  });
103
- box.drawn = true;
119
+ box.markDrawn();
104
120
  }
105
121
  function curveTo(state, dx1, dy1, dx2, dy2, dx3, dy3) {
106
122
  const x0 = state.x;
@@ -116,10 +132,10 @@ function curveTo(state, dx1, dy1, dx2, dy2, dx3, dy3) {
116
132
  state.y = y3;
117
133
  }
118
134
  function lineTo(state, dx, dy) {
119
- includePoint(state.box, state.x, state.y);
135
+ state.box.includePoint(state.x, state.y);
120
136
  state.x += dx;
121
137
  state.y += dy;
122
- includePoint(state.box, state.x, state.y);
138
+ state.box.includePoint(state.x, state.y);
123
139
  }
124
140
  function moveTo(state, dx, dy) {
125
141
  state.x += dx;
@@ -408,13 +424,7 @@ function computeBounds(glyphId, context) {
408
424
  stems: 0,
409
425
  widthParsed: false,
410
426
  operations: 0,
411
- box: {
412
- minX: Infinity,
413
- minY: Infinity,
414
- maxX: -Infinity,
415
- maxY: -Infinity,
416
- drawn: false
417
- }
427
+ box: new BoundsBox()
418
428
  };
419
429
  if (!execute(code, state, context, 0) || !state.box.drawn) return;
420
430
  return {
@@ -2,7 +2,7 @@ import { t as GlyphInkBounds } from "./glyph-bounds-BV_Z40KS.cjs";
2
2
  //#region src/cff-bounds.d.ts
3
3
  interface CffGlyphBounds {
4
4
  readonly numGlyphs: number;
5
- bounds(glyphId: number): GlyphInkBounds | undefined;
5
+ bounds: (glyphId: number) => GlyphInkBounds | undefined;
6
6
  }
7
7
  declare function parseCffGlyphBounds(bytes: Uint8Array<ArrayBuffer>): CffGlyphBounds | undefined;
8
8
  //#endregion
@@ -2,7 +2,7 @@ import { t as GlyphInkBounds } from "./glyph-bounds-BV_Z40KS.js";
2
2
  //#region src/cff-bounds.d.ts
3
3
  interface CffGlyphBounds {
4
4
  readonly numGlyphs: number;
5
- bounds(glyphId: number): GlyphInkBounds | undefined;
5
+ bounds: (glyphId: number) => GlyphInkBounds | undefined;
6
6
  }
7
7
  declare function parseCffGlyphBounds(bytes: Uint8Array<ArrayBuffer>): CffGlyphBounds | undefined;
8
8
  //#endregion
@@ -61,13 +61,31 @@ function subrBias(count) {
61
61
  if (count < SUBR_BIAS_MEDIUM_LIMIT) return SUBR_BIAS_MEDIUM;
62
62
  return SUBR_BIAS_LARGE;
63
63
  }
64
- function includePoint(box, x, y) {
65
- box.minX = Math.min(box.minX, x);
66
- box.minY = Math.min(box.minY, y);
67
- box.maxX = Math.max(box.maxX, x);
68
- box.maxY = Math.max(box.maxY, y);
69
- box.drawn = true;
70
- }
64
+ var BoundsBox = class {
65
+ minX = Infinity;
66
+ minY = Infinity;
67
+ maxX = -Infinity;
68
+ maxY = -Infinity;
69
+ drawn = false;
70
+ includePoint(x, y) {
71
+ this.minX = Math.min(this.minX, x);
72
+ this.minY = Math.min(this.minY, y);
73
+ this.maxX = Math.max(this.maxX, x);
74
+ this.maxY = Math.max(this.maxY, y);
75
+ this.drawn = true;
76
+ }
77
+ includeXExtent(value) {
78
+ this.minX = Math.min(this.minX, value);
79
+ this.maxX = Math.max(this.maxX, value);
80
+ }
81
+ includeYExtent(value) {
82
+ this.minY = Math.min(this.minY, value);
83
+ this.maxY = Math.max(this.maxY, value);
84
+ }
85
+ markDrawn() {
86
+ this.drawn = true;
87
+ }
88
+ };
71
89
  function cubicAt(p0, p1, p2, p3, t) {
72
90
  const s = 1 - t;
73
91
  return s * s * s * p0 + 3 * s * s * t * p1 + 3 * s * t * t * p2 + t * t * t * p3;
@@ -92,14 +110,12 @@ function includeCubicAxis(p0, p1, p2, p3, apply) {
92
110
  }
93
111
  function includeCubic(box, x0, y0, x1, y1, x2, y2, x3, y3) {
94
112
  includeCubicAxis(x0, x1, x2, x3, (value) => {
95
- box.minX = Math.min(box.minX, value);
96
- box.maxX = Math.max(box.maxX, value);
113
+ box.includeXExtent(value);
97
114
  });
98
115
  includeCubicAxis(y0, y1, y2, y3, (value) => {
99
- box.minY = Math.min(box.minY, value);
100
- box.maxY = Math.max(box.maxY, value);
116
+ box.includeYExtent(value);
101
117
  });
102
- box.drawn = true;
118
+ box.markDrawn();
103
119
  }
104
120
  function curveTo(state, dx1, dy1, dx2, dy2, dx3, dy3) {
105
121
  const x0 = state.x;
@@ -115,10 +131,10 @@ function curveTo(state, dx1, dy1, dx2, dy2, dx3, dy3) {
115
131
  state.y = y3;
116
132
  }
117
133
  function lineTo(state, dx, dy) {
118
- includePoint(state.box, state.x, state.y);
134
+ state.box.includePoint(state.x, state.y);
119
135
  state.x += dx;
120
136
  state.y += dy;
121
- includePoint(state.box, state.x, state.y);
137
+ state.box.includePoint(state.x, state.y);
122
138
  }
123
139
  function moveTo(state, dx, dy) {
124
140
  state.x += dx;
@@ -407,13 +423,7 @@ function computeBounds(glyphId, context) {
407
423
  stems: 0,
408
424
  widthParsed: false,
409
425
  operations: 0,
410
- box: {
411
- minX: Infinity,
412
- minY: Infinity,
413
- maxX: -Infinity,
414
- maxY: -Infinity,
415
- drawn: false
416
- }
426
+ box: new BoundsBox()
417
427
  };
418
428
  if (!execute(code, state, context, 0) || !state.box.drawn) return;
419
429
  return {
package/dist/cff.d.cts CHANGED
@@ -2,7 +2,7 @@
2
2
  interface CffIndex {
3
3
  readonly count: number;
4
4
  readonly endOffset: number;
5
- entry(index: number): Uint8Array<ArrayBuffer> | undefined;
5
+ entry: (index: number) => Uint8Array<ArrayBuffer> | undefined;
6
6
  }
7
7
  type CffDict = ReadonlyMap<number, readonly number[]>;
8
8
  declare const CFF_ESCAPED_OPERATOR_BASE = 1200;
package/dist/cff.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  interface CffIndex {
3
3
  readonly count: number;
4
4
  readonly endOffset: number;
5
- entry(index: number): Uint8Array<ArrayBuffer> | undefined;
5
+ entry: (index: number) => Uint8Array<ArrayBuffer> | undefined;
6
6
  }
7
7
  type CffDict = ReadonlyMap<number, readonly number[]>;
8
8
  declare const CFF_ESCAPED_OPERATOR_BASE = 1200;
@@ -6,7 +6,7 @@ interface CmapSubtable {
6
6
  readonly encodingId: number;
7
7
  readonly format: number;
8
8
  readonly lookup: CmapLookup;
9
- forEachMapping(visit: (code: number, glyphId: number) => void): void;
9
+ forEachMapping: (visit: (code: number, glyphId: number) => void) => void;
10
10
  }
11
11
  declare function readCmapSubtables(font: SfntFont): readonly CmapSubtable[];
12
12
  declare function buildCmapLookup(font: SfntFont): CmapLookup | undefined;
@@ -6,7 +6,7 @@ interface CmapSubtable {
6
6
  readonly encodingId: number;
7
7
  readonly format: number;
8
8
  readonly lookup: CmapLookup;
9
- forEachMapping(visit: (code: number, glyphId: number) => void): void;
9
+ forEachMapping: (visit: (code: number, glyphId: number) => void) => void;
10
10
  }
11
11
  declare function readCmapSubtables(font: SfntFont): readonly CmapSubtable[];
12
12
  declare function buildCmapLookup(font: SfntFont): CmapLookup | undefined;
package/dist/cmap.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { PdfDiagnosticSink } from "./diagnostics.cjs";
2
2
  //#region src/cmap.d.ts
3
3
  interface ToUnicodeCMap {
4
- lookup(code: number): string | undefined;
4
+ lookup: (code: number) => string | undefined;
5
5
  }
6
6
  declare function parseToUnicodeCMap(bytes: Uint8Array<ArrayBuffer>, sink: PdfDiagnosticSink): ToUnicodeCMap;
7
7
  //#endregion
package/dist/cmap.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { PdfDiagnosticSink } from "./diagnostics.js";
2
2
  //#region src/cmap.d.ts
3
3
  interface ToUnicodeCMap {
4
- lookup(code: number): string | undefined;
4
+ lookup: (code: number) => string | undefined;
5
5
  }
6
6
  declare function parseToUnicodeCMap(bytes: Uint8Array<ArrayBuffer>, sink: PdfDiagnosticSink): ToUnicodeCMap;
7
7
  //#endregion
@@ -1,5 +1,5 @@
1
1
  import { PdfDiagnosticSink } from "./diagnostics.cjs";
2
- import { n as PdfDict, r as PdfObject } from "./objects-B7HdMeWS.cjs";
2
+ import { n as PdfDict, r as PdfObject } from "./objects-e2RS3-yT.cjs";
3
3
  //#region src/content-read.d.ts
4
4
  interface ContentOperation {
5
5
  readonly operands: readonly PdfObject[];
@@ -1,5 +1,5 @@
1
1
  import { PdfDiagnosticSink } from "./diagnostics.js";
2
- import { n as PdfDict, r as PdfObject } from "./objects-B7HdMeWS.js";
2
+ import { n as PdfDict, r as PdfObject } from "./objects-e2RS3-yT.js";
3
3
  //#region src/content-read.d.ts
4
4
  interface ContentOperation {
5
5
  readonly operands: readonly PdfObject[];
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_afm_widths = require("./afm-widths-BTu0IDp2.cjs");
2
+ const require_afm_widths = require("./afm-widths-BYiX2L9D.cjs");
3
3
  const require_objects = require("./objects.cjs");
4
4
  const require_bytes_writer = require("./bytes/writer.cjs");
5
5
  const require_serialize = require("./serialize.cjs");
@@ -43,15 +43,15 @@ function writeShowTextBlock(writer, item, resourceName, scalePercent, show) {
43
43
  writer.writeAscii(` ${show.operator}\n`);
44
44
  writer.writeAscii("ET\n");
45
45
  }
46
- function writeStandardText(writer, item, standardName, resourceName, measurer, substitutions) {
46
+ function writeStandardText(writer, item, standardName, resourceName, measurer) {
47
47
  const encoded = require_afm_widths.encodeForShow(item.text, standardName);
48
- substitutions.push(...encoded.substitutions);
49
48
  const scale = measurer.horizontalScaleFor(item.font);
50
49
  writeShowTextBlock(writer, item, resourceName, scale * 100, {
51
50
  operand: require_objects.pdfHexString(encoded.codes),
52
51
  operator: "Tj"
53
52
  });
54
53
  if (item.underline === true) writeUnderline(writer, item, item.widthPt ?? encoded.width1000 / GLYPH_SPACE_UNITS_PER_EM * item.sizePt * scale, measurer.underlineAtSize(item.font, item.sizePt));
54
+ return encoded.substitutions;
55
55
  }
56
56
  function embeddedShowOperand(encoded) {
57
57
  if (encoded.kerns.length === 0) return {
@@ -71,22 +71,25 @@ function embeddedShowOperand(encoded) {
71
71
  operator: "TJ"
72
72
  };
73
73
  }
74
- function writeEmbeddedText(writer, item, face, resourceName, missingGlyphs) {
74
+ function writeEmbeddedText(writer, item, face, resourceName) {
75
75
  const encoded = require_embedded_font.encodeForShowEmbedded(item.text, face);
76
- missingGlyphs.push(...encoded.substitutions);
77
76
  writeShowTextBlock(writer, item, resourceName, EMBEDDED_HORIZONTAL_SCALE_PERCENT, embeddedShowOperand(encoded));
78
77
  if (item.underline === true) writeUnderline(writer, item, item.widthPt ?? encoded.width1000 / GLYPH_SPACE_UNITS_PER_EM * item.sizePt, {
79
78
  offsetPt: face.metrics.underlinePositionGlyphSpace / GLYPH_SPACE_UNITS_PER_EM * item.sizePt,
80
79
  thicknessPt: face.metrics.underlineThicknessGlyphSpace / GLYPH_SPACE_UNITS_PER_EM * item.sizePt
81
80
  });
81
+ return encoded.substitutions;
82
82
  }
83
- function writeText(writer, item, context, substitutions, missingGlyphs) {
83
+ function writeText(writer, item, context) {
84
84
  const font = context.resolveFont(item.font);
85
- if (font.kind === "embedded") {
86
- writeEmbeddedText(writer, item, font.face, font.resourceName, missingGlyphs);
87
- return;
88
- }
89
- writeStandardText(writer, item, font.standardName, font.resourceName, context.measurer, substitutions);
85
+ if (font.kind === "embedded") return {
86
+ substitutions: [],
87
+ missingGlyphs: writeEmbeddedText(writer, item, font.face, font.resourceName)
88
+ };
89
+ return {
90
+ substitutions: writeStandardText(writer, item, font.standardName, font.resourceName, context.measurer),
91
+ missingGlyphs: []
92
+ };
90
93
  }
91
94
  function paintOperatorFor(fill, stroke, fillRule) {
92
95
  const evenOdd = fillRule === "evenodd";
@@ -332,8 +335,11 @@ function writeContentStream(items, context) {
332
335
  if (layerObjectNum !== void 0) writer.writeAscii(` /OC ${layerObjectNum} 0 R`);
333
336
  writer.writeAscii(" >> BDC\n");
334
337
  }
335
- if (item.kind === "text") writeText(writer, item, context, substitutions, missingGlyphs);
336
- else if (item.kind === "image") writeImage(writer, item, context);
338
+ if (item.kind === "text") {
339
+ const written = writeText(writer, item, context);
340
+ substitutions.push(...written.substitutions);
341
+ missingGlyphs.push(...written.missingGlyphs);
342
+ } else if (item.kind === "image") writeImage(writer, item, context);
337
343
  else if (item.kind === "rect") writeRect(writer, item);
338
344
  else if (item.kind === "line") writeLine(writer, item);
339
345
  else if (item.kind === "ellipse") writeEllipse(writer, item);
@@ -1,6 +1,6 @@
1
1
  import { r as StandardFontName } from "./afm-widths-CneRyu5l.cjs";
2
2
  import { LayoutItem } from "./layout.cjs";
3
- import { r as EmbeddedFaceSubstitution, t as EmbeddedFace } from "./embedded-font-DJUn9kMH.cjs";
3
+ import { r as EmbeddedFaceSubstitution, t as EmbeddedFace } from "./embedded-font-DgVBedw6.cjs";
4
4
  import { WinAnsiSubstitution } from "./winansi.cjs";
5
5
  import { LayoutFont, TextMeasurer } from "document-schema.js";
6
6
  //#region src/content-write.d.ts
@@ -18,8 +18,8 @@ interface ResolvedImageResource {
18
18
  }
19
19
  interface ContentWriteContext {
20
20
  readonly measurer: TextMeasurer;
21
- resolveFont(font: LayoutFont): ResolvedFontResource;
22
- resolveImage(imageId: string): ResolvedImageResource;
21
+ resolveFont: (font: Readonly<LayoutFont>) => ResolvedFontResource;
22
+ resolveImage: (imageId: string) => ResolvedImageResource;
23
23
  readonly layerObjectNumberOf?: (name: string) => number | undefined;
24
24
  readonly nextMcid?: () => number;
25
25
  }
@@ -1,6 +1,6 @@
1
1
  import { r as StandardFontName } from "./afm-widths-CneRyu5l.js";
2
2
  import { LayoutItem } from "./layout.js";
3
- import { r as EmbeddedFaceSubstitution, t as EmbeddedFace } from "./embedded-font-BRhZfEN2.js";
3
+ import { r as EmbeddedFaceSubstitution, t as EmbeddedFace } from "./embedded-font-ByD7ZiQS.js";
4
4
  import { WinAnsiSubstitution } from "./winansi.js";
5
5
  import { LayoutFont, TextMeasurer } from "document-schema.js";
6
6
  //#region src/content-write.d.ts
@@ -18,8 +18,8 @@ interface ResolvedImageResource {
18
18
  }
19
19
  interface ContentWriteContext {
20
20
  readonly measurer: TextMeasurer;
21
- resolveFont(font: LayoutFont): ResolvedFontResource;
22
- resolveImage(imageId: string): ResolvedImageResource;
21
+ resolveFont: (font: Readonly<LayoutFont>) => ResolvedFontResource;
22
+ resolveImage: (imageId: string) => ResolvedImageResource;
23
23
  readonly layerObjectNumberOf?: (name: string) => number | undefined;
24
24
  readonly nextMcid?: () => number;
25
25
  }
@@ -1,4 +1,4 @@
1
- import { h as encodeForShow } from "./afm-widths-De_QMWgC.js";
1
+ import { h as encodeForShow } from "./afm-widths-blUDDjlI.js";
2
2
  import { pdfArray, pdfHexString, pdfNum } from "./objects.js";
3
3
  import { ByteWriter } from "./bytes/writer.js";
4
4
  import { formatNumber, writeObject } from "./serialize.js";
@@ -42,15 +42,15 @@ function writeShowTextBlock(writer, item, resourceName, scalePercent, show) {
42
42
  writer.writeAscii(` ${show.operator}\n`);
43
43
  writer.writeAscii("ET\n");
44
44
  }
45
- function writeStandardText(writer, item, standardName, resourceName, measurer, substitutions) {
45
+ function writeStandardText(writer, item, standardName, resourceName, measurer) {
46
46
  const encoded = encodeForShow(item.text, standardName);
47
- substitutions.push(...encoded.substitutions);
48
47
  const scale = measurer.horizontalScaleFor(item.font);
49
48
  writeShowTextBlock(writer, item, resourceName, scale * 100, {
50
49
  operand: pdfHexString(encoded.codes),
51
50
  operator: "Tj"
52
51
  });
53
52
  if (item.underline === true) writeUnderline(writer, item, item.widthPt ?? encoded.width1000 / GLYPH_SPACE_UNITS_PER_EM * item.sizePt * scale, measurer.underlineAtSize(item.font, item.sizePt));
53
+ return encoded.substitutions;
54
54
  }
55
55
  function embeddedShowOperand(encoded) {
56
56
  if (encoded.kerns.length === 0) return {
@@ -70,22 +70,25 @@ function embeddedShowOperand(encoded) {
70
70
  operator: "TJ"
71
71
  };
72
72
  }
73
- function writeEmbeddedText(writer, item, face, resourceName, missingGlyphs) {
73
+ function writeEmbeddedText(writer, item, face, resourceName) {
74
74
  const encoded = encodeForShowEmbedded(item.text, face);
75
- missingGlyphs.push(...encoded.substitutions);
76
75
  writeShowTextBlock(writer, item, resourceName, EMBEDDED_HORIZONTAL_SCALE_PERCENT, embeddedShowOperand(encoded));
77
76
  if (item.underline === true) writeUnderline(writer, item, item.widthPt ?? encoded.width1000 / GLYPH_SPACE_UNITS_PER_EM * item.sizePt, {
78
77
  offsetPt: face.metrics.underlinePositionGlyphSpace / GLYPH_SPACE_UNITS_PER_EM * item.sizePt,
79
78
  thicknessPt: face.metrics.underlineThicknessGlyphSpace / GLYPH_SPACE_UNITS_PER_EM * item.sizePt
80
79
  });
80
+ return encoded.substitutions;
81
81
  }
82
- function writeText(writer, item, context, substitutions, missingGlyphs) {
82
+ function writeText(writer, item, context) {
83
83
  const font = context.resolveFont(item.font);
84
- if (font.kind === "embedded") {
85
- writeEmbeddedText(writer, item, font.face, font.resourceName, missingGlyphs);
86
- return;
87
- }
88
- writeStandardText(writer, item, font.standardName, font.resourceName, context.measurer, substitutions);
84
+ if (font.kind === "embedded") return {
85
+ substitutions: [],
86
+ missingGlyphs: writeEmbeddedText(writer, item, font.face, font.resourceName)
87
+ };
88
+ return {
89
+ substitutions: writeStandardText(writer, item, font.standardName, font.resourceName, context.measurer),
90
+ missingGlyphs: []
91
+ };
89
92
  }
90
93
  function paintOperatorFor(fill, stroke, fillRule) {
91
94
  const evenOdd = fillRule === "evenodd";
@@ -331,8 +334,11 @@ function writeContentStream(items, context) {
331
334
  if (layerObjectNum !== void 0) writer.writeAscii(` /OC ${layerObjectNum} 0 R`);
332
335
  writer.writeAscii(" >> BDC\n");
333
336
  }
334
- if (item.kind === "text") writeText(writer, item, context, substitutions, missingGlyphs);
335
- else if (item.kind === "image") writeImage(writer, item, context);
337
+ if (item.kind === "text") {
338
+ const written = writeText(writer, item, context);
339
+ substitutions.push(...written.substitutions);
340
+ missingGlyphs.push(...written.missingGlyphs);
341
+ } else if (item.kind === "image") writeImage(writer, item, context);
336
342
  else if (item.kind === "rect") writeRect(writer, item);
337
343
  else if (item.kind === "line") writeLine(writer, item);
338
344
  else if (item.kind === "ellipse") writeEllipse(writer, item);
package/dist/document.cjs CHANGED
@@ -154,19 +154,22 @@ function openPdfDocument(bytes, sink) {
154
154
  function pages() {
155
155
  const pagesRoot = resolveDict(require_objects.dictGet(catalog, "Pages"));
156
156
  if (pagesRoot === void 0) return [];
157
- const result = [];
158
157
  originalLeaves.clear();
159
- walkPageTree(pagesRoot, {}, /* @__PURE__ */ new Set(), result);
158
+ const result = [];
159
+ for (const leaf of walkPageTree(pagesRoot, {}, /* @__PURE__ */ new Set())) {
160
+ originalLeaves.set(leaf.node, result.length);
161
+ result.push(leaf.page);
162
+ }
160
163
  return result;
161
164
  }
162
- function walkPageTree(node, inherited, visited, result) {
165
+ function walkPageTree(node, inherited, visited) {
163
166
  if (visited.has(node)) {
164
167
  sink({
165
168
  code: "pdf/page-tree-cycle",
166
169
  severity: "warning",
167
170
  message: "the page tree contains a cycle; stopping descent at the repeated node"
168
171
  });
169
- return;
172
+ return [];
170
173
  }
171
174
  visited.add(node);
172
175
  const merged = { ...inherited };
@@ -178,17 +181,20 @@ function openPdfDocument(bytes, sink) {
178
181
  if (kids === void 0) {
179
182
  const entries = new Map(node.entries);
180
183
  for (const key of INHERITABLE_PAGE_KEYS) if (!entries.has(key) && merged[key] !== void 0) entries.set(key, merged[key]);
181
- originalLeaves.set(node, result.length);
182
- result.push({
183
- kind: "dict",
184
- entries
185
- });
186
- return;
184
+ return [{
185
+ node,
186
+ page: {
187
+ kind: "dict",
188
+ entries
189
+ }
190
+ }];
187
191
  }
192
+ const leaves = [];
188
193
  for (const kid of kids) {
189
194
  const kidDict = resolveDict(kid);
190
- if (kidDict !== void 0) walkPageTree(kidDict, merged, visited, result);
195
+ if (kidDict !== void 0) for (const leaf of walkPageTree(kidDict, merged, visited)) leaves.push(leaf);
191
196
  }
197
+ return leaves;
192
198
  }
193
199
  function pageIndex(obj) {
194
200
  const dict = require_objects.asDict(resolve(obj));
@@ -1,13 +1,13 @@
1
1
  import { PdfDiagnosticSink } from "./diagnostics.cjs";
2
- import { n as PdfDict, r as PdfObject } from "./objects-B7HdMeWS.cjs";
2
+ import { n as PdfDict, r as PdfObject } from "./objects-e2RS3-yT.cjs";
3
3
  //#region src/document.d.ts
4
4
  interface PdfDocument {
5
5
  readonly trailer: PdfDict;
6
6
  readonly catalog: PdfDict;
7
- resolve(obj: PdfObject | undefined): PdfObject | undefined;
8
- resolveDict(obj: PdfObject | undefined): PdfDict | undefined;
9
- pages(): PdfDict[];
10
- pageIndex(obj: PdfObject | undefined): number | undefined;
7
+ resolve: (obj: PdfObject | undefined) => PdfObject | undefined;
8
+ resolveDict: (obj: PdfObject | undefined) => PdfDict | undefined;
9
+ pages: () => PdfDict[];
10
+ pageIndex: (obj: PdfObject | undefined) => number | undefined;
11
11
  }
12
12
  declare function openPdfDocument(bytes: Uint8Array<ArrayBuffer>, sink: PdfDiagnosticSink): PdfDocument;
13
13
  //#endregion
@@ -1,13 +1,13 @@
1
1
  import { PdfDiagnosticSink } from "./diagnostics.js";
2
- import { n as PdfDict, r as PdfObject } from "./objects-B7HdMeWS.js";
2
+ import { n as PdfDict, r as PdfObject } from "./objects-e2RS3-yT.js";
3
3
  //#region src/document.d.ts
4
4
  interface PdfDocument {
5
5
  readonly trailer: PdfDict;
6
6
  readonly catalog: PdfDict;
7
- resolve(obj: PdfObject | undefined): PdfObject | undefined;
8
- resolveDict(obj: PdfObject | undefined): PdfDict | undefined;
9
- pages(): PdfDict[];
10
- pageIndex(obj: PdfObject | undefined): number | undefined;
7
+ resolve: (obj: PdfObject | undefined) => PdfObject | undefined;
8
+ resolveDict: (obj: PdfObject | undefined) => PdfDict | undefined;
9
+ pages: () => PdfDict[];
10
+ pageIndex: (obj: PdfObject | undefined) => number | undefined;
11
11
  }
12
12
  declare function openPdfDocument(bytes: Uint8Array<ArrayBuffer>, sink: PdfDiagnosticSink): PdfDocument;
13
13
  //#endregion