pdf-parser.js 5.2.26 → 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 (95) hide show
  1. package/dist/annotations.d.cts +2 -2
  2. package/dist/annotations.d.ts +2 -2
  3. package/dist/attachments.d.cts +2 -2
  4. package/dist/attachments.d.ts +2 -2
  5. package/dist/cff-bounds.cjs +31 -21
  6. package/dist/cff-bounds.js +31 -21
  7. package/dist/content-read.d.cts +1 -1
  8. package/dist/content-read.d.ts +1 -1
  9. package/dist/content-write.cjs +18 -12
  10. package/dist/content-write.d.cts +2 -2
  11. package/dist/content-write.d.ts +2 -2
  12. package/dist/content-write.js +18 -12
  13. package/dist/document.cjs +17 -11
  14. package/dist/document.d.cts +1 -1
  15. package/dist/document.d.ts +1 -1
  16. package/dist/document.js +17 -11
  17. package/dist/{embedded-font-Bnhh4juV.d.ts → embedded-font-ByD7ZiQS.d.ts} +1 -1
  18. package/dist/{embedded-font-CEf-zBCA.d.cts → embedded-font-DgVBedw6.d.cts} +1 -1
  19. package/dist/embedded-font-write.d.cts +2 -2
  20. package/dist/embedded-font-write.d.ts +2 -2
  21. package/dist/embedded-font.d.cts +1 -1
  22. package/dist/embedded-font.d.ts +1 -1
  23. package/dist/encrypt-write.d.cts +1 -1
  24. package/dist/encrypt-write.d.ts +1 -1
  25. package/dist/encrypt.d.cts +1 -1
  26. package/dist/encrypt.d.ts +1 -1
  27. package/dist/filters.cjs +6 -6
  28. package/dist/filters.d.cts +1 -1
  29. package/dist/filters.d.ts +1 -1
  30. package/dist/filters.js +6 -6
  31. package/dist/font-read.d.cts +1 -1
  32. package/dist/font-read.d.ts +1 -1
  33. package/dist/font-registry.d.cts +3 -3
  34. package/dist/font-registry.d.ts +3 -3
  35. package/dist/form.cjs +13 -8
  36. package/dist/form.d.cts +2 -2
  37. package/dist/form.d.ts +2 -2
  38. package/dist/form.js +13 -8
  39. package/dist/{glyf-contours-C0epBNqP.d.ts → glyf-contours-B1PsI9oA.d.ts} +1 -1
  40. package/dist/{glyf-contours-BRpvd0rt.d.cts → glyf-contours-NHBpgks-.d.cts} +1 -1
  41. package/dist/glyf-contours.d.cts +1 -1
  42. package/dist/glyf-contours.d.ts +1 -1
  43. package/dist/gsub-table.cjs +12 -8
  44. package/dist/gsub-table.js +12 -8
  45. package/dist/image/jpeg2000-codestream.cjs +17 -8
  46. package/dist/image/jpeg2000-codestream.js +17 -8
  47. package/dist/images-read.d.cts +2 -2
  48. package/dist/images-read.d.ts +2 -2
  49. package/dist/index.d.cts +1 -1
  50. package/dist/index.d.ts +1 -1
  51. package/dist/interpret.cjs +29 -16
  52. package/dist/interpret.d.cts +1 -1
  53. package/dist/interpret.d.ts +1 -1
  54. package/dist/interpret.js +29 -16
  55. package/dist/math-font-write.d.cts +1 -1
  56. package/dist/math-font-write.d.ts +1 -1
  57. package/dist/names.cjs +7 -7
  58. package/dist/names.d.cts +2 -2
  59. package/dist/names.d.ts +2 -2
  60. package/dist/names.js +7 -7
  61. package/dist/navigation.cjs +6 -7
  62. package/dist/navigation.d.cts +4 -4
  63. package/dist/navigation.d.ts +4 -4
  64. package/dist/navigation.js +6 -7
  65. package/dist/{objects-B7HdMeWS.d.cts → objects-e2RS3-yT.d.cts} +3 -3
  66. package/dist/{objects-B7HdMeWS.d.ts → objects-e2RS3-yT.d.ts} +3 -3
  67. package/dist/objects.d.cts +1 -1
  68. package/dist/objects.d.ts +1 -1
  69. package/dist/optional-content.d.cts +2 -2
  70. package/dist/optional-content.d.ts +2 -2
  71. package/dist/ot-layout-common.cjs +18 -13
  72. package/dist/ot-layout-common.js +18 -13
  73. package/dist/parse.d.cts +1 -1
  74. package/dist/parse.d.ts +1 -1
  75. package/dist/predictors.d.cts +1 -1
  76. package/dist/predictors.d.ts +1 -1
  77. package/dist/raster.d.cts +8 -8
  78. package/dist/raster.d.ts +8 -8
  79. package/dist/read.cjs +12 -8
  80. package/dist/read.js +12 -8
  81. package/dist/serialize.d.cts +1 -1
  82. package/dist/serialize.d.ts +1 -1
  83. package/dist/sfnt-subset.d.cts +1 -1
  84. package/dist/sfnt-subset.d.ts +1 -1
  85. package/dist/structure.d.cts +2 -2
  86. package/dist/structure.d.ts +2 -2
  87. package/dist/text-layout.d.cts +1 -1
  88. package/dist/text-layout.d.ts +1 -1
  89. package/dist/tounicode.d.cts +1 -1
  90. package/dist/tounicode.d.ts +1 -1
  91. package/dist/write.d.cts +1 -1
  92. package/dist/write.d.ts +1 -1
  93. package/dist/xref.d.cts +1 -1
  94. package/dist/xref.d.ts +1 -1
  95. package/package.json +1 -1
