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

Render rich text with only one text element #17216

Merged
merged 1 commit into from
Nov 2, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/display/xfa_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ class XfaLayer {
linkService,
});
}
const stack = [[root, -1, rootHtml]];

const isNotForRichText = intent !== "richText";
const rootDiv = parameters.div;
rootDiv.append(rootHtml);

Expand All @@ -187,13 +187,28 @@ class XfaLayer {
}

// Set defaults.
if (intent !== "richText") {
if (isNotForRichText) {
rootDiv.setAttribute("class", "xfaLayer xfaFont");
}

// Text nodes used for the text highlighter.
const textDivs = [];

// In the rich text context, it's possible to just have a text node without
// a root element, so we handle this case here (see issue 17215).
if (root.children.length === 0) {
if (root.value) {
const node = document.createTextNode(root.value);
rootHtml.append(node);
if (isNotForRichText && XfaText.shouldBuildText(root.name)) {
textDivs.push(node);
}
}
return { textDivs };
}

const stack = [[root, -1, rootHtml]];

while (stack.length > 0) {
const [parent, i, html] = stack.at(-1);
if (i + 1 === parent.children.length) {
Expand Down Expand Up @@ -233,7 +248,7 @@ class XfaLayer {
stack.push([child, -1, childHtml]);
} else if (child.value) {
const node = document.createTextNode(child.value);
if (XfaText.shouldBuildText(name)) {
if (isNotForRichText && XfaText.shouldBuildText(name)) {
textDivs.push(node);
}
childHtml.append(node);
Expand Down
2 changes: 2 additions & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -617,3 +617,5 @@
!bug1851498.pdf
!issue17065.pdf
!issue17069.pdf
!issue17215.pdf

Binary file added test/pdfs/issue17215.pdf
Binary file not shown.
10 changes: 9 additions & 1 deletion test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8189,5 +8189,13 @@
"link": true,
"rounds": 1,
"type": "eq"
}
},
{
"id": "issue17215-annotations",
"file": "pdfs/issue17215.pdf",
"md5": "968848af6ef593a3d1d6aba030ef47cb",
"rounds": 1,
"type": "eq",
"annotations": true
}
]