pdf-lite 1.7.4-alpha.4 → 1.7.4-alpha.5

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.
@@ -14,7 +14,12 @@ function calcTextX(quadding, padding, availableWidth, textWidth) {
14
14
  }
15
15
  export class PdfChoiceAppearanceStream extends PdfAppearanceStream {
16
16
  constructor(ctx) {
17
- const [x1, y1, x2, y2] = ctx.rect;
17
+ // Normalize rect coordinates: some PDFs have inverted y-axis where y1 > y2
18
+ let [x1, y1, x2, y2] = ctx.rect;
19
+ if (x2 < x1)
20
+ [x1, x2] = [x2, x1];
21
+ if (y2 < y1)
22
+ [y1, y2] = [y2, y1];
18
23
  const width = x2 - x1;
19
24
  const height = y2 - y1;
20
25
  super({
@@ -21,7 +21,13 @@ function calcTextX(quadding, padding, availableWidth, textWidth) {
21
21
  */
22
22
  export class PdfTextAppearanceStream extends PdfAppearanceStream {
23
23
  constructor(ctx) {
24
- const [x1, y1, x2, y2] = ctx.rect;
24
+ // Normalize rect coordinates: some PDFs have inverted y-axis where y1 > y2
25
+ // This ensures width and height are always positive
26
+ let [x1, y1, x2, y2] = ctx.rect;
27
+ if (x2 < x1)
28
+ [x1, x2] = [x2, x1];
29
+ if (y2 < y1)
30
+ [y1, y2] = [y2, y1];
25
31
  const width = x2 - x1;
26
32
  const height = y2 - y1;
27
33
  const value = ctx.value;
@@ -88,7 +88,12 @@ export class PdfButtonFormField extends PdfFormField {
88
88
  const rect = this.rect;
89
89
  if (!rect || rect.length !== 4)
90
90
  return false;
91
- const [x1, y1, x2, y2] = rect;
91
+ // Normalize rect coordinates: some PDFs have inverted y-axis where y1 > y2
92
+ let [x1, y1, x2, y2] = rect;
93
+ if (x2 < x1)
94
+ [x1, x2] = [x2, x1];
95
+ if (y2 < y1)
96
+ [y1, y2] = [y2, y1];
92
97
  const width = x2 - x1;
93
98
  const height = y2 - y1;
94
99
  // Merge own flags with parent flags so inherited bits (e.g. Radio) are
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pdf-lite",
3
- "version": "1.7.4-alpha.4",
3
+ "version": "1.7.4-alpha.5",
4
4
  "main": "dist/index.js",
5
5
  "type": "module",
6
6
  "exports": {