Merge pull request #17216 from calixteman/issue17215

Render rich text with only one text element
This commit is contained in:
calixteman 2023-11-02 16:42:01 +01:00 committed by GitHub
commit f528f6f07b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 4 deletions

View File

@ -176,8 +176,8 @@ class XfaLayer {
linkService,
});
}
const stack = [[root, -1, rootHtml]];
const isNotForRichText = intent !== "richText";
const rootDiv = parameters.div;
rootDiv.append(rootHtml);
@ -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) {
@ -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);

View File

@ -617,3 +617,5 @@
!bug1851498.pdf
!issue17065.pdf
!issue17069.pdf
!issue17215.pdf

BIN
test/pdfs/issue17215.pdf Executable file

Binary file not shown.

View File

@ -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
}
]