Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XFA - Fix lot of layout issues #13402

Merged
merged 1 commit into from
May 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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