Skip to content

Commit

Permalink
[pdf] Work with history for free text annot
Browse files Browse the repository at this point in the history
  • Loading branch information
KhromovNikita committed Feb 7, 2024
1 parent 17b2ded commit 0d102ec
Show file tree
Hide file tree
Showing 13 changed files with 638 additions and 169 deletions.
8 changes: 8 additions & 0 deletions common/Drawings/DrawingObjectsHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,10 @@ function handleShapeImage(drawing, drawingObjectsController, e, x, y, group, pag
let hit_in_inner_area = drawing.hitInInnerArea && drawing.hitInInnerArea(x, y);
let hit_in_path = drawing.hitInPath && drawing.hitInPath(x, y);
let hit_in_text_rect = drawing.hitInTextRect && drawing.hitInTextRect(x, y);
if (drawing.group && drawing.group.IsFreeText && drawing.group.IsFreeText() && drawing.group.IsInTextBox() == false) {
hit_in_text_rect = false;
}

if(hit_in_inner_area || hit_in_path || hit_in_text_rect)
{
let oCheckResult = drawingObjectsController.checkDrawingHyperlinkAndMacro(drawing, e, hit_in_text_rect, x, y, pageIndex);
Expand Down Expand Up @@ -552,6 +556,10 @@ function handleShapeImageInGroup(drawingObjectsController, drawing, shape, e, x,
var hit_in_inner_area = shape.hitInInnerArea && shape.hitInInnerArea(x, y);
var hit_in_path = shape.hitInPath && shape.hitInPath(x, y);
var hit_in_text_rect = shape.hitInTextRect && shape.hitInTextRect(x, y);
if (shape.group.IsFreeText && shape.group.IsFreeText() && shape.group.IsInTextBox() == false) {
hit_in_text_rect = false;
}

var ret;
if(hit_in_inner_area || hit_in_path || hit_in_text_rect)
{
Expand Down
42 changes: 34 additions & 8 deletions pdf/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@
return;

let oDoc = this.DocumentRenderer.getPDFDoc();
var oActiveForm = oDoc.activeForm;
let oActiveForm = oDoc.activeForm;
let oActiveAnnot = oDoc.mouseDownAnnot;
if (oActiveForm && oActiveForm.content.IsSelectionUse()) {
let sText = oActiveForm.content.GetSelectedText(true);
if (!sText)
Expand All @@ -176,6 +177,17 @@
if (AscCommon.c_oAscClipboardDataFormat.Html & _formats)
_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(true);
if (!sText)
return;

if (AscCommon.c_oAscClipboardDataFormat.Text & _formats)
_clipboard.pushData(AscCommon.c_oAscClipboardDataFormat.Text, sText);

if (AscCommon.c_oAscClipboardDataFormat.Html & _formats)
_clipboard.pushData(AscCommon.c_oAscClipboardDataFormat.Html, "<div><p><span>" + sText + "</span></p></div>");
}
else {
let _text_object = {Text: ""};
let _html_data = this.DocumentRenderer.Copy(_text_object);
Expand All @@ -192,10 +204,20 @@
return;
let oDoc = this.DocumentRenderer.getPDFDoc();
let oField = oDoc.activeForm;
let oActiveAnnot = oDoc.mouseDownAnnot;
if (oField && oField.IsCanEditText()) {
if (oField.content.IsSelectionUse()) {
oField.Remove(-1);
this.DocumentRenderer._paint();
this.DocumentRenderer.onUpdateOverlay();
this.WordControl.m_oDrawingDocument.TargetStart();
this.WordControl.m_oDrawingDocument.showTarget(true);
oDoc.UpdateCopyCutState();
}
}
else if (oActiveAnnot && oActiveAnnot.IsFreeText() && oActiveAnnot.IsInTextBox()) {
let oContent = oActiveAnnot.GetDocContent();
if (oContent.IsSelectionUse()) {
oActiveAnnot.Remove(-1);
this.DocumentRenderer.onUpdateOverlay();
this.WordControl.m_oDrawingDocument.TargetStart();
this.WordControl.m_oDrawingDocument.showTarget(true);
Expand Down Expand Up @@ -372,14 +394,18 @@

let viewer = this.DocumentRenderer;
let oDoc = viewer.getPDFDoc();
if (!viewer
|| !oDoc.checkFieldFont(oDoc.activeForm)
|| !oDoc.activeForm
|| !oDoc.activeForm.IsCanEditText()) {
let oActiveForm = oDoc.activeForm;
let oActiveAnnot = oDoc.mouseDownAnnot;

if (!oDoc || !viewer || (!oActiveForm && !oActiveAnnot))
return false;

let isEntered = false;
if (oActiveForm && oDoc.checkFieldFont(oActiveForm) && oActiveForm.IsCanEditText()) {
isEntered = oActiveForm.EnterText(text);
}

let isEntered = oDoc.activeForm.EnterText(text);
else if (oActiveAnnot && oActiveAnnot.IsFreeText() && oActiveAnnot.IsInTextBox())
isEntered = oActiveAnnot.EnterText(text);

if (isEntered) {
this.WordControl.m_oDrawingDocument.TargetStart();
Expand Down
21 changes: 17 additions & 4 deletions pdf/src/annotations/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,15 @@
CAnnotationBase.prototype.IsFreeText = function() {
return false;
};
CAnnotationBase.prototype.SetNeedRecalc = function(bRecalc) {
this._needRecalc = bRecalc;
CAnnotationBase.prototype.SetNeedRecalc = function(bRecalc, bSkipAddToRedraw) {
if (bRecalc == false) {
this._needRecalc = false;
}
else {
this._needRecalc = true;
if (bSkipAddToRedraw != true)
this.AddToRedraw();
}
};
CAnnotationBase.prototype.IsNeedRecalc = function() {
return this._needRecalc;
Expand Down Expand Up @@ -828,8 +835,14 @@
};
CAnnotationBase.prototype.AddToRedraw = function() {
let oViewer = editor.getDocumentRenderer();
if (oViewer.pagesInfo.pages[this.GetPage()])
oViewer.pagesInfo.pages[this.GetPage()].needRedrawAnnots = true;
let _t = this;

function setRedrawPageOnRepaint() {
if (oViewer.pagesInfo.pages[_t.GetPage()])
oViewer.pagesInfo.pages[_t.GetPage()].needRedrawAnnots = true;
}

oViewer.paint(setRedrawPageOnRepaint);
};
/**
* Gets rgb color object from internal color array.
Expand Down
Loading

0 comments on commit 0d102ec

Please sign in to comment.