From d99a7c070f6eb76c47e44bea75f2734c1fc9c9db Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Sun, 20 Jun 2021 15:38:58 +0200 Subject: [PATCH] XFA - Don't display print-only elements - partial fix for https://bugzilla.mozilla.org/show_bug.cgi?id=1716980. --- src/core/xfa/html_utils.js | 15 ++++++++++++++- src/core/xfa/template.js | 25 ++++++++++++++++++++++++- web/xfa_layer_builder.css | 4 ++++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/core/xfa/html_utils.js b/src/core/xfa/html_utils.js index 9d1ddc989..9648e3ccd 100644 --- a/src/core/xfa/html_utils.js +++ b/src/core/xfa/html_utils.js @@ -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`, @@ -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); @@ -482,6 +494,7 @@ export { fixDimensions, fixTextIndent, getFonts, + isPrintOnly, layoutClass, layoutText, measureToString, diff --git a/src/core/xfa/template.js b/src/core/xfa/template.js index a163bf64e..988d0501d 100644 --- a/src/core/xfa/template.js +++ b/src/core/xfa/template.js @@ -69,6 +69,7 @@ import { fixDimensions, fixTextIndent, getFonts, + isPrintOnly, layoutClass, layoutText, measureToString, @@ -298,6 +299,10 @@ class Area extends XFAObject { class: ["xfaArea"], }; + if (isPrintOnly(this)) { + attributes.class.push("xfaPrintOnly"); + } + if (this.name) { attributes.xfaName = this.name; } @@ -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], }, }); @@ -1511,6 +1523,9 @@ class Draw extends XFAObject { if (this.font) { classNames.push("xfaFont"); } + if (isPrintOnly(this)) { + classNames.push("xfaPrintOnly"); + } const attributes = { style, @@ -2079,6 +2094,10 @@ class ExclGroup extends XFAObject { classNames.push(cl); } + if (isPrintOnly(this)) { + classNames.push("xfaPrintOnly"); + } + attributes.style = style; attributes.class = classNames; @@ -2327,6 +2346,10 @@ class Field extends XFAObject { classNames.push("xfaFont"); } + if (isPrintOnly(this)) { + classNames.push("xfaPrintOnly"); + } + const attributes = { style, id: this[$uid], diff --git a/web/xfa_layer_builder.css b/web/xfa_layer_builder.css index 5dadb1199..c3706ed2d 100644 --- a/web/xfa_layer_builder.css +++ b/web/xfa_layer_builder.css @@ -13,6 +13,10 @@ * limitations under the License. */ +.xfaPrintOnly { + display: none; +} + .xfaLayer { position: absolute; top: 0;