Skip to content

Commit

Permalink
XFA - Remove empty pages
Browse files Browse the repository at this point in the history
  - it aims to fix mozilla#13583;
  - because hidden subform and breakBefore some pages can be empty so remove them;
  - don't fail when there is horizontal overflow (except in lr-tb);
  - fix a typo in radial gradient first argument.
  • Loading branch information
calixteman committed Jun 21, 2021
1 parent 2e6d3d6 commit a6d4d6b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
15 changes: 4 additions & 11 deletions src/core/xfa/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ function checkDimensions(node, space) {
}

const parent = node[$getParent]();
const attempt = (node[$extra] && node[$extra].attempt) || 0;
const attempt = (parent[$extra] && parent[$extra].attempt) || 0;
switch (parent.layout) {
case "lr-tb":
case "rl-tb":
Expand Down Expand Up @@ -307,20 +307,13 @@ function checkDimensions(node, space) {
}
return true;
case "position":
const [x, y, w, h] = getTransformedBBox(node);
const isWidthOk = node.w === "" || Math.round(w + x - space.width) <= 1;
const isHeightOk = node.h === "" || Math.round(h + y - space.height) <= 1;

if (isWidthOk && isHeightOk) {
const [, y, , h] = getTransformedBBox(node);
if (node.h === "" || Math.round(h + y - space.height) <= 1) {
return true;
}

const area = node[$getTemplateRoot]()[$extra].currentContentArea;
if (isWidthOk) {
return h + y > area.h;
}

return w + x > area.w;
return h + y > area.h;
case "rl-row":
case "row":
default:
Expand Down
10 changes: 7 additions & 3 deletions src/core/xfa/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -2390,8 +2390,10 @@ class Field extends XFAObject {

const caption = this.caption ? this.caption[$toHTML]().html : null;
if (!caption) {
// Even if no caption this class will help to center the ui.
ui.attributes.class.push("xfaLeft");
if (ui.attributes.class) {
// Even if no caption this class will help to center the ui.
ui.attributes.class.push("xfaLeft");
}
return HTMLResult.success(createWrapper(this, html), bbox);
}

Expand Down Expand Up @@ -3753,7 +3755,7 @@ class Radial extends XFAObject {
this.type === "toEdge"
? `${startColor},${endColor}`
: `${endColor},${startColor}`;
return `radial-gradient(circle to center, ${colors})`;
return `radial-gradient(circle at center, ${colors})`;
}
}

Expand Down Expand Up @@ -4269,6 +4271,7 @@ class Subform extends XFAObject {
}

if (children.length === 0) {
delete this[$extra];
return HTMLResult.EMPTY;
}

Expand Down Expand Up @@ -4540,6 +4543,7 @@ class Template extends XFAObject {

while (true) {
if (!hasSomething) {
mainHtml.children.pop();
// Nothing has been added in the previous page
if (++hasSomethingCounter === MAX_EMPTY_PAGES) {
warn("XFA - Something goes wrong: please file a bug.");
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/xfa_dhl_shipment.pdf.link
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://web.archive.org/web/20210621073147/https://www.dhl.com/content/dam/downloads/g0/express/emailship_page/globalpage/dhl_emailship_pdfclient_my_en.pdf
8 changes: 8 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,14 @@
"link": true,
"type": "load"
},
{ "id": "xfa_dhl_shipment",
"file": "pdfs/xfa_dhl_shipment.pdf",
"md5": "503ece429d69e7d626d6932a475fbe63",
"link": true,
"rounds": 1,
"enableXfa": true,
"type": "eq"
},
{ "id": "xfa_bug1716047",
"file": "pdfs/xfa_bug1716047.pdf",
"md5": "2f524163bd8397f43d195090978c3b56",
Expand Down
6 changes: 6 additions & 0 deletions test/unit/xfa_tohtml_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ describe("XFAFactory", function () {
<draw w="1pt" h="1pt"><value><text>foo</text></value></draw>
</subform>
</subform>
<subform name="third">
<breakBefore targetType="pageArea" startNew="1"/>
<subform>
<draw w="1pt" h="1pt"><value><text>bar</text></value></draw>
</subform>
</subform>
</subform>
</template>
<xfa:datasets xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">
Expand Down

0 comments on commit a6d4d6b

Please sign in to comment.