Skip to content

Commit

Permalink
Fix bug #70236
Browse files Browse the repository at this point in the history
  • Loading branch information
KhromovNikita committed Oct 1, 2024
1 parent dd1c194 commit 7474c67
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 8 deletions.
7 changes: 2 additions & 5 deletions pdf/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@
let oActiveDrawing = oDoc.activeDrawing;

if (oActiveForm && oActiveForm.content.IsSelectionUse()) {
let sText = oActiveForm.content.GetSelectedText(false);
let sText = oActiveForm.content.GetSelectedText(false, {NewLine: true});
if (!sText)
return;

Expand All @@ -259,7 +259,7 @@
_clipboard.pushData(AscCommon.c_oAscClipboardDataFormat.Html, "<div><p><span>" + sText + "</span></p></div>");
}
else if (oActiveAnnot && oActiveAnnot.IsFreeText() && oActiveAnnot.IsInTextBox()) {
let sText = oActiveAnnot.GetDocContent().GetSelectedText(false);
let sText = oActiveAnnot.GetDocContent().GetSelectedText(false, {NewLine: true});
if (!sText)
return;

Expand Down Expand Up @@ -378,9 +378,6 @@
if (!this.needPasteText || typeof(data) != "string")
return;

if (oActiveForm && (oActiveForm.GetType() != AscPDF.FIELD_TYPES.text || oActiveForm.IsMultiline() == false))
data = data.trim().replace(/[\n\r]/g, ' ');

AscFonts.FontPickerByCharacter.checkText(data, this, processPaste);

function processPaste() {
Expand Down
22 changes: 20 additions & 2 deletions pdf/src/annotations/freeText.js
Original file line number Diff line number Diff line change
Expand Up @@ -1030,8 +1030,26 @@
};
CAnnotationFreeText.prototype.EnterText = function(value) {
let docContent = this.GetDocContent();

let result = docContent.EnterText(value);
let codePoints = typeof(value) === "string" ? value.codePointsArray() : value;

function correctCodePoints(codePoints) {
function correctCodePoint(codePoint) {
if ([9, 10, 13].includes(codePoint)) {
return 32;
}
else {
return codePoint;
}
}

if (Array.isArray(codePoints)) {
return codePoints.map(correctCodePoint);
}

return correctCodePoint(codePoints);
};

let result = docContent.EnterText(correctCodePoints(codePoints));
this.OnChangeTextContent();
return result;
};
Expand Down
2 changes: 1 addition & 1 deletion pdf/src/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -2819,7 +2819,7 @@ var CPresentation = CPresentation || function(){};
let oContent;
if (oForm) {
if (oForm.GetType() == AscPDF.FIELD_TYPES.text && oForm.IsCanEditText() && oForm.IsMultiline()) {
oForm.EnterText([13]);
Asc.editor.asc_enterText([13]);
oContent = oForm.GetDocContent();
}
else {
Expand Down
43 changes: 43 additions & 0 deletions pdf/src/forms/textBoxContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,49 @@
this.MoveCursorToEndPos();
}
};
CTextBoxContent.prototype.EnterText = function(value) {
let oParentPDF = this.ParentPDF;
let isAllowLineBreak = oParentPDF.IsForm() && oForm.GetType() == AscPDF.FIELD_TYPES.text && oParentPDF.IsMultiline();

if (undefined === value
|| null === value
|| (Array.isArray(value) && !value.length))
return false;

let codePoints = typeof(value) === "string" ? value.codePointsArray() : value;

if (Array.isArray(codePoints)) {
for (let index = 0, count = codePoints.length; index < count; ++index) {
let codePoint = codePoints[index];
addToParagraph.call(this, codePoint);
}
}
else {
addToParagraph.call(this, codePoints);
}

function addToParagraph(codePoint) {
if ((10 === codePoint || 13 === codePoint)) {
if (isAllowLineBreak) {
this.AddToParagraph(new AscWord.CRunBreak(AscWord.break_Line));
}
else {
this.AddToParagraph(new AscWord.CRunSpace(32));
}
}
else if (9 === codePoint) {
this.AddToParagraph(new AscWord.CRunSpace(32));
}
else if (AscCommon.IsSpace(codePoint)) {
this.AddToParagraph(new AscWord.CRunSpace(codePoint));
}
else {
this.AddToParagraph(new AscWord.CRunText(codePoint));
}
}

return true;
};
CTextBoxContent.prototype.getAllText = function() {
let paragraph = this.GetElement(0);
if (!paragraph || !paragraph.IsParagraph())
Expand Down

0 comments on commit 7474c67

Please sign in to comment.