|
@@ -1,4 +1,6 @@
|
|
|
-using ComPDFKitViewer;
|
|
|
+using ComPDFKit.Import;
|
|
|
+using ComPDFKit.PDFPage;
|
|
|
+using ComPDFKitViewer;
|
|
|
using ComPDFKitViewer.PdfViewer;
|
|
|
using Microsoft.Office.Core;
|
|
|
using System;
|
|
@@ -6,6 +8,7 @@ using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
+using System.Windows;
|
|
|
|
|
|
namespace PDF_Master.Helper
|
|
|
{
|
|
@@ -15,6 +18,60 @@ namespace PDF_Master.Helper
|
|
|
CropAllPagesWM
|
|
|
}
|
|
|
|
|
|
+ public class AreaCropPageUndoManager : IHistory
|
|
|
+ {
|
|
|
+ private CPDFViewer pdfviewer = null;
|
|
|
+
|
|
|
+ private List<Tuple<List<int>, Rect,Size>> history = new List<Tuple<List<int>, Rect, Size>>();
|
|
|
+
|
|
|
+ private int historyIndex = -1;
|
|
|
+
|
|
|
+ public AreaCropPageUndoManager(CPDFViewer pDFViewer) {
|
|
|
+ pdfviewer = pDFViewer;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public void ADDAreaCropPage(List<int> pageindex, Rect rect,Size pagesize)
|
|
|
+ {
|
|
|
+ historyIndex++;
|
|
|
+ history.Add(new Tuple<List<int>, Rect, Size>(pageindex, rect, pagesize));
|
|
|
+ }
|
|
|
+
|
|
|
+ public bool Redo()
|
|
|
+ {
|
|
|
+ historyIndex++;
|
|
|
+ if (historyIndex < history.Count)
|
|
|
+ {
|
|
|
+ pdfviewer?.CropPage(CPDFDisplayBox.CropBox, history[historyIndex].Item2, history[historyIndex].Item1);
|
|
|
+ pdfviewer.UndoManager.CanSave = true;
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public bool Undo()
|
|
|
+ {
|
|
|
+ if (historyIndex > -1)
|
|
|
+ {
|
|
|
+ Rect newRect =new Rect( -history[historyIndex].Item2.Left, -history[historyIndex].Item2.Top, history[historyIndex].Item3.Width+ history[historyIndex].Item2.Left, history[historyIndex].Item3.Height + history[historyIndex].Item2.Top);
|
|
|
+ pdfviewer?.CropPage(CPDFDisplayBox.CropBox, newRect, history[historyIndex].Item1);
|
|
|
+ historyIndex--;
|
|
|
+ pdfviewer.UndoManager.CanSave = true;
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public class CropPageUndoManager : IHistory
|
|
|
{
|
|
|
public List<int> cropPageList = new List<int>();
|
|
@@ -43,8 +100,8 @@ namespace PDF_Master.Helper
|
|
|
cropPageEnumList.Insert(cropPageEnumIndex, CropPageEnum.CropCurrentPageWM);
|
|
|
if (cropPageEnumIndex != cropPageEnumList.Count - 1)
|
|
|
{
|
|
|
- cropPageEnumList.RemoveRange(cropPageEnumIndex + 1, cropPageEnumList.Count - cropPageEnumIndex-1);
|
|
|
- cropPageList.RemoveRange(cropPageList.Count - cropPageListInterval-1, cropPageListInterval);
|
|
|
+ cropPageEnumList.RemoveRange(cropPageEnumIndex + 1, cropPageEnumList.Count - cropPageEnumIndex - 1);
|
|
|
+ cropPageList.RemoveRange(cropPageList.Count - cropPageListInterval - 1, cropPageListInterval);
|
|
|
cropPageListInterval = 0;
|
|
|
}
|
|
|
|
|
@@ -57,11 +114,11 @@ namespace PDF_Master.Helper
|
|
|
cropPageEnumList.Insert(cropPageEnumIndex, CropPageEnum.CropAllPagesWM);
|
|
|
if (cropPageEnumIndex != cropPageEnumList.Count - 1)
|
|
|
{
|
|
|
- cropPageEnumList.RemoveRange(cropPageEnumIndex+1, cropPageEnumList.Count - cropPageEnumIndex-1);
|
|
|
- cropPageList.RemoveRange(cropPageList.Count - cropPageListInterval- pdfviewer.Document.PageCount, cropPageListInterval);
|
|
|
+ cropPageEnumList.RemoveRange(cropPageEnumIndex + 1, cropPageEnumList.Count - cropPageEnumIndex - 1);
|
|
|
+ cropPageList.RemoveRange(cropPageList.Count - cropPageListInterval - pdfviewer.Document.PageCount, cropPageListInterval);
|
|
|
cropPageListInterval = 0;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
|
|
|
public void setPageList(List<int> CropPageList)
|
|
@@ -72,12 +129,13 @@ namespace PDF_Master.Helper
|
|
|
public bool Redo()
|
|
|
{
|
|
|
cropPageEnumIndex++;
|
|
|
- if (cropPageEnumIndex < cropPageEnumList.Count )
|
|
|
+ if (cropPageEnumIndex < cropPageEnumList.Count)
|
|
|
{
|
|
|
-
|
|
|
+
|
|
|
if (cropPageEnumList[cropPageEnumIndex] == CropPageEnum.CropAllPagesWM) { cropPageListInterval -= pdfviewer.Document.PageCount; } else { cropPageListInterval--; }
|
|
|
-
|
|
|
+
|
|
|
if (cropPageList.Count - cropPageListInterval == 0) { pdfviewer.SetCropMode(false); } else { pdfviewer.SetCropMode(true, cropPageList.GetRange(0, cropPageList.Count - cropPageListInterval)); }
|
|
|
+ pdfviewer.UndoManager.CanSave = true;
|
|
|
return true;
|
|
|
}
|
|
|
else
|
|
@@ -101,6 +159,7 @@ namespace PDF_Master.Helper
|
|
|
if (cropPageList.Count - cropPageListInterval == 0) { pdfviewer.SetCropMode(false); } else { pdfviewer.SetCropMode(true, cropPageList.GetRange(0, cropPageList.Count - cropPageListInterval)); }
|
|
|
|
|
|
cropPageEnumIndex--;
|
|
|
+ pdfviewer.UndoManager.CanSave = true;
|
|
|
return true;
|
|
|
}
|
|
|
else
|