Skip to content

Commit

Permalink
XFA - Don't display print-only elements
Browse files Browse the repository at this point in the history
  • Loading branch information
calixteman committed Jun 21, 2021
1 parent 223b60f commit d99a7c0
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
15 changes: 14 additions & 1 deletion src/core/xfa/html_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,10 +368,14 @@ function createWrapper(node, html) {
}
const insetsW = insets[1] + insets[3];
const insetsH = insets[0] + insets[2];
const classNames = ["xfaBorder"];
if (isPrintOnly(node.border)) {
classNames.push("xfaPrintOnly");
}
const border = {
name: "div",
attributes: {
class: ["xfaBorder"],
class: classNames,
style: {
top: `${insets[0] - widths[0] + shiftW}px`,
left: `${insets[3] - widths[3] + shiftH}px`,
Expand Down Expand Up @@ -460,6 +464,14 @@ function setAccess(node, classNames) {
}
}

function isPrintOnly(node) {
return (
node.relevant.length > 0 &&
!node.relevant[0].excluded &&
node.relevant[0].viewname === "print"
);
}

function getFonts(family, fontFinder) {
if (family.startsWith("'") || family.startsWith('"')) {
family = family.slice(1, family.length - 1);
Expand All @@ -482,6 +494,7 @@ export {
fixDimensions,
fixTextIndent,
getFonts,
isPrintOnly,
layoutClass,
layoutText,
measureToString,
Expand Down
25 changes: 24 additions & 1 deletion src/core/xfa/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import {
fixDimensions,
fixTextIndent,
getFonts,
isPrintOnly,
layoutClass,
layoutText,
measureToString,
Expand Down Expand Up @@ -298,6 +299,10 @@ class Area extends XFAObject {
class: ["xfaArea"],
};

if (isPrintOnly(this)) {
attributes.class.push("xfaPrintOnly");
}

if (this.name) {
attributes.xfaName = this.name;
}
Expand Down Expand Up @@ -1136,12 +1141,19 @@ class ContentArea extends XFAObject {
width: measureToString(this.w),
height: measureToString(this.h),
};

const classNames = ["xfaContentarea"];

if (isPrintOnly(this)) {
classNames.push("xfaPrintOnly");
}

return HTMLResult.success({
name: "div",
children: [],
attributes: {
style,
class: ["xfaContentarea"],
class: classNames,
id: this[$uid],
},
});
Expand Down Expand Up @@ -1511,6 +1523,9 @@ class Draw extends XFAObject {
if (this.font) {
classNames.push("xfaFont");
}
if (isPrintOnly(this)) {
classNames.push("xfaPrintOnly");
}

const attributes = {
style,
Expand Down Expand Up @@ -2079,6 +2094,10 @@ class ExclGroup extends XFAObject {
classNames.push(cl);
}

if (isPrintOnly(this)) {
classNames.push("xfaPrintOnly");
}

attributes.style = style;
attributes.class = classNames;

Expand Down Expand Up @@ -2327,6 +2346,10 @@ class Field extends XFAObject {
classNames.push("xfaFont");
}

if (isPrintOnly(this)) {
classNames.push("xfaPrintOnly");
}

const attributes = {
style,
id: this[$uid],
Expand Down
4 changes: 4 additions & 0 deletions web/xfa_layer_builder.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
* limitations under the License.
*/

.xfaPrintOnly {
display: none;
}

.xfaLayer {
position: absolute;
top: 0;
Expand Down

0 comments on commit d99a7c0

Please sign in to comment.