123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- using ComPDFKit.PDFAnnotation;
- using ComPDFKit.PDFPage;
- using ComPDFKit.Tool.Help;
- namespace ComPDFKit.Tool.UndoManger
- {
- public class StickyNoteAnnotHistory:AnnotHistory
- {
- public override int GetAnnotIndex()
- {
- if (CurrentParam != null)
- {
- return CurrentParam.AnnotIndex;
- }
- return base.GetAnnotIndex();
- }
- public override int GetPageIndex()
- {
- if (CurrentParam != null)
- {
- return CurrentParam.PageIndex;
- }
- return base.GetPageIndex();
- }
- public override void SetAnnotIndex(int newIndex)
- {
- if (CurrentParam != null)
- {
- CurrentParam.AnnotIndex = newIndex;
- }
- if (PreviousParam != null)
- {
- PreviousParam.AnnotIndex = newIndex;
- }
- }
- internal override bool Add()
- {
- StickyNoteParam currentParam = CurrentParam as StickyNoteParam;
- if (currentParam == null || PDFDoc == null || !PDFDoc.IsValid())
- {
- return false;
- }
- CPDFPage pdfPage = PDFDoc.PageAtIndex(currentParam.PageIndex);
- CPDFTextAnnotation stickynoteAnnot = pdfPage?.CreateAnnot(C_ANNOTATION_TYPE.C_ANNOTATION_TEXT) as CPDFTextAnnotation;
- if(stickynoteAnnot != null)
- {
- int annotIndex = pdfPage.GetAnnotCount() - 1;
-
- if(currentParam.StickyNoteColor!=null && currentParam.StickyNoteColor.Length==3)
- {
- stickynoteAnnot.SetColor(currentParam.StickyNoteColor);
- }
-
- stickynoteAnnot.SetTransparency((byte)currentParam.Transparency);
- stickynoteAnnot.SetRect(currentParam.ClientRect);
- if (!string.IsNullOrEmpty(currentParam.Author))
- {
- stickynoteAnnot.SetAuthor(currentParam.Author);
- }
- if (!string.IsNullOrEmpty(currentParam.Content))
- {
- stickynoteAnnot.SetContent(currentParam.Content);
- }
- stickynoteAnnot.SetIsLocked(currentParam.Locked);
- stickynoteAnnot.SetCreationDate(PDFHelp.GetCurrentPdfTime());
- stickynoteAnnot.UpdateAp();
- stickynoteAnnot.ReleaseAnnot();
- if (currentParam != null)
- {
- currentParam.AnnotIndex = annotIndex;
- }
- if (PreviousParam != null)
- {
- PreviousParam.AnnotIndex = annotIndex;
- }
- return true;
- }
- return false;
- }
- internal override bool Update(bool isUndo)
- {
- if (CurrentParam as StickyNoteParam == null || PreviousParam as StickyNoteParam == null)
- {
- return false;
- }
- if (MakeAnnotValid(CurrentParam))
- {
- CPDFTextAnnotation stickynoteAnnot = Annot as CPDFTextAnnotation;
- if (stickynoteAnnot == null || !stickynoteAnnot.IsValid())
- {
- return false;
- }
- StickyNoteParam updateParam = (isUndo ? PreviousParam : CurrentParam) as StickyNoteParam;
- StickyNoteParam checkParam = (isUndo ? CurrentParam : PreviousParam) as StickyNoteParam;
- if (!CheckArrayEqual(updateParam.StickyNoteColor, checkParam.StickyNoteColor))
- {
- if (updateParam.StickyNoteColor != null && updateParam.StickyNoteColor.Length == 3)
- {
- stickynoteAnnot.SetColor(updateParam.StickyNoteColor);
- }
- }
- if (updateParam.Transparency != checkParam.Transparency)
- {
- stickynoteAnnot.SetTransparency((byte)updateParam.Transparency);
- }
- if (!updateParam.ClientRect.Equals(checkParam.ClientRect))
- {
- stickynoteAnnot.SetRect(updateParam.ClientRect);
- }
- if (updateParam.Author != checkParam.Author)
- {
- stickynoteAnnot.SetAuthor(updateParam.Author);
- }
- if (updateParam.Content != checkParam.Content)
- {
- stickynoteAnnot.SetContent(updateParam.Content);
- }
- if (updateParam.Locked != checkParam.Locked)
- {
- stickynoteAnnot.SetIsLocked(updateParam.Locked);
- }
- stickynoteAnnot.SetModifyDate(PDFHelp.GetCurrentPdfTime());
- stickynoteAnnot.UpdateAp();
- return true;
- }
- return false;
- }
- internal override bool Remove()
- {
- if (MakeAnnotValid(CurrentParam))
- {
- Annot.RemoveAnnot();
- return true;
- }
- return false;
- }
- }
- }
|