Skip to content

Commit 5a4e06a

Browse files
authored
Merge pull request #13547 from calixteman/cerfa
XFA - Handle correctly subformSet
2 parents c7c59fe + d1e9459 commit 5a4e06a

File tree

5 files changed

+65
-21
lines changed

5 files changed

+65
-21
lines changed

src/core/xfa/html_utils.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import {
1717
$extra,
1818
$getParent,
19+
$getSubformParent,
1920
$nodeName,
2021
$toStyle,
2122
XFAObject,
@@ -296,7 +297,7 @@ function computeBbox(node, html, availableSpace) {
296297
}
297298

298299
function fixDimensions(node) {
299-
const parent = node[$getParent]();
300+
const parent = node[$getSubformParent]();
300301
if (parent.layout && parent.layout.includes("row")) {
301302
const extra = parent[$extra];
302303
const colSpan = node.colSpan;

src/core/xfa/template.js

+38-19
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ import {
2525
$flushHTML,
2626
$getAvailableSpace,
2727
$getChildren,
28+
$getContainedChildren,
2829
$getNextPage,
2930
$getParent,
31+
$getSubformParent,
3032
$hasItem,
3133
$hasSettableValue,
3234
$ids,
@@ -106,6 +108,16 @@ function getRoot(node) {
106108
return parent;
107109
}
108110

111+
function* getContainedChildren(node) {
112+
for (const child of node[$getChildren]()) {
113+
if (child instanceof SubformSet) {
114+
yield* child[$getContainedChildren]();
115+
continue;
116+
}
117+
yield child;
118+
}
119+
}
120+
109121
function valueToHtml(value) {
110122
return HTMLResult.success({
111123
name: "span",
@@ -338,6 +350,12 @@ class Area extends XFAObject {
338350
this.subformSet = new XFAObjectArray();
339351
}
340352

353+
*[$getContainedChildren]() {
354+
// This function is overriden in order to fake that subforms under
355+
// this set are in fact under parent subform.
356+
yield* getContainedChildren(this);
357+
}
358+
341359
[$isTransparent]() {
342360
return true;
343361
}
@@ -4079,6 +4097,12 @@ class Subform extends XFAObject {
40794097
this.subformSet = new XFAObjectArray();
40804098
}
40814099

4100+
*[$getContainedChildren]() {
4101+
// This function is overriden in order to fake that subforms under
4102+
// this set are in fact under parent subform.
4103+
yield* getContainedChildren(this);
4104+
}
4105+
40824106
[$flushHTML]() {
40834107
return flushHTML(this);
40844108
}
@@ -4163,7 +4187,7 @@ class Subform extends XFAObject {
41634187
]);
41644188

41654189
if (this.layout.includes("row")) {
4166-
const columnWidths = this[$getParent]().columnWidths;
4190+
const columnWidths = this[$getSubformParent]().columnWidths;
41674191
if (Array.isArray(columnWidths) && columnWidths.length > 0) {
41684192
this[$extra].columnWidths = columnWidths;
41694193
this[$extra].currentColumn = 0;
@@ -4294,27 +4318,22 @@ class SubformSet extends XFAObject {
42944318
this.breakBefore = new XFAObjectArray();
42954319
this.subform = new XFAObjectArray();
42964320
this.subformSet = new XFAObjectArray();
4297-
}
42984321

4299-
[$toHTML]() {
4300-
const children = [];
4301-
if (!this[$extra]) {
4302-
this[$extra] = Object.create(null);
4303-
}
4304-
this[$extra].children = children;
4322+
// TODO: need to handle break stuff and relation.
4323+
}
43054324

4306-
this[$childrenToHTML]({
4307-
filter: new Set(["subform", "subformSet"]),
4308-
include: true,
4309-
});
4325+
*[$getContainedChildren]() {
4326+
// This function is overriden in order to fake that subforms under
4327+
// this set are in fact under parent subform.
4328+
yield* getContainedChildren(this);
4329+
}
43104330

4311-
return HTMLResult.success({
4312-
name: "div",
4313-
children,
4314-
attributes: {
4315-
id: this[$uid],
4316-
},
4317-
});
4331+
[$getSubformParent]() {
4332+
let parent = this[$getParent]();
4333+
while (!(parent instanceof Subform)) {
4334+
parent = parent[$getParent]();
4335+
}
4336+
return parent;
43184337
}
43194338
}
43204339

src/core/xfa/xfa_object.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ const $getChildrenByNameIt = Symbol();
4343
const $getDataValue = Symbol();
4444
const $getRealChildrenByNameIt = Symbol();
4545
const $getChildren = Symbol();
46+
const $getContainedChildren = Symbol();
4647
const $getNextPage = Symbol();
48+
const $getSubformParent = Symbol();
4749
const $getParent = Symbol();
4850
const $global = Symbol();
4951
const $hasItem = Symbol();
@@ -255,6 +257,10 @@ class XFAObject {
255257
return this[_parent];
256258
}
257259

260+
[$getSubformParent]() {
261+
return this[$getParent]();
262+
}
263+
258264
[$getChildren](name = null) {
259265
if (!name) {
260266
return this[_children];
@@ -296,8 +302,15 @@ class XFAObject {
296302
return HTMLResult.EMPTY;
297303
}
298304

299-
*[_filteredChildrenGenerator](filter, include) {
305+
*[$getContainedChildren]() {
306+
// This function is overriden in Subform and SubformSet.
300307
for (const node of this[$getChildren]()) {
308+
yield node;
309+
}
310+
}
311+
312+
*[_filteredChildrenGenerator](filter, include) {
313+
for (const node of this[$getContainedChildren]()) {
301314
if (!filter || include === filter.has(node[$nodeName])) {
302315
const availableSpace = this[$getAvailableSpace]();
303316
const res = node[$toHTML](availableSpace);
@@ -965,10 +978,12 @@ export {
965978
$getChildrenByClass,
966979
$getChildrenByName,
967980
$getChildrenByNameIt,
981+
$getContainedChildren,
968982
$getDataValue,
969983
$getNextPage,
970984
$getParent,
971985
$getRealChildrenByNameIt,
986+
$getSubformParent,
972987
$global,
973988
$hasItem,
974989
$hasSettableValue,

test/pdfs/xfa_issue13213.pdf.link

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://github.com/mozilla/pdf.js/files/6290046/cerfa_12156-05.pdf

test/test_manifest.json

+8
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,14 @@
938938
"enableXfa": true,
939939
"type": "eq"
940940
},
941+
{ "id": "xfa_issue13213",
942+
"file": "pdfs/xfa_issue13213.pdf",
943+
"md5": "8a0e3179bffbac721589d1b1df863b49",
944+
"link": true,
945+
"rounds": 1,
946+
"enableXfa": true,
947+
"type": "eq"
948+
},
941949
{ "id": "issue10272",
942950
"file": "pdfs/issue10272.pdf",
943951
"md5": "bf3b2f74c6878d38a70dc0825f1b9a02",

0 commit comments

Comments
 (0)