From 29bfb6c4ddb8ec6136fd6aaf0cf06d5ab319708c Mon Sep 17 00:00:00 2001 From: Nikita Khromov Date: Fri, 27 Sep 2024 13:16:25 +0700 Subject: [PATCH] [pdf] Fix write change --- pdf/src/forms/base/base.js | 3 -- pdf/src/history/annotsChanges.js | 52 +++++++++++++++++++++--------- pdf/src/history/documentChanges.js | 2 +- 3 files changed, 37 insertions(+), 20 deletions(-) diff --git a/pdf/src/forms/base/base.js b/pdf/src/forms/base/base.js index 4983218698..7232adf5fe 100644 --- a/pdf/src/forms/base/base.js +++ b/pdf/src/forms/base/base.js @@ -1959,9 +1959,6 @@ // common triggers CBaseField.prototype.onMouseEnter = function() { this.AddActionsToQueue(AscPDF.FORMS_TRIGGERS_TYPES.MouseEnter); - - let oDoc = this.GetDocument(); - }; CBaseField.prototype.onMouseExit = function() { this.AddActionsToQueue(AscPDF.FORMS_TRIGGERS_TYPES.MouseExit); diff --git a/pdf/src/history/annotsChanges.js b/pdf/src/history/annotsChanges.js index cfb5cc443c..ecda8a739b 100644 --- a/pdf/src/history/annotsChanges.js +++ b/pdf/src/history/annotsChanges.js @@ -105,15 +105,29 @@ CChangesAnnotArrayOfDoubleProperty.prototype.constructor = CChangesAnnotArrayOfD CChangesAnnotArrayOfDoubleProperty.prototype.WriteToBinary = function(Writer) { - var nNewCount = this.New.length; - Writer.WriteLong(nNewCount); - for (var nIndex = 0; nIndex < nNewCount; ++nIndex) - Writer.WriteDouble(this.New[nIndex]); + let nFlags = 0; - var nOldCount = this.Old.length; - Writer.WriteLong(nOldCount); - for (var nIndex = 0; nIndex < nOldCount; ++nIndex) - Writer.WriteDouble(this.Old[nIndex]); + if (undefined === this.New) + nFlags |= 1; + + if (undefined === this.Old) + nFlags |= 2; + + Writer.WriteLong(nFlags); + + if (undefined !== this.New) { + var nNewCount = this.New.length; + Writer.WriteLong(nNewCount); + for (var nIndex = 0; nIndex < nNewCount; ++nIndex) + Writer.WriteDouble(this.New[nIndex]); + } + + if (undefined !== this.Old) { + var nOldCount = this.Old.length; + Writer.WriteLong(nOldCount); + for (var nIndex = 0; nIndex < nOldCount; ++nIndex) + Writer.WriteDouble(this.Old[nIndex]); + } }; CChangesAnnotArrayOfDoubleProperty.prototype.ReadFromBinary = function(Reader) { @@ -122,15 +136,21 @@ CChangesAnnotArrayOfDoubleProperty.prototype.ReadFromBinary = function(Reader) // Long : Count of the columns in the old grid // Array of double : widths of columns in the old grid - var nCount = Reader.GetLong(); - this.New = []; - for (var nIndex = 0; nIndex < nCount; ++nIndex) - this.New[nIndex] = Reader.GetDouble(); + let nFlags = Reader.GetLong(); + + if (!(nFlags & 1)) { + let nCount = Reader.GetLong(); + this.New = []; + for (var nIndex = 0; nIndex < nCount; ++nIndex) + this.New[nIndex] = Reader.GetDouble(); + } - nCount = Reader.GetLong(); - this.Old = []; - for (var nIndex = 0; nIndex < nCount; ++nIndex) - this.Old[nIndex] = Reader.GetDouble(); + if (!(nFlags & 2)) { + let nCount = Reader.GetLong(); + this.Old = []; + for (var nIndex = 0; nIndex < nCount; ++nIndex) + this.Old[nIndex] = Reader.GetDouble(); + } }; CChangesAnnotArrayOfDoubleProperty.prototype.Load = function(){ diff --git a/pdf/src/history/documentChanges.js b/pdf/src/history/documentChanges.js index d14730f829..59c43c3d4a 100644 --- a/pdf/src/history/documentChanges.js +++ b/pdf/src/history/documentChanges.js @@ -742,7 +742,7 @@ CChangesPDFDocumentRotatePage.prototype.ReadFromBinary = function(Reader) // long : Old - var nFlags = Reader.GetLong(); + let nFlags = Reader.GetLong(); if (nFlags & 1) this.Page = undefined;