Preserve the whitespaces when getting text from FreeText annotations (bug 1871353)

When the text of an annotation is extracted in using getTextContent, consecutive white spaces
are just replaced by one space and. So this patch add an option to make sure that white
spaces are preserved when appearance is parsed.
For the case where there's no appearance, we can have a fast path to get the correct string
from the Content entry.
When an existing FreeText is edited, space (0x20) are replaced by non-breakable (0xa0) ones
to make to see all of them on screen.
This commit is contained in:
Calixte Denizet 2023-12-21 22:57:58 +01:00
parent 1019b9f821
commit 7839e7b495
8 changed files with 152 additions and 36 deletions

View file

@ -2281,6 +2281,7 @@ class PartialEvaluator {
viewBox,
markedContentData = null,
disableNormalization = false,
keepWhiteSpace = false,
}) {
// Ensure that `resources`/`stateManager` is correctly initialized,
// even if the provided parameter is e.g. `null`.
@ -2347,11 +2348,12 @@ class PartialEvaluator {
twoLastChars[twoLastCharsPos] = char;
twoLastCharsPos = nextPos;
return ret;
return !keepWhiteSpace && ret;
}
function shouldAddWhitepsace() {
return (
!keepWhiteSpace &&
twoLastChars[twoLastCharsPos] !== " " &&
twoLastChars[(twoLastCharsPos + 1) % 2] === " "
);
@ -2836,7 +2838,7 @@ class PartialEvaluator {
}
let scaledDim = glyphWidth * scale;
if (category.isWhitespace) {
if (!keepWhiteSpace && category.isWhitespace) {
// Don't push a " " in the textContentItem
// (except when it's between two non-spaces chars),
// it will be done (if required) in next call to
@ -3272,6 +3274,7 @@ class PartialEvaluator {
viewBox,
markedContentData,
disableNormalization,
keepWhiteSpace,
})
.then(function () {
if (!sinkWrapper.enqueueInvoked) {