1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 10:08:06 +02:00

XFA - Create Form DOM in merging template and data trees

- Spec: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.364.2157&rep=rep1&type=pdf#page=171;
  - support for the 2 ways of merging: consumeData and matchTemplate;
  - create additional nodes in template DOM when occur node allows it;
  - support for global values in data DOM.
This commit is contained in:
Calixte Denizet 2021-02-24 19:05:04 +01:00
parent 5e3af62d58
commit 3243672727
9 changed files with 1584 additions and 109 deletions

View file

@ -13,15 +13,19 @@
* limitations under the License.
*/
import { $buildXFAObject, NamespaceIds } from "./namespaces.js";
import {
$appendChild,
$content,
$finalize,
$hasItem,
$hasSettableValue,
$isTransparent,
$namespaceId,
$nodeName,
$onChild,
$removeChild,
$setSetAttributes,
$setValue,
ContentObject,
Option01,
OptionObject,
@ -29,6 +33,7 @@ import {
XFAObject,
XFAObjectArray,
} from "./xfa_object.js";
import { $buildXFAObject, NamespaceIds } from "./namespaces.js";
import {
getBBox,
getColor,
@ -44,6 +49,15 @@ import { warn } from "../../shared/util.js";
const TEMPLATE_NS_ID = NamespaceIds.template.id;
function _setValue(templateNode, value) {
if (!templateNode.value) {
const nodeValue = new Value({});
templateNode[$appendChild](nodeValue);
templateNode.value = nodeValue;
}
templateNode.value[$setValue](value);
}
class AppearanceFilter extends StringObject {
constructor(attributes) {
super(TEMPLATE_NS_ID, "appearanceFilter");
@ -496,6 +510,10 @@ class Caption extends XFAObject {
this.para = null;
this.value = null;
}
[$setValue](value) {
_setValue(this, value);
}
}
class Certificate extends StringObject {
@ -586,6 +604,10 @@ class Color extends XFAObject {
this.value = getColor(attributes.value);
this.extras = null;
}
[$hasSettableValue]() {
return false;
}
}
class Comb extends XFAObject {
@ -869,6 +891,10 @@ class Draw extends XFAObject {
this.value = null;
this.setProperty = new XFAObjectArray();
}
[$setValue](value) {
_setValue(this, value);
}
}
class Edge extends XFAObject {
@ -1045,7 +1071,7 @@ class Event extends XFAObject {
}
class ExData extends ContentObject {
constructor(builder, attributes) {
constructor(attributes) {
super(TEMPLATE_NS_ID, "exData");
this.contentType = attributes.contentType || "";
this.href = attributes.href || "";
@ -1188,6 +1214,32 @@ class ExclGroup extends XFAObject {
this.field = new XFAObjectArray();
this.setProperty = new XFAObjectArray();
}
[$hasSettableValue]() {
return true;
}
[$setValue](value) {
for (const field of this.field.children) {
if (!field.value) {
const nodeValue = new Value({});
field[$appendChild](nodeValue);
field.value = nodeValue;
}
const nodeBoolean = new BooleanElement({});
nodeBoolean[$content] = 0;
for (const item of field.items.children) {
if (item[$hasItem](value)) {
nodeBoolean[$content] = 1;
break;
}
}
field.value[$setValue](nodeBoolean);
}
}
}
class Execute extends XFAObject {
@ -1294,6 +1346,8 @@ class Field extends XFAObject {
this.extras = null;
this.font = null;
this.format = null;
// For a choice list, one list is used to have display entries
// and the other for the exported values
this.items = new XFAObjectArray(2);
this.keep = null;
this.margin = null;
@ -1307,6 +1361,10 @@ class Field extends XFAObject {
this.event = new XFAObjectArray();
this.setProperty = new XFAObjectArray();
}
[$setValue](value) {
_setValue(this, value);
}
}
class Fill extends XFAObject {
@ -1590,6 +1648,15 @@ class Items extends XFAObject {
this.text = new XFAObjectArray();
this.time = new XFAObjectArray();
}
[$hasItem](value) {
return (
this.hasOwnProperty(value[$nodeName]) &&
this[value[$nodeName]].children.some(
node => node[$content] === value[$content]
)
);
}
}
class Keep extends XFAObject {
@ -1917,10 +1984,7 @@ class Para extends XFAObject {
"right",
]);
this.id = attributes.id || "";
this.lineHeight = getMeasurement(attributes.lineHeight, [
"0pt",
"measurement",
]);
this.lineHeight = getMeasurement(attributes.lineHeight, "0pt");
this.marginLeft = getMeasurement(attributes.marginLeft, "0");
this.marginRight = getMeasurement(attributes.marginRight, "0");
this.orphans = getInteger({
@ -2735,6 +2799,26 @@ class Value extends XFAObject {
this.text = null;
this.time = null;
}
[$setValue](value) {
const valueName = value[$nodeName];
if (this[valueName] !== null) {
this[valueName][$content] = value[$content];
return;
}
// Reset all the properties.
for (const name of Object.getOwnPropertyNames(this)) {
const obj = this[name];
if (obj instanceof XFAObject) {
this[name] = null;
this[$removeChild](obj);
}
}
this[value[$nodeName]] = value;
this[$appendChild](value);
}
}
class Variables extends XFAObject {
@ -3225,4 +3309,13 @@ class TemplateNamespace {
}
}
export { Template, TemplateNamespace };
export {
BindItems,
Field,
Items,
SetProperty,
Template,
TemplateNamespace,
Text,
Value,
};