123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- using ComPDFKit.Import;
- using ComPDFKit.PDFPage;
- using ComPDFKitViewer;
- using ComPDFKitViewer.PdfViewer;
- using Microsoft.Office.Core;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- namespace PDF_Master.Helper
- {
- public enum CropPageEnum
- {
- CropCurrentPageWM,
- 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>();
- private List<CropPageEnum> cropPageEnumList = new List<CropPageEnum>();
- private int cropPageEnumIndex = -1;
- private int cropPageListInterval = 0;
- private CPDFViewer pdfviewer = null;
- public CropPageUndoManager()
- {
- }
- public void setPDFViewer(CPDFViewer pDFViewer)
- {
- pdfviewer = pDFViewer;
- }
- public void ADDCropCurrentPageWM()
- {
- cropPageEnumIndex++;
- 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);
- cropPageListInterval = 0;
- }
- }
- public void ADDCropAllPagesWM()
- {
- cropPageEnumIndex++;
- 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);
- cropPageListInterval = 0;
- }
- }
- public void setPageList(List<int> CropPageList)
- {
- cropPageList = CropPageList;
- }
- public bool Redo()
- {
- cropPageEnumIndex++;
- 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
- {
- return false;
- }
- }
- public bool Undo()
- {
- if (cropPageEnumIndex > -1)
- {
- 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)); }
- cropPageEnumIndex--;
- pdfviewer.UndoManager.CanSave = true;
- return true;
- }
- else
- {
- return false;
- }
- }
- }
- }
|