From f2c5d20b55a07542a6d9a6a94a95989f777bb2d1 Mon Sep 17 00:00:00 2001 From: fernfei Date: Tue, 14 May 2024 21:19:19 +0800 Subject: [PATCH] fix: Fix watermark can't cover entire document and affect header page text see https://forum.onlyoffice.com/t/regarding-the-issue-of-your-text-here-appearing-when-adding-and-then-removing-a-watermark/8981 https://forum.onlyoffice.com/t/when-the-document-has-multiple-pages-the-watermark-cannot-be-displayed-on-each-page-of-the-document/6703/4?u=hufei --- word/Editor/Document.js | 30 +++++++++++++++++++++++++++++- word/Editor/HeaderFooter.js | 24 ++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/word/Editor/Document.js b/word/Editor/Document.js index a4a0c3bab2..04aa10cbe1 100644 --- a/word/Editor/Document.js +++ b/word/Editor/Document.js @@ -12401,7 +12401,35 @@ CDocument.prototype.SetWatermarkProps = function(oProps) return; this.StartAction(AscDFH.historydescription_Document_AddWatermark); - this.SetWatermarkPropsAction(oProps); + for (let pageIndex = 0; pageIndex < this.Pages.length; pageIndex++) { + // Определим четность страницы и является ли она первой в данной секции. Заметим, что четность страницы + // отсчитывается от начала текущей секции и не зависит от настроек нумерации страниц для данной секции. + var SectionPageInfo = this.Get_SectionPageNumInfo( pageIndex ); + + var bFirst = SectionPageInfo.bFirst; + var bEven = SectionPageInfo.bEven; + + // Запросим нужный нам колонтитул + var HdrFtr = this.Get_SectionHdrFtr( pageIndex, bFirst, bEven ); + + var Header = HdrFtr.Header; + var Footer = HdrFtr.Footer; + var SectPr = HdrFtr.SectPr; + + if (!Header && SectPr.IsTitlePage()) { + Header = new CHeaderFooter(this.GetHdrFtr(), this, this.Get_DrawingDocument(), hdrftr_Header); + SectPr.Set_Header_First(Header); + }else if (!Header && SectPr.IsEvenAndOdd()) { + Header = new CHeaderFooter(this.GetHdrFtr(), this, this.Get_DrawingDocument(), hdrftr_Header); + SectPr.Set_Header_First(Header); + } else if(!Header){ + Header = new CHeaderFooter(this.GetHdrFtr(), this, this.Get_DrawingDocument(), hdrftr_Header); + SectPr.Set_Header_Default(Header); + } + if(Header){ + Header.SetWatermarkPropsAction(oProps); + } + } this.Recalculate(); this.Document_UpdateInterfaceState(); this.Document_UpdateSelectionState(); diff --git a/word/Editor/HeaderFooter.js b/word/Editor/HeaderFooter.js index 17e0ca6857..b105334bf3 100644 --- a/word/Editor/HeaderFooter.js +++ b/word/Editor/HeaderFooter.js @@ -1321,6 +1321,30 @@ CHeaderFooter.prototype = return this.Content.CanAddComment(); } }; +CHeaderFooter.prototype.SetWatermarkPropsAction = function (oProps) { + const oLogicDocument = this.LogicDocument; + let oWatermark = this.FindWatermark(); + if(oWatermark) + { + if(oWatermark.GraphicObj.selected) + { + this.RemoveSelection(true); + } + oWatermark.Remove_FromDocument(false); + } + oWatermark = oLogicDocument.DrawingObjects.createWatermark(oProps); + if(oWatermark) + { + const oDocState = oLogicDocument.Get_SelectionState2(); + const oContent = this.Content; + var paraRun = new ParaRun(null, false); + paraRun.Add(oWatermark); + var oFirstParagraph = oContent.GetFirstParagraph(); + oFirstParagraph.AddToContentToEnd(paraRun); + oLogicDocument.Set_SelectionState2(oDocState); + return oWatermark; + } +}; CHeaderFooter.prototype.UpdateContentToDefaults = function() { this.Content.ClearContent(true);