diff --git a/pdf/api.js b/pdf/api.js index a744a045a6..9069303a3a 100644 --- a/pdf/api.js +++ b/pdf/api.js @@ -1430,6 +1430,18 @@ PDFEditorApi.prototype.IsRedactTool = function() { return !!this.isRedactTool; }; + PDFEditorApi.prototype.SetRedactDelForm = function(bDel) { + this.bRedactDelForms = bDel; + }; + PDFEditorApi.prototype.IsRedactDelForms = function() { + return !!this.bRedactDelForms; + }; + PDFEditorApi.prototype.SetRedactDelAnnots = function(bDel) { + this.bRedactDelAnnots = bDel; + }; + PDFEditorApi.prototype.IsRedactDelAnnots = function() { + return !!this.bRedactDelAnnots; + }; PDFEditorApi.prototype.RedactPages = function(aIdxs) { let oDoc = this.getPDFDoc(); let oFile = oDoc.Viewer.file; @@ -5397,6 +5409,8 @@ // redact PDFEditorApi.prototype['SetRedactTool'] = PDFEditorApi.prototype.SetRedactTool; PDFEditorApi.prototype['IsRedactTool'] = PDFEditorApi.prototype.IsRedactTool; + PDFEditorApi.prototype['SetRedactDelForm'] = PDFEditorApi.prototype.SetRedactDelForm; + PDFEditorApi.prototype['SetRedactDelAnnots']= PDFEditorApi.prototype.SetRedactDelAnnots; PDFEditorApi.prototype['RedactPages'] = PDFEditorApi.prototype.RedactPages; PDFEditorApi.prototype['ApplyRedact'] = PDFEditorApi.prototype.ApplyRedact; PDFEditorApi.prototype['HasRedact'] = PDFEditorApi.prototype.HasRedact; diff --git a/pdf/src/document.js b/pdf/src/document.js index b1d801cb8a..d3c2f3b10a 100644 --- a/pdf/src/document.js +++ b/pdf/src/document.js @@ -7664,6 +7664,7 @@ var CPresentation = CPresentation || function(){}; CPDFDoc.prototype.ApplyRedact = function(sRedactId, nPage) { let oFile = this.Viewer.file; let oNativeFile = oFile.nativeFile; + let _t = this; this.BlurActiveObject(); @@ -7675,6 +7676,33 @@ var CPresentation = CPresentation || function(){}; isOnMerge = true; } + function isIntersectingRects(quads, rect) { + let xCoords = [quads[0], quads[2], quads[4], quads[6]]; + let yCoords = [quads[1], quads[3], quads[5], quads[7]]; + + let r1 = { + left: Math.min.apply(null, xCoords), + right: Math.max.apply(null, xCoords), + top: Math.min.apply(null, yCoords), + bottom: Math.max.apply(null, yCoords) + }; + + let r2 = { + left: rect[0], + top: rect[1], + right: rect[2], + bottom: rect[3] + }; + + let isOutside = + r1.left > r2.right || + r1.right < r2.left || + r1.top > r2.bottom || + r1.bottom < r2.top; + + return !isOutside; + } + function applyForPage(pageIdx) { if (!isOnMerge) { sRedactId = AscCommon.g_oIdCounter.GetNewIdForPdfRedact(); @@ -7746,6 +7774,34 @@ var CPresentation = CPresentation || function(){}; this.SetRedactData(sRedactId, oPageInfo.GetId(), aQuadsFlat, oRender); } + + if (Asc.editor.IsRedactDelForms()) { + oPageInfo.fields.slice().forEach(function(field) { + let aRect = field.GetRect(); + + for (let i = 0, count = aQuadsFlat.length / 8; i < count; i++) { + if (isIntersectingRects(aQuadsFlat.slice(i, i + 8), aRect)) { + _t.RemoveField(field.GetId()); + return; + } + } + }); + } + if (Asc.editor.IsRedactDelAnnots()) { + oPageInfo.annots.slice().forEach(function(annot) { + if (annot.IsRedact()) { + return; + } + + let aRect = annot.GetRect(); + for (let i = 0, count = aQuadsFlat.length / 8; i < count; i++) { + if (isIntersectingRects(aQuadsFlat.slice(i, i + 8), aRect)) { + _t.RemoveAnnot(annot.GetId()); + return; + } + } + }); + } } if (nPage != undefined) {