From e147cac0101dc2a5c40817cc86f58ad6a98d3537 Mon Sep 17 00:00:00 2001 From: Nikita Khromov Date: Fri, 14 Feb 2025 13:04:09 +0700 Subject: [PATCH] Fixes --- common/Drawings/CommonController.js | 4 +- pdf/api.js | 4 + pdf/src/GraphicObjects.js | 7 +- pdf/src/document.js | 81 +++++--- pdf/src/drawings/chart.js | 2 +- pdf/src/drawings/drawingPrototype.js | 2 +- pdf/src/drawings/graphicFrame.js | 2 +- pdf/src/drawings/image.js | 2 +- pdf/src/drawings/shape.js | 31 ++- pdf/src/drawings/smartArt.js | 2 +- pdf/src/forms/base/base.js | 79 +++++++- pdf/src/forms/text.js | 10 +- pdf/src/viewer.js | 210 +++++++++----------- word/Editor/GraphicObjects/DrawingStates.js | 15 ++ 14 files changed, 301 insertions(+), 150 deletions(-) diff --git a/common/Drawings/CommonController.js b/common/Drawings/CommonController.js index 98ec7d48a9..3847821d89 100644 --- a/common/Drawings/CommonController.js +++ b/common/Drawings/CommonController.js @@ -7266,7 +7266,7 @@ drawing = drawings[i]; // skip sticky note for pdf editor - if (drawing.IsAnnot && drawing.IsAnnot() && drawing.IsComment()) { + if (drawing.IsAnnot && drawing.IsAnnot() && drawing.IsComment() || drawing.IsEditFieldShape && drawing.IsEditFieldShape()) { continue; } @@ -7925,7 +7925,7 @@ let hyperlink_properties = null; if(drawings.length === 1) { let oDrawing = drawings[0]; - let isStickyNote = oDrawing.IsAnnot && oDrawing.IsAnnot() && oDrawing.IsComment(); // skip pdf text annot + let isStickyNote = oDrawing.IsAnnot && oDrawing.IsAnnot() && oDrawing.IsComment() || drawing.IsEditFieldShape && oDrawing.IsEditFieldShape(); // skip pdf text annot and form if(!isStickyNote && (oDrawing.isShape() || oDrawing.isImage())) { diff --git a/pdf/api.js b/pdf/api.js index 050f30eb8f..5641d171fb 100644 --- a/pdf/api.js +++ b/pdf/api.js @@ -1097,6 +1097,10 @@ ///////////////////////////////////////////////////////////// ///////// For filed //////////////////////////////////////////////////////////// + PDFEditorApi.prototype.SetEditFieldsMode = function(bEdit) { + let oDoc = this.getPDFDoc(); + oDoc.SetEditFieldsMode(bEdit); + }; PDFEditorApi.prototype.AddTextField = function() { let oDoc = this.getPDFDoc(); diff --git a/pdf/src/GraphicObjects.js b/pdf/src/GraphicObjects.js index d9bd7c52b0..0bd5279917 100644 --- a/pdf/src/GraphicObjects.js +++ b/pdf/src/GraphicObjects.js @@ -978,7 +978,7 @@ let oDoc = this.document; let isDrawHandles = oApi ? oApi.isShowShapeAdjustments() : true; - let oObject = AscCommon.g_oTableId.Get_ById(ret.objectId) || oDoc.GetShapeBasedAnnotById(ret.objectId); + let oObject = AscCommon.g_oTableId.Get_ById(ret.objectId) || oDoc.GetShapeBasedAnnotById(ret.objectId) || this.selectedObjects.find(function(obj) { return obj.GetId() == ret.objectId}); let isViewerObj = this.document.IsViewerObject(oObject); if (!isDrawHandles && isViewerObj) { @@ -1206,6 +1206,11 @@ for (i = 0; i < this.selectedObjects.length; ++i) { let oDrawing = this.selectedObjects[i]; if (oDrawing.selectStartPage === pageIndex) { + + if (oDrawing.IsForm()) { + oDrawing = oDrawing.editShape; + } + let nType = oDrawing.IsAnnot() && oDrawing.IsStamp() ? AscFormat.TYPE_TRACK.ANNOT_STAMP : AscFormat.TYPE_TRACK.SHAPE; if (oDrawing.IsAnnot() && (oDrawing.IsTextMarkup() || oDrawing.IsComment())) { diff --git a/pdf/src/document.js b/pdf/src/document.js index 7aefa138d8..290269c850 100644 --- a/pdf/src/document.js +++ b/pdf/src/document.js @@ -446,6 +446,16 @@ var CPresentation = CPresentation || function(){}; oField.SetDocument(this); return oField; }; + CPDFDoc.prototype.SetEditFieldsMode = function(bEdit) { + this.editFieldsMode = bEdit; + + this.widgets.forEach(function(field) { + field.SetEditMode(bEdit); + }); + }; + CPDFDoc.prototype.IsEditFieldsMode = function() { + return this.editFieldsMode; + }; CPDFDoc.prototype.CreateTextField = function(bDateField) { let oTextField = this.CreateField('TextField1', AscPDF.FIELD_TYPES.text, [200, 50, 350, 72]); @@ -1214,8 +1224,8 @@ var CPresentation = CPresentation || function(){}; oViewer.onMouseDownEpsilon(e); } - // если в селекте нет drawing (аннотации или шейпа) по которой кликнули, то сбрасываем селект - if (oMouseDownObject == null || (false == oController.selectedObjects.includes(oMouseDownObject) && oController.selection.groupSelection != oMouseDownObject)) { + // если в селекте нет drawing по которой кликнули, то сбрасываем селект + if (oMouseDownObject == null || (this.IsEditFieldsMode() == false && (false == oController.selectedObjects.includes(oMouseDownObject)) && oController.selection.groupSelection != oMouseDownObject)) { oController.resetSelection(); oController.resetTrackState(); } @@ -1819,6 +1829,11 @@ var CPresentation = CPresentation || function(){}; } // обработка mouseMove в полях else if (this.activeForm) { + if (this.IsEditFieldsMode()) { + oController.OnMouseMove(e, X, Y, pageObject.index); + return; + } + // селект текста внутри формы с редаткриуемым текстом if ([AscPDF.FIELD_TYPES.text, AscPDF.FIELD_TYPES.combobox].includes(this.activeForm.GetType())) { this.SelectionSetEnd(AscCommon.global_mouseEvent.X, AscCommon.global_mouseEvent.Y, e); @@ -1925,6 +1940,12 @@ var CPresentation = CPresentation || function(){}; else if (oCurObject.GetId() == oCursorInfo.objectId) { return true; } + else if (this.IsEditFieldsMode()) { + let oEditShape = oCurObject.GetEditShape && oCurObject.GetEditShape(); + if (oEditShape && oEditShape.GetId() == oCursorInfo.objectId) { + return true; + } + } } // курсор залочен для этих действий @@ -1939,29 +1960,34 @@ var CPresentation = CPresentation || function(){}; if (!pageObject) return false; - switch (oMouseMoveField.GetType()) { - case AscPDF.FIELD_TYPES.text: { - cursorType = "text"; - - if (oMouseMoveField.IsDateFormat() && oMouseMoveField.IsInForm()) { - // попадание в mark поля с датой - if (pageObject.x >= oMouseMoveField._markRect.x1 && pageObject.x <= oMouseMoveField._markRect.x2 && pageObject.y >= oMouseMoveField._markRect.y1 && pageObject.y <= oMouseMoveField._markRect.y2) { + if (this.IsEditFieldsMode()) { + cursorType = "pointer"; + } + else { + switch (oMouseMoveField.GetType()) { + case AscPDF.FIELD_TYPES.text: { + cursorType = "text"; + + if (oMouseMoveField.IsDateFormat() && oMouseMoveField.IsInForm()) { + // попадание в mark поля с датой + if (pageObject.x >= oMouseMoveField._markRect.x1 && pageObject.x <= oMouseMoveField._markRect.x2 && pageObject.y >= oMouseMoveField._markRect.y1 && pageObject.y <= oMouseMoveField._markRect.y2) { + cursorType = "pointer"; + } + } + break; + } + case AscPDF.FIELD_TYPES.combobox: { + cursorType = "text"; + + // попадание в mark выбора элементов списка + if (pageObject.x >= oMouseMoveField._markRect.x1 && pageObject.x <= oMouseMoveField._markRect.x2 && pageObject.y >= oMouseMoveField._markRect.y1 && pageObject.y <= oMouseMoveField._markRect.y2 && oMouseMoveField._options.length != 0) { cursorType = "pointer"; } + break; } - break; - } - case AscPDF.FIELD_TYPES.combobox: { - cursorType = "text"; - - // попадание в mark выбора элементов списка - if (pageObject.x >= oMouseMoveField._markRect.x1 && pageObject.x <= oMouseMoveField._markRect.x2 && pageObject.y >= oMouseMoveField._markRect.y1 && pageObject.y <= oMouseMoveField._markRect.y2 && oMouseMoveField._options.length != 0) { + default: cursorType = "pointer"; - } - break; } - default: - cursorType = "pointer"; } } else if (oMouseMoveAnnot) { @@ -2034,8 +2060,15 @@ var CPresentation = CPresentation || function(){}; return; } - if (this.mouseDownField && oMouseUpField == this.mouseDownField) { - this.OnMouseUpField(oMouseUpField, e); + if (this.mouseDownField) { + if (this.IsEditFieldsMode()) { + oController.OnMouseUp(e, X, Y, pageObject.index); + return; + } + + if (oMouseUpField == this.mouseDownField) { + this.OnMouseUpField(oMouseUpField, e); + } } else if (this.mouseDownAnnot) { oController.OnMouseUp(e, X, Y, pageObject.index); @@ -6335,7 +6368,7 @@ var CPresentation = CPresentation || function(){}; if (isRestrictionView) { for (let i = 0; i < selected_objects.length; i++) { - if (selected_objects[i].IsDrawing()) { + if (selected_objects[i].IsDrawing() && !selected_objects[i].IsEditFieldShape()) { return true; } } @@ -6768,7 +6801,7 @@ var CPresentation = CPresentation || function(){}; return this.Api.canEdit() && false == this.Api.IsCommentMarker(); }; CPDFDoc.prototype.IsViewerObject = function(oObject) { - return !!(oObject && oObject.IsAnnot && (oObject.IsAnnot() || oObject.IsForm() || oObject.group && oObject.group.IsAnnot())); + return !!(oObject && oObject.IsAnnot && (oObject.IsAnnot() || oObject.IsForm() || (oObject.IsDrawing() && oObject.IsEditFieldShape()) || oObject.group && oObject.group.IsAnnot())); }; CPDFDoc.prototype.IsFillingFormMode = function() { return false; diff --git a/pdf/src/drawings/chart.js b/pdf/src/drawings/chart.js index a699c89f7f..7487e3af2a 100644 --- a/pdf/src/drawings/chart.js +++ b/pdf/src/drawings/chart.js @@ -56,7 +56,7 @@ CPdfChart.prototype.constructor = CPdfChart; CPdfChart.prototype = Object.create(AscFormat.CChartSpace.prototype); - Object.assign(CPdfChart.prototype, AscPDF.PdfDrawingPrototype.prototype); + Object.assign(CPdfChart.prototype, AscPDF.CPdfDrawingPrototype.prototype); CPdfChart.prototype.IsChart = function() { return true; diff --git a/pdf/src/drawings/drawingPrototype.js b/pdf/src/drawings/drawingPrototype.js index e446c4b64e..5977ec7f64 100644 --- a/pdf/src/drawings/drawingPrototype.js +++ b/pdf/src/drawings/drawingPrototype.js @@ -444,6 +444,6 @@ this.toXml(memory, ''); }; - window["AscPDF"].PdfDrawingPrototype = CPdfDrawingPrototype; + window["AscPDF"].CPdfDrawingPrototype = CPdfDrawingPrototype; })(); diff --git a/pdf/src/drawings/graphicFrame.js b/pdf/src/drawings/graphicFrame.js index 833ae911e1..85342b6abf 100644 --- a/pdf/src/drawings/graphicFrame.js +++ b/pdf/src/drawings/graphicFrame.js @@ -43,7 +43,7 @@ CPdfGraphicFrame.prototype.constructor = CPdfGraphicFrame; CPdfGraphicFrame.prototype = Object.create(AscFormat.CGraphicFrame.prototype); - Object.assign(CPdfGraphicFrame.prototype, AscPDF.PdfDrawingPrototype.prototype); + Object.assign(CPdfGraphicFrame.prototype, AscPDF.CPdfDrawingPrototype.prototype); CPdfGraphicFrame.prototype.IsGraphicFrame = function() { return true; diff --git a/pdf/src/drawings/image.js b/pdf/src/drawings/image.js index 99654f6beb..502da0a06a 100644 --- a/pdf/src/drawings/image.js +++ b/pdf/src/drawings/image.js @@ -43,7 +43,7 @@ CPdfImage.prototype.constructor = CPdfImage; CPdfImage.prototype = Object.create(AscFormat.CImageShape.prototype); - Object.assign(CPdfImage.prototype, AscPDF.PdfDrawingPrototype.prototype); + Object.assign(CPdfImage.prototype, AscPDF.CPdfDrawingPrototype.prototype); CPdfImage.prototype.IsImage = function() { return true; diff --git a/pdf/src/drawings/shape.js b/pdf/src/drawings/shape.js index b28a3e887b..90d5a58637 100644 --- a/pdf/src/drawings/shape.js +++ b/pdf/src/drawings/shape.js @@ -42,11 +42,36 @@ CPdfShape.prototype.constructor = CPdfShape; CPdfShape.prototype = Object.create(AscFormat.CShape.prototype); - Object.assign(CPdfShape.prototype, AscPDF.PdfDrawingPrototype.prototype); + Object.assign(CPdfShape.prototype, AscPDF.CPdfDrawingPrototype.prototype); CPdfShape.prototype.IsShape = function() { return true; }; + CPdfShape.prototype.SetEditField = function(oForm) { + this.editField = oForm; + }; + CPdfShape.prototype.IsEditFieldShape = function() { + return !!this.editField; + }; + CPdfShape.prototype.GetEditField = function() { + return this.editField; + } + CPdfShape.prototype.GetDocument = function() { + if (this.IsEditFieldShape()) { + return this.editField.GetDocument(); + } + else { + return AscPDF.CPdfDrawingPrototype.prototype.GetDocument.call(this); + } + }; + CPdfShape.prototype.GetPage = function() { + if (this.IsEditFieldShape()) { + return this.editField.GetPage(); + } + else { + return AscPDF.CPdfDrawingPrototype.prototype.GetPage.call(this); + } + }; CPdfShape.prototype.ShouldDrawImaginaryBorder = function(graphicsWord) { let bDraw = !!(this.spPr && this.spPr.hasNoFill() && !(this.pen && this.pen.Fill && this.pen.Fill.fill && !(this.pen.Fill.fill instanceof AscFormat.CNoFill))); bDraw = bDraw && this.IsFromScan(); @@ -80,6 +105,10 @@ return false; } + if (this.IsEditFieldShape()) { + return false; + } + return this.getNoRot() === false; }; CPdfShape.prototype.Recalculate = function() { diff --git a/pdf/src/drawings/smartArt.js b/pdf/src/drawings/smartArt.js index 24b4d3b9eb..ffe8828b95 100644 --- a/pdf/src/drawings/smartArt.js +++ b/pdf/src/drawings/smartArt.js @@ -56,7 +56,7 @@ CPdfSmartArt.prototype.constructor = CPdfSmartArt; CPdfSmartArt.prototype = Object.create(AscFormat.SmartArt.prototype); - Object.assign(CPdfSmartArt.prototype, AscPDF.PdfDrawingPrototype.prototype); + Object.assign(CPdfSmartArt.prototype, AscPDF.CPdfDrawingPrototype.prototype); CPdfSmartArt.prototype.IsSmartArt = function() { return true; diff --git a/pdf/src/forms/base/base.js b/pdf/src/forms/base/base.js index f51cae3b6c..43bdc3a8a6 100644 --- a/pdf/src/forms/base/base.js +++ b/pdf/src/forms/base/base.js @@ -1312,6 +1312,11 @@ return this._needDrawHighlight; }; + CBaseField.prototype.DrawEdit = function(oGraphicsWord) { + if (this.IsEditMode()) { + this.editShape.Draw(oGraphicsWord); + } + }; CBaseField.prototype.AddToRedraw = function() { let oViewer = editor.getDocumentRenderer(); let nPage = this.GetPage(); @@ -1828,13 +1833,13 @@ } else { if (this.IsNeedDrawFromStream()) - this.DrawFromStream(pdfGraphics); + this.DrawFromStream(pdfGraphics, textBoxGraphics); else this.DrawFromTextBox(pdfGraphics, textBoxGraphics, pageIndex); } }; - CBaseField.prototype.DrawFromStream = function(oGraphicsPDF) { + CBaseField.prototype.DrawFromStream = function(oGraphicsPDF, oGraphicsWord) { let nAPType = this.IsHovered && this.IsHovered() ? AscPDF.APPEARANCE_TYPE.rollover : undefined; let originView = this.GetOriginView(nAPType, oGraphicsPDF.GetDrawingPageW(), oGraphicsPDF.GetDrawingPageH()); @@ -1865,6 +1870,7 @@ // oGraphicsPDF.Stroke(); this.DrawLocks(oGraphicsPDF); + this.DrawEdit(oGraphicsWord); }; CBaseField.prototype.DrawLocks = function(oGraphicsPDF) { let aOrigRect = this.GetRect(); @@ -2029,6 +2035,7 @@ CBaseField.prototype.SetRect = function(aOrigRect) { this._origRect = aOrigRect; this.SetWasChanged(true); + this.SetNeedRecalc(true); }; CBaseField.prototype.GetOrigRect = function() { return this._origRect; @@ -2166,6 +2173,74 @@ return oTextPr.FontSize; }; + CBaseField.prototype.SetEditMode = function(bEdit) { + if (bEdit == false) { + this.editShape = null; + this.AddToRedraw(); + return; + } + + AscCommon.History.StartNoHistoryMode(); + let oPdfShape = new AscPDF.CPdfShape(); + let aOrigRect = this.GetRect(); + let aRectMM = aOrigRect ? aOrigRect.map(function(measure) { + return measure * g_dKoef_pt_to_mm; + }) : []; + + let nOffX = aRectMM[0]; + let nOffY = aRectMM[1]; + let nExtX = aRectMM[2] - aRectMM[0]; + let nExtY = aRectMM[3] - aRectMM[1]; + + oPdfShape.setSpPr(new AscFormat.CSpPr()); + oPdfShape.spPr.setLn(new AscFormat.CLn()); + let oFill = AscFormat.CreateSolidFillRGBA(255, 255, 255, 0); + oFill.setTransparent(0); + + oPdfShape.spPr.ln.setFill(oFill); + oPdfShape.spPr.setFill(oFill); + oPdfShape.spPr.setParent(oPdfShape); + oPdfShape.spPr.setXfrm(new AscFormat.CXfrm()); + oPdfShape.spPr.xfrm.setParent(oPdfShape.spPr); + + oPdfShape.spPr.xfrm.setOffX(nOffX); + oPdfShape.spPr.xfrm.setOffY(nOffY); + oPdfShape.spPr.xfrm.setExtX(nExtX); + oPdfShape.spPr.xfrm.setExtY(nExtY); + + oPdfShape.spPr.setGeometry(AscFormat.CreateGeometry("rect")); + + oPdfShape.createTextBody(); + oPdfShape.txBody.bodyPr.setInsets(0.5,0.5,0.5,0.5); + oPdfShape.txBody.bodyPr.horzOverflow = AscFormat.nHOTClip; + oPdfShape.txBody.bodyPr.vertOverflow = AscFormat.nVOTClip; + oPdfShape.setVerticalAlign(AscFormat.VERTICAL_ANCHOR_TYPE_CENTER); + + let oContent = oPdfShape.GetDocContent(); + let oPara = oContent.GetElement(0); + let oRun = oPara.GetElement(0); + oRun.AddText(this.GetFullName()); + oPara.SetParagraphAlign(AscCommon.align_Center); + oPara.SetApplyToAll(true); + oPara.Add(new ParaTextPr({HighlightColor: AscFormat.CreateUniColorRGB(0, 0, 0)})); + oPara.SetApplyToAll(false); + + oPdfShape.setStyle(AscFormat.CreateDefaultShapeStyle()); + oPdfShape.setBDeleted(false); + oPdfShape.recalculate(); + + oPdfShape.SetEditField(this); + this.editShape = oPdfShape; + AscCommon.History.EndNoHistoryMode(); + + this.AddToRedraw(); + }; + CBaseField.prototype.IsEditMode = function() { + return !!this.editShape; + }; + CBaseField.prototype.GetEditShape = function() { + return this.editShape; + }; CBaseField.prototype.WriteToBinaryBase2 = function(memory) { // font name let sFontName = this.GetTextFont(); diff --git a/pdf/src/forms/text.js b/pdf/src/forms/text.js index 2d29fd7bb1..d5ffd6fbeb 100644 --- a/pdf/src/forms/text.js +++ b/pdf/src/forms/text.js @@ -339,7 +339,7 @@ oGraphicsWord.AddClipRect(this.contentClipRect.X, this.contentClipRect.Y, this.contentClipRect.W, this.contentClipRect.H); oContentToDraw.Draw(0, oGraphicsWord); - + oGraphicsWord.RemoveLastClip(); this.DrawBorders(oGraphicsPDF, oGraphicsWord); // redraw target cursor if field is selected @@ -348,6 +348,7 @@ this.DrawLocks(oGraphicsPDF); + this.DrawEdit(oGraphicsWord); }; CTextField.prototype.DrawDateMarker = function(oCtx) { if (this.IsHidden()) @@ -650,6 +651,13 @@ oDoc.activeForm = this; + if (oDoc.IsEditFieldsMode()) { + let oController = oDoc.GetController(); + this.editShape.select(oController, this.GetPage()); + this.editShape.onMouseDown(x, y, e); + return; + } + function callbackAfterFocus(x, y, e) { this.SetInForm(true); oDoc.SetLocalHistory(); diff --git a/pdf/src/viewer.js b/pdf/src/viewer.js index b9f0e77515..b418eb95c3 100644 --- a/pdf/src/viewer.js +++ b/pdf/src/viewer.js @@ -2841,145 +2841,127 @@ } }; - this.onUpdateOverlay = function() - { + this.onUpdateOverlay = function() { Asc.editor.checkLastWork(); + if (!this.overlay || this.scheduledRepaintTimer != null) return; + + const oDoc = this.getPDFDoc(); + const oDrDoc = oDoc.GetDrawingDocument(); + if (oDoc.fontLoader.isWorking() || this.IsOpenFormsInProgress) return; - if (!this.overlay || this.scheduledRepaintTimer != null) - return; - - let oDoc = this.getPDFDoc(); - let oDrDoc = oDoc.GetDrawingDocument(); - if (oDoc.fontLoader.isWorking() || this.IsOpenFormsInProgress) - return; - this.overlay.Clear(); - oDrDoc.AutoShapesTrack.PageIndex = -1; - - if (!this.file) - return; - - if (this.startVisiblePage < 0 || this.endVisiblePage < 0) - return; - - // seletion - var ctx = this.overlay.m_oContext; + + if (!this.file || this.startVisiblePage < 0 || this.endVisiblePage < 0) return; + + const ctx = this.overlay.m_oContext; ctx.globalAlpha = 0.2; - - if (this.IsSearch) - { - if (oDoc.SearchEngine.Show) - { - ctx.globalAlpha = 0.5; - ctx.fillStyle = "rgba(255,200,0,1)"; - ctx.beginPath(); - - for (let i = this.startVisiblePage; i <= this.endVisiblePage; i++) - { - var pageMatches = oDoc.SearchEngine.GetPdfPageMatches(i); - if (0 != pageMatches.length) { - oDrDoc.AutoShapesTrack.SetCurrentPage(i, true); - this.drawSearch(i, pageMatches); - } - - } - - ctx.fill(); - ctx.globalAlpha = 0.2; - } - ctx.beginPath(); - - if (this.CurrentSearchNavi && oDoc.SearchEngine.Show) - { - if (!(this.CurrentSearchNavi instanceof AscWord.Paragraph)) { - var pageNum = this.CurrentSearchNavi[0].PageNum; - ctx.fillStyle = "rgba(51,102,204,255)"; - if (pageNum >= this.startVisiblePage && pageNum <= this.endVisiblePage) - { - oDrDoc.AutoShapesTrack.SetCurrentPage(pageNum, true); - ctx.globalAlpha = 0.2; - this.drawSearchCur(pageNum, this.CurrentSearchNavi); - } - } - } + + if (this.IsSearch) { + this.drawSearchHighlights(ctx, oDoc, oDrDoc); + this.drawCurrentSearchHighlight(ctx, oDoc, oDrDoc); } - + oDrDoc.private_StartDrawSelection(this.overlay); + this.drawSelection(ctx, oDoc, oDrDoc); - //if (!this.MouseHandObject) - { - ctx.fillStyle = "rgba(51,102,204,255)"; + if (oDoc.activeForm && oDoc.activeForm.content && oDoc.activeForm.content.IsSelectionUse() && !oDoc.activeForm.content.IsSelectionEmpty()) { ctx.beginPath(); - - if (this.file.isSelectionUse()) - { - for (let i = this.startVisiblePage; i <= this.endVisiblePage; i++) - { - var pageCoords = this.pageDetector.pages[i - this.startVisiblePage]; - ctx.beginPath(); - oDrDoc.AutoShapesTrack.SetCurrentPage(i, true); - ctx.globalAlpha = 0.2; - this.file.drawSelection(i, this.overlay, pageCoords.x, pageCoords.y); - ctx.fill(); - } + oDoc.activeForm.content.DrawSelectionOnPage(0); + oDrDoc.private_EndDrawSelection(); + } + + if (oDrDoc.MathTrack.IsActive()) { + const prevAlpha = ctx.globalAlpha; + ctx.globalAlpha = 1.0; + oDrDoc.DrawMathTrack(this.overlay); + ctx.globalAlpha = prevAlpha; + } + + this.drawForeignSelections(oDoc, oDrDoc, ctx); + }; + + this.drawSearchHighlights = function(ctx, oDoc, oDrDoc) { + if (!oDoc.SearchEngine.Show) return; + ctx.globalAlpha = 0.5; + ctx.fillStyle = "rgba(255,200,0,1)"; + ctx.beginPath(); + for (let i = this.startVisiblePage; i <= this.endVisiblePage; i++) { + const matches = oDoc.SearchEngine.GetPdfPageMatches(i); + if (matches.length) { + oDrDoc.AutoShapesTrack.SetCurrentPage(i, true); + this.drawSearch(i, matches); } - - this.DrawingObjects.updateSelectionState(); - - if (this.DrawingObjects.needUpdateOverlay()) - { - oDrDoc.AutoShapesTrack.PageIndex = -1; - this.DrawingObjects.drawOnOverlay(oDrDoc.AutoShapesTrack); - oDrDoc.AutoShapesTrack.CorrectOverlayBounds(); + } + ctx.fill(); + ctx.globalAlpha = 0.2; + }; + + this.drawCurrentSearchHighlight = function(ctx, oDoc, oDrDoc) { + if (this.CurrentSearchNavi && oDoc.SearchEngine.Show && !(this.CurrentSearchNavi instanceof AscWord.Paragraph)) { + const pageNum = this.CurrentSearchNavi[0].PageNum; + if (pageNum >= this.startVisiblePage && pageNum <= this.endVisiblePage) { + ctx.fillStyle = "rgba(51,102,204,255)"; + oDrDoc.AutoShapesTrack.SetCurrentPage(pageNum, true); + ctx.globalAlpha = 0.2; + this.drawSearchCur(pageNum, this.CurrentSearchNavi); } - else if (oDoc.mouseDownAnnot) - { - if (oDoc.mouseDownAnnot.IsFreeText() && oDoc.mouseDownAnnot.IsInTextBox() && oDoc.mouseDownAnnot.GetDocContent().IsSelectionUse()) { - ctx.beginPath(); - oDrDoc.SetTextSelectionOutline(true); - oDoc.mouseDownAnnot.GetDocContent().DrawSelectionOnPage(0); - oDrDoc.private_EndDrawSelection(); - } - else { - let nPage = oDoc.mouseDownAnnot.GetPage(); - oDrDoc.AutoShapesTrack.SetCurrentPage(nPage, true); - this.DrawingObjects.drawSelect(nPage); - } + } + }; + + this.drawSelection = function(ctx, oDoc, oDrDoc) { + ctx.fillStyle = "rgba(51,102,204,255)"; + ctx.beginPath(); + if (this.file.isSelectionUse()) { + for (let i = this.startVisiblePage; i <= this.endVisiblePage; i++) { + const pageCoords = this.pageDetector.pages[i - this.startVisiblePage]; + ctx.beginPath(); + oDrDoc.AutoShapesTrack.SetCurrentPage(i, true); + ctx.globalAlpha = 0.2; + this.file.drawSelection(i, this.overlay, pageCoords.x, pageCoords.y); + ctx.fill(); } - else if (oDoc.activeDrawing) { - let nPage = oDoc.activeDrawing.GetPage(); + } + + this.DrawingObjects.updateSelectionState(); + + if (this.DrawingObjects.needUpdateOverlay()) { + oDrDoc.AutoShapesTrack.PageIndex = -1; + this.DrawingObjects.drawOnOverlay(oDrDoc.AutoShapesTrack); + oDrDoc.AutoShapesTrack.CorrectOverlayBounds(); + } + else if (oDoc.mouseDownAnnot) { + if (oDoc.mouseDownAnnot.IsFreeText() && oDoc.mouseDownAnnot.IsInTextBox() && oDoc.mouseDownAnnot.GetDocContent().IsSelectionUse()) { + ctx.beginPath(); oDrDoc.SetTextSelectionOutline(true); + oDoc.mouseDownAnnot.GetDocContent().DrawSelectionOnPage(0); oDrDoc.private_EndDrawSelection(); - oDrDoc.AutoShapesTrack.PageIndex = nPage; + } + else { + const nPage = oDoc.mouseDownAnnot.GetPage(); + oDrDoc.AutoShapesTrack.SetCurrentPage(nPage, true); this.DrawingObjects.drawSelect(nPage); } } - if (oDoc.activeForm && oDoc.activeForm.content && oDoc.activeForm.content.IsSelectionUse() && oDoc.activeForm.content.IsSelectionEmpty() == false) - { - ctx.beginPath(); - oDoc.activeForm.content.DrawSelectionOnPage(0); + else if (oDoc.activeDrawing || (oDoc.activeForm && oDoc.IsEditFieldsMode())) { + let oObj = oDoc.activeDrawing || oDoc.activeForm; + const nPage = oObj.GetPage(); + oDrDoc.SetTextSelectionOutline(true); oDrDoc.private_EndDrawSelection(); + oDrDoc.AutoShapesTrack.PageIndex = nPage; + this.DrawingObjects.drawSelect(nPage); } - - if (oDrDoc.MathTrack.IsActive()) - { - var dGlobalAplpha = ctx.globalAlpha; - ctx.globalAlpha = 1.0; - oDrDoc.DrawMathTrack(this.overlay); - ctx.globalAlpha = dGlobalAplpha; - } - - ctx.globalAlpha = 1.0; - - for (let i = this.startVisiblePage; i <= this.endVisiblePage; i++) - { + }; + + this.drawForeignSelections = function(oDoc, oDrDoc, ctx) { + for (let i = this.startVisiblePage; i <= this.endVisiblePage; i++) { oDrDoc.AutoShapesTrack.SetCurrentPage(i, true); ctx.globalAlpha = 1.0; oDoc.Draw_ForeingSelection(i); oDoc.CollaborativeEditing.Update_ForeignSelectedObjectsLabelsPositions(i); } }; + this.checkVisiblePages = function() { diff --git a/word/Editor/GraphicObjects/DrawingStates.js b/word/Editor/GraphicObjects/DrawingStates.js index bcda35999a..4d451082f4 100644 --- a/word/Editor/GraphicObjects/DrawingStates.js +++ b/word/Editor/GraphicObjects/DrawingStates.js @@ -452,12 +452,21 @@ NullState.prototype = } else { let oViewer = Asc.editor.getDocumentRenderer(); + let oDoc = Asc.editor.getPDFDoc(); let aDrawings = []; aDrawings = aDrawings.concat(oViewer.pagesInfo.pages[pageIndex].drawings); aDrawings = aDrawings.concat(oViewer.pagesInfo.pages[pageIndex].annots); + if (oDoc.IsEditFieldsMode()) { + if (this.drawingObjects.selectedObjects.find(function(obj) { + return obj.IsDrawing() && obj.IsEditFieldShape(); + })) { + aDrawings = aDrawings.concat(this.drawingObjects.selectedObjects); + } + } + ret = AscFormat.handleFloatObjects(this.drawingObjects, aDrawings, e, x, y, null, pageIndex, true); if(ret) @@ -947,6 +956,12 @@ RotateState.prototype = oTrack.originalObject.SetPage(oTrack.pageIndex); } } + if (oTrack.originalObject.IsDrawing() && oTrack.originalObject.IsEditFieldShape()) { + let aRect = [bounds.posX * g_dKoef_mm_to_pt, bounds.posY * g_dKoef_mm_to_pt, (bounds.posX + bounds.extX) * g_dKoef_mm_to_pt, (bounds.posY + bounds.extY) * g_dKoef_mm_to_pt]; + let oField = oTrack.originalObject.GetEditField(); + + oField.SetRect(aRect); + } oTrack.originalObject.SetNeedRecalc(true); }