123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- 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;
- namespace PDF_Office.Helper
- {
- public enum CropPageEnum
- {
- CropCurrentPageWM,
- CropAllPagesWM
- }
- 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-37, 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)); }
- 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--;
- return true;
- }
- else
- {
- return false;
- }
- }
- }
- }
|