Skip to content

Commit

Permalink
Set parent of radio annotation even if there is no 'V' field
Browse files Browse the repository at this point in the history
  • Loading branch information
calixteman committed Sep 15, 2020
1 parent b0c7a74 commit 93d9934
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/core/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -1741,11 +1741,13 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
// The parent field's `V` entry holds a `Name` object with the appearance
// state of whichever child field is currently in the "on" state.
const fieldParent = params.dict.get("Parent");
if (isDict(fieldParent) && fieldParent.has("V")) {
const fieldParentValue = fieldParent.get("V");
if (isName(fieldParentValue)) {
this.parent = params.dict.getRaw("Parent");
this.data.fieldValue = this._decodeFormValue(fieldParentValue);
if (isDict(fieldParent)) {
this.parent = params.dict.getRaw("Parent");
if (fieldParent.has("V")) {
const fieldParentValue = fieldParent.get("V");
if (isName(fieldParentValue)) {
this.data.fieldValue = this._decodeFormValue(fieldParentValue);
}
}
}

Expand Down
61 changes: 61 additions & 0 deletions test/unit/annotation_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2318,6 +2318,67 @@ describe("annotation", function () {
}, done.fail);
});

it("should save radio buttons without a field value", function (done) {
const appearanceStatesDict = new Dict();
const normalAppearanceDict = new Dict();

normalAppearanceDict.set("Checked", Ref.get(314, 0));
normalAppearanceDict.set("Off", Ref.get(271, 0));
appearanceStatesDict.set("N", normalAppearanceDict);

buttonWidgetDict.set("Ff", AnnotationFieldFlag.RADIO);
buttonWidgetDict.set("AP", appearanceStatesDict);

const buttonWidgetRef = Ref.get(123, 0);
const parentRef = Ref.get(456, 0);

const parentDict = new Dict();
parentDict.set("Kids", [buttonWidgetRef]);
buttonWidgetDict.set("Parent", parentRef);

const xref = new XRefMock([
{ ref: buttonWidgetRef, data: buttonWidgetDict },
{ ref: parentRef, data: parentDict },
]);

parentDict.xref = xref;
buttonWidgetDict.xref = xref;
partialEvaluator.xref = xref;
const task = new WorkerTask("test save");

AnnotationFactory.create(
xref,
buttonWidgetRef,
pdfManagerMock,
idFactoryMock
)
.then(annotation => {
const annotationStorage = {};
annotationStorage[annotation.data.id] = true;
return Promise.all([
annotation,
annotation.save(partialEvaluator, task, annotationStorage),
]);
}, done.fail)
.then(([annotation, data]) => {
expect(data.length).toEqual(2);
const [radioData, parentData] = data;
radioData.data = radioData.data.replace(/\(D:[0-9]+\)/, "(date)");
expect(radioData.ref).toEqual(Ref.get(123, 0));
expect(radioData.data).toEqual(
"123 0 obj\n" +
"<< /Type /Annot /Subtype /Widget /FT /Btn /Ff 32768 " +
"/AP << /N << /Checked 314 0 R /Off 271 0 R>>>> " +
"/Parent 456 0 R /AS /Checked /M (date)>>\nendobj\n"
);
expect(parentData.ref).toEqual(Ref.get(456, 0));
expect(parentData.data).toEqual(
"456 0 obj\n<< /Kids [123 0 R] /V /Checked>>\nendobj\n"
);
done();
}, done.fail);
});

it("should save nothing", function (done) {
const buttonWidgetRef = Ref.get(124, 0);
const xref = new XRefMock([
Expand Down

0 comments on commit 93d9934

Please sign in to comment.