From e96f51d3d315b2a2f74d47e29587bfbd2eab6095 Mon Sep 17 00:00:00 2001 From: Nikita Khromov Date: Thu, 6 Feb 2025 16:53:38 +0700 Subject: [PATCH] Fix --- pdf/src/annotations/base.js | 15 ++++++++++++++- pdf/src/annotations/circle.js | 6 ++++-- pdf/src/annotations/freeText.js | 6 ++++++ pdf/src/annotations/ink.js | 6 ++++++ pdf/src/annotations/line.js | 7 +++++++ pdf/src/annotations/polyLine.js | 8 +++++++- pdf/src/annotations/polygon.js | 7 +++++++ pdf/src/annotations/square.js | 6 ++++++ pdf/src/annotations/stamp.js | 29 ++++++++++++++++++++--------- pdf/src/document.js | 3 +++ 10 files changed, 80 insertions(+), 13 deletions(-) diff --git a/pdf/src/annotations/base.js b/pdf/src/annotations/base.js index 6cae3f14d6..61789969b4 100644 --- a/pdf/src/annotations/base.js +++ b/pdf/src/annotations/base.js @@ -411,8 +411,21 @@ return null; oApInfoTmp = oApearanceInfo["N"]; - oSavedView = this._originView.normal; + + // for stamp save info in stamp + if (this.GetCopyOfApIdx() != -1 && !this.IsStamp()) { + let _t = this; + let oDoc = this.GetDocument(); + let oCopyOf = oDoc.annots.find(function(annot) { + return annot.GetApIdx() == _t.GetCopyOfApIdx(); + }); + if (oCopyOf) { + this._originView.normal = oCopyOf._originView.normal; + } + } + + oSavedView = this._originView.normal; if (oSavedView) { if (oSavedView.width == oApearanceInfo["w"] && oSavedView.height == oApearanceInfo["h"]) { return oSavedView; diff --git a/pdf/src/annotations/circle.js b/pdf/src/annotations/circle.js index ee43568686..b498681de0 100644 --- a/pdf/src/annotations/circle.js +++ b/pdf/src/annotations/circle.js @@ -75,6 +75,7 @@ let aFillColor = this.GetFillColor(); let aRD = this.GetRectangleDiff(); + oCircle._copyApIdx = this._copyApIdx; oCircle._apIdx = this._apIdx; oCircle._originView = this._originView; oCircle.SetOriginPage(this.GetOriginPage()); @@ -123,10 +124,11 @@ this.FillCommentsDataTo(oCircle); - if (this.IsNeedDrawFromStream()) { + if ((this.IsUseInDocument() && this.IsNeedDrawFromStream()) || !this.IsChanged() || this.GetCopyOfApIdx() != -1) { + oCircle.SetCopyOfApIdx(this.GetCopyOfApIdx() != -1 ? this.GetCopyOfApIdx() : this.GetApIdx()); oCircle.SetDrawFromStream(true); } - + return oCircle; }; CAnnotationCircle.prototype.RefillGeometry = function(oGeometry, aShapeRectInMM) { diff --git a/pdf/src/annotations/freeText.js b/pdf/src/annotations/freeText.js index 2daa87e09b..17a496f1b5 100644 --- a/pdf/src/annotations/freeText.js +++ b/pdf/src/annotations/freeText.js @@ -492,6 +492,7 @@ let aCallout = this.GetCallout(); let aRD = this.GetRectangleDiff(); + oFreeText._copyApIdx = this._copyApIdx; oFreeText._apIdx = this._apIdx; oFreeText._originView = this._originView; oFreeText.SetOriginPage(this.GetOriginPage()); @@ -541,6 +542,11 @@ this.FillCommentsDataTo(oFreeText); + if ((this.IsUseInDocument() && this.IsNeedDrawFromStream()) || !this.IsChanged() || this.GetCopyOfApIdx() != -1) { + oFreeText.SetCopyOfApIdx(this.GetCopyOfApIdx() != -1 ? this.GetCopyOfApIdx() : this.GetApIdx()); + oFreeText.SetDrawFromStream(true); + } + return oFreeText; }; CAnnotationFreeText.prototype.Recalculate = function() { diff --git a/pdf/src/annotations/ink.js b/pdf/src/annotations/ink.js index a0a7ea4910..155a46c266 100644 --- a/pdf/src/annotations/ink.js +++ b/pdf/src/annotations/ink.js @@ -350,6 +350,7 @@ let aStrokeColor = this.GetStrokeColor(); + oNewInk._copyApIdx = this._copyApIdx; oNewInk._apIdx = this._apIdx; oNewInk._originView = this._originView; oNewInk.SetOriginPage(this.GetOriginPage()); @@ -391,6 +392,11 @@ this.FillCommentsDataTo(oNewInk); + if ((this.IsUseInDocument() && this.IsNeedDrawFromStream()) || !this.IsChanged() || this.GetCopyOfApIdx() != -1) { + oNewInk.SetCopyOfApIdx(this.GetCopyOfApIdx() != -1 ? this.GetCopyOfApIdx() : this.GetApIdx()); + oNewInk.SetDrawFromStream(true); + } + return oNewInk; }; CAnnotationInk.prototype.GetRelativePaths = function() { diff --git a/pdf/src/annotations/line.js b/pdf/src/annotations/line.js index 34173e54c4..b1ec35c895 100644 --- a/pdf/src/annotations/line.js +++ b/pdf/src/annotations/line.js @@ -204,6 +204,7 @@ let aFillColor = this.GetFillColor(); let aLinePoints = this.GetLinePoints(); + oLine._copyApIdx = this._copyApIdx; oLine._apIdx = this._apIdx; oLine._originView = this._originView; oLine.SetOriginPage(this.GetOriginPage()); @@ -253,6 +254,12 @@ oLine.recalculate(); this.FillCommentsDataTo(oLine); + + if ((this.IsUseInDocument() && this.IsNeedDrawFromStream()) || !this.IsChanged() || this.GetCopyOfApIdx() != -1) { + oLine.SetCopyOfApIdx(this.GetCopyOfApIdx() != -1 ? this.GetCopyOfApIdx() : this.GetApIdx()); + oLine.SetDrawFromStream(true); + } + return oLine; }; CAnnotationLine.prototype.IsLine = function() { diff --git a/pdf/src/annotations/polyLine.js b/pdf/src/annotations/polyLine.js index 5116b2ff53..f32243009a 100644 --- a/pdf/src/annotations/polyLine.js +++ b/pdf/src/annotations/polyLine.js @@ -148,6 +148,7 @@ let aFillColor = this.GetFillColor(); let aVertices = this.GetVertices(); + oPolyline._copyApIdx = this._copyApIdx; oPolyline._apIdx = this._apIdx; oPolyline._originView = this._originView; oPolyline.SetOriginPage(this.GetOriginPage()); @@ -181,7 +182,6 @@ let aFillColor = this.GetFillColor(); let aVertices = this.GetVertices(); - oPolyline.SetCopyOfApIdx(this.GetCopyOfApIdx() != -1 ? this.GetCopyOfApIdx() : this.GetApIdx()); oPolyline.SetOriginPage(this.GetOriginPage()); oPolyline.SetAuthor(AscCommon.UserInfoParser.getCurrentName()); oPolyline.SetModDate(sDate); @@ -198,6 +198,12 @@ oPolyline.recalcInfo.recalculateGeometry = true; this.FillCommentsDataTo(oPolyline); + + if ((this.IsUseInDocument() && this.IsNeedDrawFromStream()) || !this.IsChanged() || this.GetCopyOfApIdx() != -1) { + oPolyline.SetCopyOfApIdx(this.GetCopyOfApIdx() != -1 ? this.GetCopyOfApIdx() : this.GetApIdx()); + oPolyline.SetDrawFromStream(true); + } + return oPolyline; }; CAnnotationPolyLine.prototype.onMouseDown = function(x, y, e) { diff --git a/pdf/src/annotations/polygon.js b/pdf/src/annotations/polygon.js index 703cf159f7..e8d319f512 100644 --- a/pdf/src/annotations/polygon.js +++ b/pdf/src/annotations/polygon.js @@ -157,6 +157,7 @@ let aFillColor = this.GetFillColor(); let aVertices = this.GetVertices(); + oPolygon._copyApIdx = this._copyApIdx; oPolygon._apIdx = this._apIdx; oPolygon._originView = this._originView; oPolygon.SetOriginPage(this.GetOriginPage()); @@ -207,6 +208,12 @@ oPolygon.recalculate(); this.FillCommentsDataTo(oPolygon); + + if ((this.IsUseInDocument() && this.IsNeedDrawFromStream()) || !this.IsChanged() || this.GetCopyOfApIdx() != -1) { + oPolygon.SetCopyOfApIdx(this.GetCopyOfApIdx() != -1 ? this.GetCopyOfApIdx() : this.GetApIdx()); + oPolygon.SetDrawFromStream(true); + } + return oPolygon; }; CAnnotationPolygon.prototype.onMouseDown = function(x, y, e) { diff --git a/pdf/src/annotations/square.js b/pdf/src/annotations/square.js index 66a681c50d..0ee09398ce 100644 --- a/pdf/src/annotations/square.js +++ b/pdf/src/annotations/square.js @@ -72,6 +72,7 @@ let aFillColor = this.GetFillColor(); let aRD = this.GetRectangleDiff(); + oSquare._copyApIdx = this._copyApIdx; oSquare._apIdx = this._apIdx; oSquare._originView = this._originView; oSquare.SetOriginPage(this.GetOriginPage()); @@ -116,6 +117,11 @@ oSquare.Recalculate(true); this.FillCommentsDataTo(oSquare); + + if ((this.IsUseInDocument() && this.IsNeedDrawFromStream()) || !this.IsChanged() || this.GetCopyOfApIdx() != -1) { + oSquare.SetCopyOfApIdx(this.GetCopyOfApIdx() != -1 ? this.GetCopyOfApIdx() : this.GetApIdx()); + oSquare.SetDrawFromStream(true); + } return oSquare; }; CAnnotationSquare.prototype.RefillGeometry = function(oGeometry, aShapeRectInMM) { diff --git a/pdf/src/annotations/stamp.js b/pdf/src/annotations/stamp.js index 42d2de44d8..df45b88f3d 100644 --- a/pdf/src/annotations/stamp.js +++ b/pdf/src/annotations/stamp.js @@ -245,10 +245,11 @@ let oViewer = editor.getDocumentRenderer(); let oFile = oViewer.file; let nPage = this.GetOriginPage(); + let nApIdx = this.GetCopyOfApIdx() != -1 ? this.GetCopyOfApIdx() : this.GetApIdx(); if (this.APInfo == null || this.APInfo.size.w != nPageW || this.APInfo.size.h != nPageH) { this.APInfo = { - info: oFile.nativeFile["getAnnotationsAP"](nPage, nPageW, nPageH, undefined, this.GetApIdx()), + info: oFile.nativeFile["getAnnotationsAP"](nPage, nPageW, nPageH, undefined, nApIdx), size: { w: nPageW, h: nPageH @@ -257,7 +258,7 @@ } for (let i = 0; i < this.APInfo.info.length; i++) { - if (this.APInfo.info[i]["i"] == this._apIdx) + if (this.APInfo.info[i]["i"] == nApIdx) return this.APInfo.info[i]; } @@ -379,6 +380,7 @@ let aStrokeColor = this.GetStrokeColor(); let aFillColor = this.GetFillColor(); + oNewStamp._copyApIdx = this._copyApIdx; oNewStamp._apIdx = this._apIdx; oNewStamp._originView = this._originView; oNewStamp.SetOriginPage(this.GetOriginPage()); @@ -419,8 +421,14 @@ oNewStamp.SetWidth(this.GetWidth()); oNewStamp.SetOpacity(this.GetOpacity()); oNewStamp.SetIconType(this.GetIconType()); + oNewStamp.SetRotate(this.GetRotate()); oNewStamp.Recalculate(true); + if ((this.IsUseInDocument() && this.IsNeedDrawFromStream()) || !this.IsChanged() || this.GetCopyOfApIdx() != -1) { + oNewStamp.SetCopyOfApIdx(this.GetCopyOfApIdx() != -1 ? this.GetCopyOfApIdx() : this.GetApIdx()); + oNewStamp.SetDrawFromStream(true, true); + } + return oNewStamp; }; CAnnotationStamp.prototype.IsSelected = function() { @@ -500,15 +508,18 @@ // original rect if (memory.docRenderer) { memory.WriteDouble(aInRect[0] - nBorderW / 2); // x1 + memory.WriteDouble(aInRect[1] + nBorderW / 2); // y2 + memory.WriteDouble(aInRect[0] - nBorderW / 2); // x1 + memory.WriteDouble(aInRect[3] - nBorderW / 2); // y1 + memory.WriteDouble(aInRect[4] + nBorderW / 2); // x2 memory.WriteDouble(aInRect[3] - nBorderW / 2); // y1 memory.WriteDouble(aInRect[4] + nBorderW / 2); // x2 memory.WriteDouble(aInRect[1] + nBorderW / 2); // y2 } else { - memory.WriteDouble(aInRect[0]); // x1 - memory.WriteDouble(aInRect[3]); // y1 - memory.WriteDouble(aInRect[4]); // x2 - memory.WriteDouble(aInRect[1]); // y2 + aInRect.forEach(function(measure) { + memory.WriteDouble(measure); + }); } @@ -524,10 +535,10 @@ (reply.IsChanged() || !memory.docRenderer) && reply.WriteToBinary(memory); }); }; - CAnnotationStamp.prototype.SetDrawFromStream = function() { + CAnnotationStamp.prototype.SetDrawFromStream = function(bDraw, bForce) { let oViewer = editor.getDocumentRenderer(); - if (oViewer.IsOpenAnnotsInProgress) { - this._bDrawFromStream = true; + if (oViewer.IsOpenAnnotsInProgress || bForce) { + this._bDrawFromStream = bDraw; } }; CAnnotationStamp.prototype.WriteRenderToBinary = function(memory) { diff --git a/pdf/src/document.js b/pdf/src/document.js index 653fdddc6c..563aa594a3 100644 --- a/pdf/src/document.js +++ b/pdf/src/document.js @@ -6976,6 +6976,9 @@ var CPresentation = CPresentation || function(){}; uid: annotJson["OUserID"] }, oDoc); + if (annotJson["AP"]["Copy"]) { + oAnnot.SetCopyOfApIdx(annotJson["AP"]["Copy"]); + } oAnnot.SetDrawFromStream(Boolean(annotJson["AP"]["have"])); oAnnot.SetOriginPage(annotJson["page"]);