pdf-lite 1.7.4-alpha.4 → 1.7.4-alpha.6
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.
- package/dist/acroform/appearance/pdf-appearance-stream.d.ts +1 -0
- package/dist/acroform/appearance/pdf-appearance-stream.js +3 -0
- package/dist/acroform/appearance/pdf-choice-appearance-stream.d.ts +1 -0
- package/dist/acroform/appearance/pdf-choice-appearance-stream.js +25 -3
- package/dist/acroform/appearance/pdf-text-appearance-stream.d.ts +1 -0
- package/dist/acroform/appearance/pdf-text-appearance-stream.js +31 -3
- package/dist/acroform/fields/pdf-button-form-field.js +6 -1
- package/dist/acroform/fields/pdf-choice-form-field.js +4 -0
- package/dist/acroform/fields/pdf-text-form-field.js +1 -0
- package/package.json +1 -1
|
@@ -14,6 +14,7 @@ export declare class PdfAppearanceStream extends PdfIndirectObject<PdfStream> {
|
|
|
14
14
|
height?: number;
|
|
15
15
|
contentStream?: string;
|
|
16
16
|
resources?: PdfDictionary;
|
|
17
|
+
matrix?: [number, number, number, number, number, number];
|
|
17
18
|
});
|
|
18
19
|
get contentStream(): string;
|
|
19
20
|
set contentStream(newContent: string);
|
|
@@ -20,6 +20,9 @@ export class PdfAppearanceStream extends PdfIndirectObject {
|
|
|
20
20
|
new PdfNumber(options.width ?? 100),
|
|
21
21
|
new PdfNumber(options.height ?? 100),
|
|
22
22
|
]));
|
|
23
|
+
if (options.matrix) {
|
|
24
|
+
appearanceDict.set('Matrix', new PdfArray(options.matrix.map((v) => new PdfNumber(v))));
|
|
25
|
+
}
|
|
23
26
|
if (options.resources) {
|
|
24
27
|
appearanceDict.set('Resources', options.resources);
|
|
25
28
|
}
|
|
@@ -14,13 +14,35 @@ function calcTextX(quadding, padding, availableWidth, textWidth) {
|
|
|
14
14
|
}
|
|
15
15
|
export class PdfChoiceAppearanceStream extends PdfAppearanceStream {
|
|
16
16
|
constructor(ctx) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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];
|
|
23
|
+
const rectWidth = x2 - x1;
|
|
24
|
+
const rectHeight = y2 - y1;
|
|
25
|
+
const rotation = ctx.rotation ?? 0;
|
|
26
|
+
const needsSwap = rotation === 90 || rotation === 270;
|
|
27
|
+
const width = needsSwap ? rectHeight : rectWidth;
|
|
28
|
+
const height = needsSwap ? rectWidth : rectHeight;
|
|
29
|
+
// For rotated pages, the BBox uses the displayed (swapped)
|
|
30
|
+
// dimensions and a Matrix entry maps back to annotation space.
|
|
31
|
+
let matrix;
|
|
32
|
+
if (rotation === 90) {
|
|
33
|
+
matrix = [0, 1, -1, 0, rectWidth, 0];
|
|
34
|
+
}
|
|
35
|
+
else if (rotation === 270) {
|
|
36
|
+
matrix = [0, -1, 1, 0, 0, rectHeight];
|
|
37
|
+
}
|
|
38
|
+
else if (rotation === 180) {
|
|
39
|
+
matrix = [-1, 0, 0, -1, rectWidth, rectHeight];
|
|
40
|
+
}
|
|
20
41
|
super({
|
|
21
42
|
width,
|
|
22
43
|
height,
|
|
23
44
|
resources: ctx.fontResources,
|
|
45
|
+
matrix,
|
|
24
46
|
});
|
|
25
47
|
const isUnicode = ctx.isUnicode ?? false;
|
|
26
48
|
const reverseEncodingMap = ctx.reverseEncodingMap;
|
|
@@ -21,9 +21,24 @@ function calcTextX(quadding, padding, availableWidth, textWidth) {
|
|
|
21
21
|
*/
|
|
22
22
|
export class PdfTextAppearanceStream extends PdfAppearanceStream {
|
|
23
23
|
constructor(ctx) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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];
|
|
31
|
+
const rectWidth = x2 - x1;
|
|
32
|
+
const rectHeight = y2 - y1;
|
|
33
|
+
// For rotated pages, the field rect is in the unrotated coordinate
|
|
34
|
+
// space. A 90° or 270° page rotation swaps how the field appears on
|
|
35
|
+
// screen (tall/narrow rect becomes wide/short when viewed). We swap
|
|
36
|
+
// the layout dimensions so text is laid out for the displayed shape,
|
|
37
|
+
// then apply a rotation matrix to map back into the BBox.
|
|
38
|
+
const rotation = ctx.rotation ?? 0;
|
|
39
|
+
const needsSwap = rotation === 90 || rotation === 270;
|
|
40
|
+
const width = needsSwap ? rectHeight : rectWidth;
|
|
41
|
+
const height = needsSwap ? rectWidth : rectHeight;
|
|
27
42
|
const value = ctx.value;
|
|
28
43
|
const isUnicode = ctx.isUnicode ?? false;
|
|
29
44
|
const reverseEncodingMap = ctx.reverseEncodingMap;
|
|
@@ -161,11 +176,24 @@ export class PdfTextAppearanceStream extends PdfAppearanceStream {
|
|
|
161
176
|
}
|
|
162
177
|
g.restore();
|
|
163
178
|
g.endMarkedContent();
|
|
179
|
+
// For rotated pages, the BBox uses the displayed (swapped)
|
|
180
|
+
// dimensions and a Matrix entry maps back to annotation space.
|
|
181
|
+
let matrix;
|
|
182
|
+
if (rotation === 90) {
|
|
183
|
+
matrix = [0, 1, -1, 0, rectWidth, 0];
|
|
184
|
+
}
|
|
185
|
+
else if (rotation === 270) {
|
|
186
|
+
matrix = [0, -1, 1, 0, 0, rectHeight];
|
|
187
|
+
}
|
|
188
|
+
else if (rotation === 180) {
|
|
189
|
+
matrix = [-1, 0, 0, -1, rectWidth, rectHeight];
|
|
190
|
+
}
|
|
164
191
|
super({
|
|
165
192
|
width,
|
|
166
193
|
height,
|
|
167
194
|
contentStream: g.build(),
|
|
168
195
|
resources: ctx.fontResources,
|
|
196
|
+
matrix,
|
|
169
197
|
});
|
|
170
198
|
}
|
|
171
199
|
}
|
|
@@ -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
|
-
|
|
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
|
|
@@ -97,11 +97,15 @@ export class PdfChoiceFormField extends PdfFormField {
|
|
|
97
97
|
da: parsed,
|
|
98
98
|
flags: this.flags,
|
|
99
99
|
fontResources,
|
|
100
|
+
resolvedFonts: font
|
|
101
|
+
? new Map([[parsed.fontName, font]])
|
|
102
|
+
: undefined,
|
|
100
103
|
isUnicode,
|
|
101
104
|
reverseEncodingMap,
|
|
102
105
|
displayOptions: this.options.map((opt) => opt.label),
|
|
103
106
|
selectedIndex: this.selectedIndex,
|
|
104
107
|
quadding: this.quadding,
|
|
108
|
+
rotation: this.page?.rotate ?? 0,
|
|
105
109
|
});
|
|
106
110
|
if (options?.makeReadOnly) {
|
|
107
111
|
this.readOnly = true;
|