mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-07-26 00:47:21 +02:00
Merge pull request #21626 from calixteman/fix/pdf-editor-inherited-default-appearance
Preserve inherited text field appearances
This commit is contained in:
commit
05e100c76e
@ -2239,11 +2239,7 @@ class PDFEditor {
|
|||||||
if (data.parentRef) {
|
if (data.parentRef) {
|
||||||
newKid.set("Parent", data.parentRef);
|
newKid.set("Parent", data.parentRef);
|
||||||
}
|
}
|
||||||
if (
|
if (acroFormDefaultAppearance && !newKid.has("DA")) {
|
||||||
acroFormDefaultAppearance &&
|
|
||||||
isName(newKid.get("FT"), "Tx") &&
|
|
||||||
!newKid.has("DA")
|
|
||||||
) {
|
|
||||||
// Fix the DA later since we need to have all the fields tree.
|
// Fix the DA later since we need to have all the fields tree.
|
||||||
daToFix.push(newKid);
|
daToFix.push(newKid);
|
||||||
}
|
}
|
||||||
@ -2261,6 +2257,10 @@ class PDFEditor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const field of daToFix) {
|
for (const field of daToFix) {
|
||||||
|
const fieldType = getInheritableProperty({ dict: field, key: "FT" });
|
||||||
|
if (!isName(fieldType, "Tx")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
const da = getInheritableProperty({ dict: field, key: "DA" });
|
const da = getInheritableProperty({ dict: field, key: "DA" });
|
||||||
if (!da) {
|
if (!da) {
|
||||||
// No DA in a parent field, we can set the default one.
|
// No DA in a parent field, we can set the default one.
|
||||||
|
|||||||
@ -7729,6 +7729,39 @@ small scripts as well as for`);
|
|||||||
await loadingTask.destroy();
|
await loadingTask.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("preserves conflicting DAs for inherited text fields", async function () {
|
||||||
|
const makePdf = (fontName, fieldName) =>
|
||||||
|
assemblePdf([
|
||||||
|
"1 0 obj\n<< /Type /Catalog /Pages 2 0 R " +
|
||||||
|
"/AcroForm 6 0 R >>\nendobj\n",
|
||||||
|
"2 0 obj\n<< /Type /Pages /Kids [3 0 R] /Count 1 >>\nendobj\n",
|
||||||
|
"3 0 obj\n<< /Type /Page /Parent 2 0 R " +
|
||||||
|
"/MediaBox [0 0 100 100] /Annots [4 0 R] >>\nendobj\n",
|
||||||
|
"4 0 obj\n<< /Type /Annot /Subtype /Widget /Rect [0 0 20 10] " +
|
||||||
|
"/Parent 5 0 R >>\nendobj\n",
|
||||||
|
`5 0 obj\n<< /FT /Tx /T (${fieldName}) ` +
|
||||||
|
"/Kids [4 0 R] >>\nendobj\n",
|
||||||
|
`6 0 obj\n<< /Fields [5 0 R] ` +
|
||||||
|
`/DA (/${fontName} 10 Tf) >>\nendobj\n`,
|
||||||
|
]);
|
||||||
|
|
||||||
|
let loadingTask = getDocument({ data: makePdf("F1", "first") });
|
||||||
|
let pdfDoc = await loadingTask.promise;
|
||||||
|
const data = await pdfDoc.extractPages([
|
||||||
|
{ document: null },
|
||||||
|
{ document: makePdf("F2", "second") },
|
||||||
|
]);
|
||||||
|
await loadingTask.destroy();
|
||||||
|
|
||||||
|
loadingTask = getDocument({ data });
|
||||||
|
pdfDoc = await loadingTask.promise;
|
||||||
|
const first = await (await pdfDoc.getPage(1)).getAnnotations();
|
||||||
|
const second = await (await pdfDoc.getPage(2)).getAnnotations();
|
||||||
|
expect(first[0].defaultAppearanceData.fontName).toEqual("F1");
|
||||||
|
expect(second[0].defaultAppearanceData.fontName).toEqual("F2");
|
||||||
|
await loadingTask.destroy();
|
||||||
|
});
|
||||||
|
|
||||||
it("extract page 2 and check AcroForm Fields T entries", async function () {
|
it("extract page 2 and check AcroForm Fields T entries", async function () {
|
||||||
let loadingTask = getDocument(
|
let loadingTask = getDocument(
|
||||||
buildGetDocumentParams("form_two_pages.pdf")
|
buildGetDocumentParams("form_two_pages.pdf")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user