pdf-lite 1.7.4-alpha.5 → 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 +19 -2
- package/dist/acroform/appearance/pdf-text-appearance-stream.d.ts +1 -0
- package/dist/acroform/appearance/pdf-text-appearance-stream.js +24 -2
- 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
|
}
|
|
@@ -20,12 +20,29 @@ export class PdfChoiceAppearanceStream extends PdfAppearanceStream {
|
|
|
20
20
|
[x1, x2] = [x2, x1];
|
|
21
21
|
if (y2 < y1)
|
|
22
22
|
[y1, y2] = [y2, y1];
|
|
23
|
-
const
|
|
24
|
-
const
|
|
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
|
+
}
|
|
25
41
|
super({
|
|
26
42
|
width,
|
|
27
43
|
height,
|
|
28
44
|
resources: ctx.fontResources,
|
|
45
|
+
matrix,
|
|
29
46
|
});
|
|
30
47
|
const isUnicode = ctx.isUnicode ?? false;
|
|
31
48
|
const reverseEncodingMap = ctx.reverseEncodingMap;
|
|
@@ -28,8 +28,17 @@ export class PdfTextAppearanceStream extends PdfAppearanceStream {
|
|
|
28
28
|
[x1, x2] = [x2, x1];
|
|
29
29
|
if (y2 < y1)
|
|
30
30
|
[y1, y2] = [y2, y1];
|
|
31
|
-
const
|
|
32
|
-
const
|
|
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;
|
|
33
42
|
const value = ctx.value;
|
|
34
43
|
const isUnicode = ctx.isUnicode ?? false;
|
|
35
44
|
const reverseEncodingMap = ctx.reverseEncodingMap;
|
|
@@ -167,11 +176,24 @@ export class PdfTextAppearanceStream extends PdfAppearanceStream {
|
|
|
167
176
|
}
|
|
168
177
|
g.restore();
|
|
169
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
|
+
}
|
|
170
191
|
super({
|
|
171
192
|
width,
|
|
172
193
|
height,
|
|
173
194
|
contentStream: g.build(),
|
|
174
195
|
resources: ctx.fontResources,
|
|
196
|
+
matrix,
|
|
175
197
|
});
|
|
176
198
|
}
|
|
177
199
|
}
|
|
@@ -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;
|