@@ -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 };
@@ -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 {
@@ -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 {
@@ -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[];
@@ -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-CEf-zBCA.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,7 +18,7 @@ interface ResolvedImageResource {
18
18
  }
19
19
  interface ContentWriteContext {
20
20
  readonly measurer: TextMeasurer;
21
- resolveFont: (font: LayoutFont) => ResolvedFontResource;
21
+ resolveFont: (font: Readonly<LayoutFont>) => ResolvedFontResource;
22
22
  resolveImage: (imageId: string) => ResolvedImageResource;
23
23
  readonly layerObjectNumberOf?: (name: string) => number | undefined;
24
24
  readonly nextMcid?: () => number;
@@ -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-Bnhh4juV.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,7 +18,7 @@ interface ResolvedImageResource {
18
18
  }
19
19
  interface ContentWriteContext {
20
20
  readonly measurer: TextMeasurer;
21
- resolveFont: (font: LayoutFont) => ResolvedFontResource;
21
+ resolveFont: (font: Readonly<LayoutFont>) => ResolvedFontResource;
22
22
  resolveImage: (imageId: string) => ResolvedImageResource;
23
23
  readonly layerObjectNumberOf?: (name: string) => number | undefined;
24
24
  readonly nextMcid?: () => number;
@@ -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,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/document.d.ts
4
4
  interface PdfDocument {
5
5
  readonly trailer: PdfDict;
@@ -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/document.d.ts
4
4
  interface PdfDocument {
5
5
  readonly trailer: PdfDict;
package/dist/document.js CHANGED
@@ -153,19 +153,22 @@ function openPdfDocument(bytes, sink) {
153
153
  function pages() {
154
154
  const pagesRoot = resolveDict(dictGet(catalog, "Pages"));
155
155
  if (pagesRoot === void 0) return [];
156
- const result = [];
157
156
  originalLeaves.clear();
158
- walkPageTree(pagesRoot, {}, /* @__PURE__ */ new Set(), result);
157
+ const result = [];
158
+ for (const leaf of walkPageTree(pagesRoot, {}, /* @__PURE__ */ new Set())) {
159
+ originalLeaves.set(leaf.node, result.length);
160
+ result.push(leaf.page);
161
+ }
159
162
  return result;
160
163
  }
161
- function walkPageTree(node, inherited, visited, result) {
164
+ function walkPageTree(node, inherited, visited) {
162
165
  if (visited.has(node)) {
163
166
  sink({
164
167
  code: "pdf/page-tree-cycle",
165
168
  severity: "warning",
166
169
  message: "the page tree contains a cycle; stopping descent at the repeated node"
167
170
  });
168
- return;
171
+ return [];
169
172
  }
170
173
  visited.add(node);
171
174
  const merged = { ...inherited };
@@ -177,17 +180,20 @@ function openPdfDocument(bytes, sink) {
177
180
  if (kids === void 0) {
178
181
  const entries = new Map(node.entries);
179
182
  for (const key of INHERITABLE_PAGE_KEYS) if (!entries.has(key) && merged[key] !== void 0) entries.set(key, merged[key]);
180
- originalLeaves.set(node, result.length);
181
- result.push({
182
- kind: "dict",
183
- entries
184
- });
185
- return;
183
+ return [{
184
+ node,
185
+ page: {
186
+ kind: "dict",
187
+ entries
188
+ }
189
+ }];
186
190
  }
191
+ const leaves = [];
187
192
  for (const kid of kids) {
188
193
  const kidDict = resolveDict(kid);
189
- if (kidDict !== void 0) walkPageTree(kidDict, merged, visited, result);
194
+ if (kidDict !== void 0) for (const leaf of walkPageTree(kidDict, merged, visited)) leaves.push(leaf);
190
195
  }
196
+ return leaves;
191
197
  }
192
198
  function pageIndex(obj) {
193
199
  const dict = asDict(resolve(obj));
@@ -45,6 +45,6 @@ interface EmbeddedShow {
45
45
  readonly kerns: readonly EmbeddedKern[];
46
46
  }
47
47
  declare function encodeForShowEmbedded(text: string, face: EmbeddedFace): EmbeddedShow;
48
- declare function collectEmbeddedGlyphs(texts: Iterable<string>, face: EmbeddedFace): ReadonlyMap<number, readonly number[]>;
48
+ declare function collectEmbeddedGlyphs(texts: Readonly<Iterable<string>>, face: EmbeddedFace): ReadonlyMap<number, readonly number[]>;
49
49
  //#endregion
50
50
  export { EmbeddedShow as a, encodeForShowEmbedded as c, EmbeddedKern as i, loadEmbeddedFace as l, EmbeddedFaceMetrics as n, NOTDEF_GLYPH_ID as o, EmbeddedFaceSubstitution as r, collectEmbeddedGlyphs as s, EmbeddedFace as t };
@@ -45,6 +45,6 @@ interface EmbeddedShow {
45
45
  readonly kerns: readonly EmbeddedKern[];
46
46
  }
47
47
  declare function encodeForShowEmbedded(text: string, face: EmbeddedFace): EmbeddedShow;
48
- declare function collectEmbeddedGlyphs(texts: Iterable<string>, face: EmbeddedFace): ReadonlyMap<number, readonly number[]>;
48
+ declare function collectEmbeddedGlyphs(texts: Readonly<Iterable<string>>, face: EmbeddedFace): ReadonlyMap<number, readonly number[]>;
49
49
  //#endregion
50
50
  export { EmbeddedShow as a, encodeForShowEmbedded as c, EmbeddedKern as i, loadEmbeddedFace as l, EmbeddedFaceMetrics as n, NOTDEF_GLYPH_ID as o, EmbeddedFaceSubstitution as r, collectEmbeddedGlyphs as s, EmbeddedFace as t };
@@ -1,5 +1,5 @@
1
- import { n as PdfDict, r as PdfObject } from "./objects-B7HdMeWS.cjs";
2
- import { t as EmbeddedFace } from "./embedded-font-CEf-zBCA.cjs";
1
+ import { n as PdfDict, r as PdfObject } from "./objects-e2RS3-yT.cjs";
2
+ import { t as EmbeddedFace } from "./embedded-font-DgVBedw6.cjs";
3
3
  import { SfntSubsetResult } from "./sfnt-subset.cjs";
4
4
  //#region src/embedded-font-write.d.ts
5
5
  declare function embeddedSubsetTag(postScriptName: string, glyphIds: readonly number[]): string;
@@ -1,5 +1,5 @@
1
- import { n as PdfDict, r as PdfObject } from "./objects-B7HdMeWS.js";
2
- import { t as EmbeddedFace } from "./embedded-font-Bnhh4juV.js";
1
+ import { n as PdfDict, r as PdfObject } from "./objects-e2RS3-yT.js";
2
+ import { t as EmbeddedFace } from "./embedded-font-ByD7ZiQS.js";
3
3
  import { SfntSubsetResult } from "./sfnt-subset.js";
4
4
  //#region src/embedded-font-write.d.ts
5
5
  declare function embeddedSubsetTag(postScriptName: string, glyphIds: readonly number[]): string;
@@ -1,2 +1,2 @@
1
- import { a as EmbeddedShow, c as encodeForShowEmbedded, i as EmbeddedKern, l as loadEmbeddedFace, n as EmbeddedFaceMetrics, o as NOTDEF_GLYPH_ID, r as EmbeddedFaceSubstitution, s as collectEmbeddedGlyphs, t as EmbeddedFace } from "./embedded-font-CEf-zBCA.cjs";
1
+ import { a as EmbeddedShow, c as encodeForShowEmbedded, i as EmbeddedKern, l as loadEmbeddedFace, n as EmbeddedFaceMetrics, o as NOTDEF_GLYPH_ID, r as EmbeddedFaceSubstitution, s as collectEmbeddedGlyphs, t as EmbeddedFace } from "./embedded-font-DgVBedw6.cjs";
2
2
  export { EmbeddedFace, EmbeddedFaceMetrics, EmbeddedFaceSubstitution, EmbeddedKern, EmbeddedShow, NOTDEF_GLYPH_ID, collectEmbeddedGlyphs, encodeForShowEmbedded, loadEmbeddedFace };
@@ -1,2 +1,2 @@
1
- import { a as EmbeddedShow, c as encodeForShowEmbedded, i as EmbeddedKern, l as loadEmbeddedFace, n as EmbeddedFaceMetrics, o as NOTDEF_GLYPH_ID, r as EmbeddedFaceSubstitution, s as collectEmbeddedGlyphs, t as EmbeddedFace } from "./embedded-font-Bnhh4juV.js";
1
+ import { a as EmbeddedShow, c as encodeForShowEmbedded, i as EmbeddedKern, l as loadEmbeddedFace, n as EmbeddedFaceMetrics, o as NOTDEF_GLYPH_ID, r as EmbeddedFaceSubstitution, s as collectEmbeddedGlyphs, t as EmbeddedFace } from "./embedded-font-ByD7ZiQS.js";
2
2
  export { EmbeddedFace, EmbeddedFaceMetrics, EmbeddedFaceSubstitution, EmbeddedKern, EmbeddedShow, NOTDEF_GLYPH_ID, collectEmbeddedGlyphs, encodeForShowEmbedded, loadEmbeddedFace };
@@ -1,4 +1,4 @@
1
- import { n as PdfDict, r as PdfObject } from "./objects-B7HdMeWS.cjs";
1
+ import { n as PdfDict, r as PdfObject } from "./objects-e2RS3-yT.cjs";
2
2
  //#region src/encrypt-write.d.ts
3
3
  declare class PdfEncryptionError extends Error {
4
4
  constructor(message: string);
@@ -1,4 +1,4 @@
1
- import { n as PdfDict, r as PdfObject } from "./objects-B7HdMeWS.js";
1
+ import { n as PdfDict, r as PdfObject } from "./objects-e2RS3-yT.js";
2
2
  //#region src/encrypt-write.d.ts
3
3
  declare class PdfEncryptionError extends Error {
4
4
  constructor(message: string);
@@ -1,5 +1,5 @@
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
  //#region src/encrypt.d.ts
4
4
  type CipherMethod = "identity" | "rc4" | "aes";
5
5
  interface PdfDecryptor {
package/dist/encrypt.d.ts CHANGED
@@ -1,5 +1,5 @@
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
  //#region src/encrypt.d.ts
4
4
  type CipherMethod = "identity" | "rc4" | "aes";
5
5
  interface PdfDecryptor {