StickyNoteAnnotHistory.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. using ComPDFKit.PDFAnnotation;
  2. using ComPDFKit.PDFPage;
  3. using ComPDFKit.Tool.Help;
  4. namespace ComPDFKit.Tool.UndoManger
  5. {
  6. public class StickyNoteAnnotHistory:AnnotHistory
  7. {
  8. public override int GetAnnotIndex()
  9. {
  10. if (CurrentParam != null)
  11. {
  12. return CurrentParam.AnnotIndex;
  13. }
  14. return base.GetAnnotIndex();
  15. }
  16. public override int GetPageIndex()
  17. {
  18. if (CurrentParam != null)
  19. {
  20. return CurrentParam.PageIndex;
  21. }
  22. return base.GetPageIndex();
  23. }
  24. public override void SetAnnotIndex(int newIndex)
  25. {
  26. if (CurrentParam != null)
  27. {
  28. CurrentParam.AnnotIndex = newIndex;
  29. }
  30. if (PreviousParam != null)
  31. {
  32. PreviousParam.AnnotIndex = newIndex;
  33. }
  34. }
  35. internal override bool Add()
  36. {
  37. StickyNoteParam currentParam = CurrentParam as StickyNoteParam;
  38. if (currentParam == null || PDFDoc == null || !PDFDoc.IsValid())
  39. {
  40. return false;
  41. }
  42. CPDFPage pdfPage = PDFDoc.PageAtIndex(currentParam.PageIndex);
  43. CPDFTextAnnotation stickynoteAnnot = pdfPage?.CreateAnnot(C_ANNOTATION_TYPE.C_ANNOTATION_TEXT) as CPDFTextAnnotation;
  44. if(stickynoteAnnot != null)
  45. {
  46. int annotIndex = pdfPage.GetAnnotCount() - 1;
  47. if(currentParam.StickyNoteColor!=null && currentParam.StickyNoteColor.Length==3)
  48. {
  49. stickynoteAnnot.SetColor(currentParam.StickyNoteColor);
  50. }
  51. stickynoteAnnot.SetTransparency((byte)currentParam.Transparency);
  52. stickynoteAnnot.SetRect(currentParam.ClientRect);
  53. if (!string.IsNullOrEmpty(currentParam.Author))
  54. {
  55. stickynoteAnnot.SetAuthor(currentParam.Author);
  56. }
  57. if (!string.IsNullOrEmpty(currentParam.Content))
  58. {
  59. stickynoteAnnot.SetContent(currentParam.Content);
  60. }
  61. if (string.IsNullOrEmpty(currentParam.IconName) == false)
  62. {
  63. stickynoteAnnot.SetIconName(currentParam.IconName);
  64. }
  65. stickynoteAnnot.SetIsLocked(currentParam.Locked);
  66. stickynoteAnnot.SetCreationDate(PDFHelp.GetCurrentPdfTime());
  67. CommonHelper.UpdateStickyAP(stickynoteAnnot);
  68. stickynoteAnnot.ReleaseAnnot();
  69. if (currentParam != null)
  70. {
  71. currentParam.AnnotIndex = annotIndex;
  72. }
  73. if (PreviousParam != null)
  74. {
  75. PreviousParam.AnnotIndex = annotIndex;
  76. }
  77. return true;
  78. }
  79. return false;
  80. }
  81. internal override bool Update(bool isUndo)
  82. {
  83. if (CurrentParam as StickyNoteParam == null || PreviousParam as StickyNoteParam == null)
  84. {
  85. return false;
  86. }
  87. if (MakeAnnotValid(CurrentParam))
  88. {
  89. CPDFTextAnnotation stickynoteAnnot = Annot as CPDFTextAnnotation;
  90. if (stickynoteAnnot == null || !stickynoteAnnot.IsValid())
  91. {
  92. return false;
  93. }
  94. StickyNoteParam updateParam = (isUndo ? PreviousParam : CurrentParam) as StickyNoteParam;
  95. StickyNoteParam checkParam = (isUndo ? CurrentParam : PreviousParam) as StickyNoteParam;
  96. if (!CheckArrayEqual(updateParam.StickyNoteColor, checkParam.StickyNoteColor))
  97. {
  98. if (updateParam.StickyNoteColor != null && updateParam.StickyNoteColor.Length == 3)
  99. {
  100. stickynoteAnnot.SetColor(updateParam.StickyNoteColor);
  101. }
  102. }
  103. if (updateParam.Transparency != checkParam.Transparency)
  104. {
  105. stickynoteAnnot.SetTransparency((byte)updateParam.Transparency);
  106. }
  107. if (!updateParam.ClientRect.Equals(checkParam.ClientRect))
  108. {
  109. stickynoteAnnot.SetRect(updateParam.ClientRect);
  110. }
  111. if (updateParam.Author != checkParam.Author)
  112. {
  113. stickynoteAnnot.SetAuthor(updateParam.Author);
  114. }
  115. if (updateParam.Content != checkParam.Content)
  116. {
  117. stickynoteAnnot.SetContent(updateParam.Content);
  118. }
  119. if(updateParam.IconName!=checkParam.IconName && !string.IsNullOrEmpty(updateParam.IconName))
  120. {
  121. stickynoteAnnot.SetIconName(updateParam.IconName);
  122. }
  123. if (updateParam.Locked != checkParam.Locked)
  124. {
  125. stickynoteAnnot.SetIsLocked(updateParam.Locked);
  126. }
  127. stickynoteAnnot.SetModifyDate(PDFHelp.GetCurrentPdfTime());
  128. CommonHelper.UpdateStickyAP(stickynoteAnnot);
  129. return true;
  130. }
  131. return false;
  132. }
  133. internal override bool Remove()
  134. {
  135. if (MakeAnnotValid(CurrentParam))
  136. {
  137. Annot.RemoveAnnot();
  138. return true;
  139. }
  140. return false;
  141. }
  142. }
  143. }