Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XFA -- Display text content #13141

Merged
merged 1 commit into from
Apr 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
88 changes: 83 additions & 5 deletions src/core/xfa/html_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* limitations under the License.
*/

import { $getParent, $toStyle, XFAObject } from "./xfa_object.js";
import { $extra, $getParent, $toStyle, XFAObject } from "./xfa_object.js";
import { warn } from "../../shared/util.js";

function measureToString(m) {
Expand Down Expand Up @@ -56,8 +56,17 @@ const converters = {
}
},
dimensions(node, style) {
if (node.w) {
style.width = measureToString(node.w);
const parent = node[$getParent]();
const extra = parent[$extra];
let width = node.w;
if (extra && extra.columnWidths) {
width = extra.columnWidths[extra.currentColumn];
extra.currentColumn =
(extra.currentColumn + 1) % extra.columnWidths.length;
}

if (width !== "") {
style.width = measureToString(width);
} else {
style.width = "auto";
if (node.maxW > 0) {
Expand All @@ -66,7 +75,7 @@ const converters = {
style.minWidth = measureToString(node.minW);
}

if (node.h) {
if (node.h !== "") {
style.height = measureToString(node.h);
} else {
style.height = "auto";
Expand Down Expand Up @@ -108,6 +117,53 @@ const converters = {
break;
}
},
hAlign(node, style) {
switch (node.hAlign) {
case "justifyAll":
style.textAlign = "justify-all";
break;
case "radix":
// TODO: implement this correctly !
style.textAlign = "left";
break;
default:
style.textAlign = node.hAlign;
}
},
borderMarginPadding(node, style) {
// Get border width in order to compute margin and padding.
const borderWidths = [0, 0, 0, 0];
const marginWidths = [0, 0, 0, 0];
const marginNode = node.margin
? [
node.margin.topInset,
node.margin.rightInset,
node.margin.bottomInset,
node.margin.leftInset,
]
: [0, 0, 0, 0];
if (node.border) {
Object.assign(style, node.border[$toStyle](borderWidths, marginWidths));
}

if (borderWidths.every(x => x === 0)) {
// No border: margin & padding are padding
if (node.margin) {
Object.assign(style, node.margin[$toStyle]());
}
style.padding = style.margin;
delete style.margin;
} else {
style.padding =
measureToString(marginNode[0] - borderWidths[0] - marginWidths[0]) +
" " +
measureToString(marginNode[1] - borderWidths[1] - marginWidths[1]) +
" " +
measureToString(marginNode[2] - borderWidths[2] - marginWidths[2]) +
" " +
measureToString(marginNode[3] - borderWidths[3] - marginWidths[3]);
}
},
};

function layoutClass(node) {
Expand Down Expand Up @@ -155,4 +211,26 @@ function toStyle(node, ...names) {
return style;
}

export { layoutClass, measureToString, toStyle };
function addExtraDivForMargin(html) {
const style = html.attributes.style;
if (style.margin) {
const padding = style.margin;
delete style.margin;
const width = style.width || "auto";
const height = style.height || "auto";

style.width = "100%";
style.height = "100%";

return {
name: "div",
attributes: {
style: { padding, width, height },
},
children: [html],
};
}
return html;
}

export { addExtraDivForMargin, layoutClass, measureToString, toStyle };
6 changes: 6 additions & 0 deletions src/core/xfa/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/

import {
$acceptWhitespace,
$clean,
$finalize,
$nsAttributes,
Expand Down Expand Up @@ -49,6 +50,11 @@ class XFAParser extends XMLParserBase {
}

onText(text) {
if (this._current[$acceptWhitespace]()) {
this._current[$onText](text);
return;
}

if (this._whiteRegex.test(text)) {
return;
}
Expand Down