JS -- Fix doc.getField and add missing field methods

- getField("foo") was wrongly returning a field named "foobar";
 - field object had few missing unimplemented methods
This commit is contained in:
Calixte Denizet 2021-01-07 19:22:37 +01:00
parent 952bc08ec0
commit 82f75a8ac2
4 changed files with 169 additions and 3 deletions

View file

@ -39,7 +39,7 @@ class Field extends PDFObject {
this.doNotSpellCheck = data.doNotSpellCheck;
this.delay = data.delay;
this.display = data.display;
this.doc = data.doc;
this.doc = data.doc.wrapped;
this.editable = data.editable;
this.exportValues = data.exportValues;
this.fileSelect = data.fileSelect;
@ -68,8 +68,13 @@ class Field extends PDFObject {
// Private
this._actions = createActionsMap(data.actions);
this._browseForFileToSubmit = data.browseForFileToSubmit || null;
this._buttonCaption = null;
this._buttonIcon = null;
this._children = null;
this._currentValueIndices = data.currentValueIndices || 0;
this._document = data.doc;
this._fieldPath = data.fieldPath;
this._fillColor = data.fillColor || ["T"];
this._isChoice = Array.isArray(data.items);
this._items = data.items || [];
@ -197,6 +202,48 @@ class Field extends PDFObject {
this._valueAsString = val ? val.toString() : "";
}
browseForFileToSubmit() {
if (this._browseForFileToSubmit) {
// TODO: implement this function on Firefox side
// we can use nsIFilePicker but open method is async.
// Maybe it's possible to use a html input (type=file) too.
this._browseForFileToSubmit();
}
}
buttonGetCaption(nFace = 0) {
if (this._buttonCaption) {
return this._buttonCaption[nFace];
}
return "";
}
buttonGetIcon(nFace = 0) {
if (this._buttonIcon) {
return this._buttonIcon[nFace];
}
return null;
}
buttonImportIcon(cPath = null, nPave = 0) {
/* Not implemented */
}
buttonSetCaption(cCaption, nFace = 0) {
if (!this._buttonCaption) {
this._buttonCaption = ["", "", ""];
}
this._buttonCaption[nFace] = cCaption;
// TODO: send to the annotation layer
}
buttonSetIcon(oIcon, nFace = 0) {
if (!this._buttonIcon) {
this._buttonIcon = [null, null, null];
}
this._buttonIcon[nFace] = oIcon;
}
checkThisBox(nWidget, bCheckIt = true) {}
clearItems() {
@ -260,6 +307,17 @@ class Field extends PDFObject {
return bExportValue ? item.exportValue : item.displayValue;
}
getArray() {
if (this._children === null) {
this._children = this._document.obj._getChildren(this._fieldPath);
}
return this._children;
}
getLock() {
return undefined;
}
isBoxChecked(nWidget) {
return false;
}
@ -337,6 +395,20 @@ class Field extends PDFObject {
this._send({ id: this._id, items: this._items });
}
setLock() {}
signatureGetModifications() {}
signatureGetSeedValue() {}
signatureInfo() {}
signatureSetSeedValue() {}
signatureSign() {}
signatureValidate() {}
_isButton() {
return false;
}