mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-08 09:20:06 +02:00
[JS] Take into account all the required fields for some computations
- Fix Field::getArray in order to collect only the fields which have a value; - Fix AFSimple_Calculate: * allow to have a string with a list of field names as argument; * since a field can be non-terminal, use Field::getArray to collect the field under it and then apply the calculation on all the descendants.
This commit is contained in:
parent
c6cc7c6e6a
commit
e756bb69e4
4 changed files with 154 additions and 10 deletions
|
@ -76,6 +76,7 @@ class Field extends PDFObject {
|
|||
this._fillColor = data.fillColor || ["T"];
|
||||
this._isChoice = Array.isArray(data.items);
|
||||
this._items = data.items || [];
|
||||
this._hasValue = data.hasOwnProperty("value");
|
||||
this._page = data.page || 0;
|
||||
this._strokeColor = data.strokeColor || ["G", 0];
|
||||
this._textColor = data.textColor || ["G", 0];
|
||||
|
@ -393,15 +394,32 @@ class Field extends PDFObject {
|
|||
}
|
||||
|
||||
getArray() {
|
||||
// Gets the array of terminal child fields (that is, fields that can have
|
||||
// a value for this Field object, the parent field).
|
||||
if (this._kidIds) {
|
||||
return this._kidIds.map(id => this._appObjects[id].wrapped);
|
||||
const array = [];
|
||||
const fillArrayWithKids = kidIds => {
|
||||
for (const id of kidIds) {
|
||||
const obj = this._appObjects[id];
|
||||
if (!obj) {
|
||||
continue;
|
||||
}
|
||||
if (obj.obj._hasValue) {
|
||||
array.push(obj.wrapped);
|
||||
}
|
||||
if (obj.obj._kidIds) {
|
||||
fillArrayWithKids(obj.obj._kidIds);
|
||||
}
|
||||
}
|
||||
};
|
||||
fillArrayWithKids(this._kidIds);
|
||||
return array;
|
||||
}
|
||||
|
||||
if (this._children === null) {
|
||||
this._children = this._document.obj
|
||||
._getChildren(this._fieldPath)
|
||||
.map(child => child.wrapped);
|
||||
this._children = this._document.obj._getTerminalChildren(this._fieldPath);
|
||||
}
|
||||
|
||||
return this._children;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue