Skip to content

Commit

Permalink
XFA - Fix lot of layout issues
Browse files Browse the repository at this point in the history
  - I thought it was possible to rely on browser layout engine to handle layout stuff but it isn't possible
    - mainly because when a contentArea overflows, we must continue to layout in the next contentArea
    - when no more contentArea is available then we must go to the next page...
    - we must handle breakBefore and breakAfter which allows to "break" the layout to go to the next container
  - Sometimes some containers don't provide their dimensions so we must compute them in order to know where to put
    them in their parents but to compute those dimensions we need to layout the container itself...
  - See top of file layout.js for more explanations about layout.
  - fix few bugs in other places I met during my work on layout.
  • Loading branch information
calixteman committed May 19, 2021
1 parent faf6b10 commit 31c06e3
Show file tree
Hide file tree
Showing 14 changed files with 1,885 additions and 302 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 31c06e3

Please sign in to comment.