[Annotation] For choice widget, use the I entry instead of the V one (bug 1770750)
It isn't really conform to the specifications but Acrobat is working like that...
This commit is contained in:
parent
ff3b9ccf6e
commit
58e4d92884
@ -1791,6 +1791,8 @@ class WidgetAnnotation extends Annotation {
|
|||||||
return mk.size > 0 ? mk : null;
|
return mk.size > 0 ? mk : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
amendSavedDict(annotationStorage, dict) {}
|
||||||
|
|
||||||
async save(evaluator, task, annotationStorage) {
|
async save(evaluator, task, annotationStorage) {
|
||||||
const storageEntry = annotationStorage
|
const storageEntry = annotationStorage
|
||||||
? annotationStorage.get(this.data.id)
|
? annotationStorage.get(this.data.id)
|
||||||
@ -1868,6 +1870,7 @@ class WidgetAnnotation extends Annotation {
|
|||||||
: stringToUTF16String(val, /* bigEndian = */ true);
|
: stringToUTF16String(val, /* bigEndian = */ true);
|
||||||
};
|
};
|
||||||
dict.set("V", Array.isArray(value) ? value.map(encoder) : encoder(value));
|
dict.set("V", Array.isArray(value) ? value.map(encoder) : encoder(value));
|
||||||
|
this.amendSavedDict(annotationStorage, dict);
|
||||||
|
|
||||||
const maybeMK = this._getMKDict(rotation);
|
const maybeMK = this._getMKDict(rotation);
|
||||||
if (maybeMK) {
|
if (maybeMK) {
|
||||||
@ -3144,6 +3147,10 @@ class ChoiceWidgetAnnotation extends WidgetAnnotation {
|
|||||||
super(params);
|
super(params);
|
||||||
|
|
||||||
const { dict, xref } = params;
|
const { dict, xref } = params;
|
||||||
|
|
||||||
|
this.indices = dict.getArray("I");
|
||||||
|
this.hasIndices = Array.isArray(this.indices) && this.indices.length > 0;
|
||||||
|
|
||||||
// Determine the options. The options array may consist of strings or
|
// Determine the options. The options array may consist of strings or
|
||||||
// arrays. If the array consists of arrays, then the first element of
|
// arrays. If the array consists of arrays, then the first element of
|
||||||
// each array is the export value and the second element of each array is
|
// each array is the export value and the second element of each array is
|
||||||
@ -3172,6 +3179,7 @@ class ChoiceWidgetAnnotation extends WidgetAnnotation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!this.hasIndices) {
|
||||||
// The field value can be `null` if no item is selected, a string if one
|
// The field value can be `null` if no item is selected, a string if one
|
||||||
// item is selected or an array of strings if multiple items are selected.
|
// item is selected or an array of strings if multiple items are selected.
|
||||||
// For consistency in the API and convenience in the display layer, we
|
// For consistency in the API and convenience in the display layer, we
|
||||||
@ -3181,6 +3189,19 @@ class ChoiceWidgetAnnotation extends WidgetAnnotation {
|
|||||||
} else if (!this.data.fieldValue) {
|
} else if (!this.data.fieldValue) {
|
||||||
this.data.fieldValue = [];
|
this.data.fieldValue = [];
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// The specs say that we should have an indices array only with
|
||||||
|
// multiselectable Choice and the "V" entry should have the
|
||||||
|
// precedence, but Acrobat itself is using it whatever the
|
||||||
|
// the "V" entry is (see bug 1770750).
|
||||||
|
this.data.fieldValue = [];
|
||||||
|
const ii = this.data.options.length;
|
||||||
|
for (const i of this.indices) {
|
||||||
|
if (Number.isInteger(i) && i >= 0 && i < ii) {
|
||||||
|
this.data.fieldValue.push(this.data.options[i].exportValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Process field flags for the display layer.
|
// Process field flags for the display layer.
|
||||||
this.data.combo = this.hasFieldFlag(AnnotationFieldFlag.COMBO);
|
this.data.combo = this.hasFieldFlag(AnnotationFieldFlag.COMBO);
|
||||||
@ -3212,6 +3233,28 @@ class ChoiceWidgetAnnotation extends WidgetAnnotation {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
amendSavedDict(annotationStorage, dict) {
|
||||||
|
if (!this.hasIndices) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const storageEntry = annotationStorage
|
||||||
|
? annotationStorage.get(this.data.id)
|
||||||
|
: undefined;
|
||||||
|
let values = storageEntry && storageEntry.value;
|
||||||
|
if (!Array.isArray(values)) {
|
||||||
|
values = [values];
|
||||||
|
}
|
||||||
|
const indices = [];
|
||||||
|
const { options } = this.data;
|
||||||
|
for (let i = 0, j = 0, ii = options.length; i < ii; i++) {
|
||||||
|
if (options[i].exportValue === values[j]) {
|
||||||
|
indices.push(i);
|
||||||
|
j += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dict.set("I", indices);
|
||||||
|
}
|
||||||
|
|
||||||
async _getAppearance(evaluator, task, intent, annotationStorage) {
|
async _getAppearance(evaluator, task, intent, annotationStorage) {
|
||||||
if (this.data.combo) {
|
if (this.data.combo) {
|
||||||
return super._getAppearance(evaluator, task, intent, annotationStorage);
|
return super._getAppearance(evaluator, task, intent, annotationStorage);
|
||||||
|
1
test/pdfs/.gitignore
vendored
1
test/pdfs/.gitignore
vendored
@ -573,3 +573,4 @@
|
|||||||
!bug1811510.pdf
|
!bug1811510.pdf
|
||||||
!bug1815476.pdf
|
!bug1815476.pdf
|
||||||
!issue16021.pdf
|
!issue16021.pdf
|
||||||
|
!bug1770750.pdf
|
||||||
|
BIN
test/pdfs/bug1770750.pdf
Executable file
BIN
test/pdfs/bug1770750.pdf
Executable file
Binary file not shown.
@ -7356,5 +7356,13 @@
|
|||||||
"md5": "78a12254cac90ba5219a4c5555ea35ed",
|
"md5": "78a12254cac90ba5219a4c5555ea35ed",
|
||||||
"rounds": 1,
|
"rounds": 1,
|
||||||
"type": "eq"
|
"type": "eq"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "bug1770750-annotations",
|
||||||
|
"file": "pdfs/bug1770750.pdf",
|
||||||
|
"md5": "01e6d77eac90b4b08d75240d3db2b826",
|
||||||
|
"rounds": 1,
|
||||||
|
"type": "eq",
|
||||||
|
"annotations": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user