Skip to content

Commit

Permalink
Merge pull request #13402 from calixteman/xfa_layout1
Browse files Browse the repository at this point in the history
XFA - Fix lot of layout issues
  • Loading branch information
calixteman authored May 25, 2021
2 parents 3538ef0 + 7cebdbd commit 4d26623
Show file tree
Hide file tree
Showing 14 changed files with 2,016 additions and 363 deletions.
25 changes: 19 additions & 6 deletions src/core/xfa/bind.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
$finalize,
$getAttributeIt,
$getChildren,
$getDataValue,
$getParent,
$getRealChildrenByNameIt,
$global,
Expand Down Expand Up @@ -88,7 +89,7 @@ class Binder {

if (formNode[$hasSettableValue]()) {
if (data[$isDataValue]()) {
const value = data[$content].trim();
const value = data[$getDataValue]();
// TODO: use picture.
formNode[$setValue](createText(value));
formNode[$data] = data;
Expand All @@ -114,7 +115,7 @@ class Binder {
}
}

_findDataByNameToConsume(name, dataNode, global) {
_findDataByNameToConsume(name, isValue, dataNode, global) {
if (!name) {
return null;
}
Expand All @@ -130,9 +131,16 @@ class Binder {
/* allTransparent = */ false,
/* skipConsumed = */ true
);
match = generator.next().value;
if (match) {
return match;
// Try to find a match of the same kind.
while (true) {
match = generator.next().value;
if (!match) {
break;
}

if (isValue === match[$isDataValue]()) {
return match;
}
}
if (
dataNode[$namespaceId] === NamespaceIds.datasets.id &&
Expand All @@ -149,7 +157,7 @@ class Binder {

// Secondly, if global try to find it just under the root of datasets
// (which is the location of global variables).
generator = this.datasets[$getRealChildrenByNameIt](
generator = this.data[$getRealChildrenByNameIt](
name,
/* allTransparent = */ false,
/* skipConsumed = */ false
Expand Down Expand Up @@ -478,13 +486,15 @@ class Binder {
if (child.bind) {
switch (child.bind.match) {
case "none":
this._bindElement(child, dataNode);
continue;
case "global":
global = true;
break;
case "dataRef":
if (!child.bind.ref) {
warn(`XFA - ref is empty in node ${child[$nodeName]}.`);
this._bindElement(child, dataNode);
continue;
}
ref = child.bind.ref;
Expand Down Expand Up @@ -545,6 +555,7 @@ class Binder {
while (matches.length < max) {
const found = this._findDataByNameToConsume(
child.name,
child[$hasSettableValue](),
dataNode,
global
);
Expand Down Expand Up @@ -580,6 +591,8 @@ class Binder {
}
this._bindOccurrences(child, match, picture);
} else if (min > 0) {
this._setProperties(child, dataNode);
this._bindItems(child, dataNode);
this._bindElement(child, dataNode);
} else {
uselessNodes.push(child);
Expand Down
8 changes: 4 additions & 4 deletions src/core/xfa/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { $buildXFAObject, NamespaceIds } from "./namespaces.js";
import {
$cleanup,
$finalize,
$ids,
$nsAttributes,
$onChild,
$resolvePrototypes,
Expand All @@ -27,13 +28,11 @@ import { Template } from "./template.js";
import { UnknownNamespace } from "./unknown.js";
import { warn } from "../../shared/util.js";

const _ids = Symbol();

class Root extends XFAObject {
constructor(ids) {
super(-1, "root", Object.create(null));
this.element = null;
this[_ids] = ids;
this[$ids] = ids;
}

[$onChild](child) {
Expand All @@ -44,7 +43,8 @@ class Root extends XFAObject {
[$finalize]() {
super[$finalize]();
if (this.element.template instanceof Template) {
this.element.template[$resolvePrototypes](this[_ids]);
this.element.template[$resolvePrototypes](this[$ids]);
this.element.template[$ids] = this[$ids];
}
}
}
Expand Down
Loading

0 comments on commit 4d26623

Please sign in to comment.