Merge pull request #12387 from calixteman/fix_12386

Use the same kind of strings for radio values
This commit is contained in:
Tim van der Meij 2020-09-17 23:45:17 +02:00 committed by GitHub
commit 26ae7ba2ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 1 deletions

View File

@ -1760,7 +1760,7 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
}
for (const key of normalAppearance.getKeys()) {
if (key !== "Off") {
this.data.buttonValue = key;
this.data.buttonValue = this._decodeFormValue(key);
break;
}
}

View File

@ -2133,6 +2133,40 @@ describe("annotation", function () {
}, done.fail);
});
it("should handle radio buttons with a field value not an ascii string", function (done) {
const parentDict = new Dict();
parentDict.set("V", Name.get("\x91I=\x91\xf0\x93\xe0\x97e3"));
const normalAppearanceStateDict = new Dict();
normalAppearanceStateDict.set("\x91I=\x91\xf0\x93\xe0\x97e3", null);
const appearanceStatesDict = new Dict();
appearanceStatesDict.set("N", normalAppearanceStateDict);
buttonWidgetDict.set("Ff", AnnotationFieldFlag.RADIO);
buttonWidgetDict.set("Parent", parentDict);
buttonWidgetDict.set("AP", appearanceStatesDict);
const buttonWidgetRef = Ref.get(124, 0);
const xref = new XRefMock([
{ ref: buttonWidgetRef, data: buttonWidgetDict },
]);
AnnotationFactory.create(
xref,
buttonWidgetRef,
pdfManagerMock,
idFactoryMock
).then(({ data }) => {
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
expect(data.checkBox).toEqual(false);
expect(data.radioButton).toEqual(true);
expect(data.fieldValue).toEqual("I=ðfiàŠe3");
expect(data.buttonValue).toEqual("I=ðfiàŠe3");
done();
}, done.fail);
});
it("should handle radio buttons without a field value", function (done) {
const normalAppearanceStateDict = new Dict();
normalAppearanceStateDict.set("2", null);