Skip to content

Commit

Permalink
[pdf] Fixed deletion text annot. Fixes for saving pdf.
Browse files Browse the repository at this point in the history
  • Loading branch information
KhromovNikita committed Oct 11, 2023
1 parent 38d19de commit 0e9e6f3
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 21 deletions.
11 changes: 6 additions & 5 deletions common/Drawings/Metafile.js
Original file line number Diff line number Diff line change
Expand Up @@ -1537,11 +1537,12 @@
this.ctCommandDouble2 = 154;
this.ctCommandString2 = 155;

this.ctHyperlink = 160;
this.ctLink = 161;
this.ctFormField = 162;
this.ctDocInfo = 163;
this.ctAnnotField = 164;
this.ctHyperlink = 160;
this.ctLink = 161;
this.ctFormField = 162;
this.ctDocInfo = 163;
this.ctAnnotField = 164;
this.ctAnnotFieldDelete = 165;

this.ctPageWidth = 200;
this.ctPageHeight = 201;
Expand Down
15 changes: 11 additions & 4 deletions pdf/src/annotations/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,9 @@
this._wasChanged = isChanged;
}
};

CAnnotationBase.prototype.IsChanged = function() {
return this._wasChanged;
};
CAnnotationBase.prototype.DrawFromStream = function(oGraphicsPDF) {
if (this.IsHidden() == true)
return;
Expand Down Expand Up @@ -638,7 +640,7 @@
oReply = this._replies[i];
if (oFirstCommToEdit == oReply)
continue;

oReplyCommentData = oCommentData.m_aReplies.find(function(item) {
return item.m_sUserData == oReply.GetApIdx();
});
Expand Down Expand Up @@ -910,8 +912,10 @@

if (sName != null)
Flags |= (1 << 0);
if (sContents != null)
Flags |= (1 << 1);

// contents
Flags |= (1 << 1);

if (BES != null || BEI != null)
Flags |= (1 << 2);
if (aStrokeColor != null)
Expand All @@ -934,6 +938,9 @@

memory.WriteString(sContents);
}
else {
memory.WriteString("");
}

// border effect
if (BES != null || BEI != null) {
Expand Down
11 changes: 1 addition & 10 deletions pdf/src/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -1746,7 +1746,6 @@ var CPresentation = CPresentation || function(){};
return isHasSelect;
};
CPDFDoc.prototype.RemoveComment = function(Id) {
let oViewer = editor.getDocumentRenderer();
let oAnnot = this.annots.find(function(annot) {
return annot.GetId() === Id;
});
Expand All @@ -1755,12 +1754,7 @@ var CPresentation = CPresentation || function(){};
return;

if (oAnnot.IsComment()) {
let nPage = oAnnot.GetPage();
oAnnot.AddToRedraw();
this.annots.splice(this.annots.indexOf(oAnnot), 1);
oViewer.pagesInfo.pages[nPage].annots.splice(oViewer.pagesInfo.pages[nPage].annots.indexOf(oAnnot), 1);
editor.sync_RemoveComment(Id);
oViewer._paint();
this.RemoveAnnot(oAnnot.GetId());
}
else {
oAnnot.RemoveComment();
Expand All @@ -1775,9 +1769,6 @@ var CPresentation = CPresentation || function(){};
if (!oAnnot)
return;

if (oAnnot.IsComment())
return this.RemoveComment(Id);

let nPage = oAnnot.GetPage();
oAnnot.AddToRedraw();

Expand Down
32 changes: 30 additions & 2 deletions pdf/src/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3869,9 +3869,29 @@
let oMemory = null;
let aPages = this.pagesInfo.pages;

// по информации аннотаций определим какие были удалены
let oDoc = this.getPDFDoc();
let aAnnotsInfo = this.file.nativeFile["getAnnotationsInfo"]();
let aDeleted = [];
aAnnotsInfo.forEach(function(oInfo) {
let isInDoc = oDoc.annots.find(function(annot) {
return annot.GetApIdx() == oInfo["AP"]["i"] || annot._replies.find(function(reply) {
return reply.GetApIdx() == oInfo["AP"]["i"];
});
});

if (!isInDoc) {
if (aDeleted[oInfo["page"]] == null) {
aDeleted[oInfo["page"]] = [];
}

aDeleted[oInfo["page"]].push(oInfo["AP"]["i"]);
}
});

for (let i = 0; i < aPages.length; i++)
{
if (aPages[i].annots == null || aPages[i].annots.length === 0)
if (aPages[i].annots == null || aPages[i].annots.length === 0 && !aDeleted[i])
continue;

if (!oMemory)
Expand All @@ -3886,7 +3906,15 @@
oMemory.WriteLong(i);

for (let nAnnot = 0; nAnnot < aPages[i].annots.length; nAnnot++) {
aPages[i].annots[nAnnot].WriteToBinary && aPages[i].annots[nAnnot].WriteToBinary(oMemory);
aPages[i].annots[nAnnot].WriteToBinary && aPages[i].annots[nAnnot].IsChanged() && aPages[i].annots[nAnnot].WriteToBinary(oMemory);
}

if (aDeleted[i]) {
for (let j = 0; j < aDeleted[i].length; j++) {
oMemory.WriteByte(AscCommon.CommandType.ctAnnotFieldDelete);
oMemory.WriteLong(8);
oMemory.WriteLong(aDeleted[i][j]);
}
}

let nEndPos = oMemory.GetCurPosition();
Expand Down

0 comments on commit 0e9e6f3

Please sign in to comment.