StrikeoutAnnotHistory.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. using ComPDFKit.PDFAnnotation;
  2. using ComPDFKit.PDFPage;
  3. using ComPDFKit.Tool.Help;
  4. namespace ComPDFKit.Tool.UndoManger
  5. {
  6. public class StrikeoutAnnotHistory: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. StrikeoutParam currentParam = CurrentParam as StrikeoutParam;
  38. if (currentParam == null || PDFDoc == null || !PDFDoc.IsValid())
  39. {
  40. return false;
  41. }
  42. CPDFPage pdfPage = PDFDoc.PageAtIndex(currentParam.PageIndex);
  43. CPDFStrikeoutAnnotation strikeoutAnnot = pdfPage?.CreateAnnot(C_ANNOTATION_TYPE.C_ANNOTATION_STRIKEOUT) as CPDFStrikeoutAnnotation;
  44. if (strikeoutAnnot != null)
  45. {
  46. int annotIndex = pdfPage.GetAnnotCount() - 1;
  47. strikeoutAnnot.SetTransparency((byte)currentParam.Transparency);
  48. strikeoutAnnot.SetRect(currentParam.ClientRect);
  49. if (currentParam.QuardRects != null)
  50. {
  51. strikeoutAnnot.SetQuardRects(currentParam.QuardRects);
  52. }
  53. if (currentParam.StrikeoutColor != null && currentParam.StrikeoutColor.Length == 3)
  54. {
  55. strikeoutAnnot.SetColor(currentParam.StrikeoutColor);
  56. }
  57. if (!string.IsNullOrEmpty(currentParam.Author))
  58. {
  59. strikeoutAnnot.SetAuthor(currentParam.Author);
  60. }
  61. if (!string.IsNullOrEmpty(currentParam.Content))
  62. {
  63. strikeoutAnnot.SetContent(currentParam.Content);
  64. }
  65. strikeoutAnnot.SetIsLocked(currentParam.Locked);
  66. strikeoutAnnot.SetCreationDate(PDFHelp.GetCurrentPdfTime());
  67. strikeoutAnnot.UpdateAp();
  68. strikeoutAnnot.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 StrikeoutParam == null || PreviousParam as StrikeoutParam == null)
  84. {
  85. return false;
  86. }
  87. if (MakeAnnotValid(CurrentParam))
  88. {
  89. CPDFStrikeoutAnnotation strikeoutAnnot = Annot as CPDFStrikeoutAnnotation;
  90. if (strikeoutAnnot == null || !strikeoutAnnot.IsValid())
  91. {
  92. return false;
  93. }
  94. StrikeoutParam updateParam = (isUndo ? PreviousParam : CurrentParam) as StrikeoutParam;
  95. StrikeoutParam checkParam = (isUndo ? CurrentParam : PreviousParam) as StrikeoutParam;
  96. if (!CheckArrayEqual(updateParam.StrikeoutColor, checkParam.StrikeoutColor))
  97. {
  98. if (updateParam.StrikeoutColor != null && updateParam.StrikeoutColor.Length == 3)
  99. {
  100. strikeoutAnnot.SetColor(updateParam.StrikeoutColor);
  101. }
  102. }
  103. if (updateParam.Transparency != checkParam.Transparency)
  104. {
  105. strikeoutAnnot.SetTransparency((byte)updateParam.Transparency);
  106. }
  107. if (updateParam.Author != checkParam.Author)
  108. {
  109. strikeoutAnnot.SetAuthor(updateParam.Author);
  110. }
  111. if (updateParam.Content != checkParam.Content)
  112. {
  113. strikeoutAnnot.SetContent(updateParam.Content);
  114. }
  115. if (updateParam.Locked != checkParam.Locked)
  116. {
  117. strikeoutAnnot.SetIsLocked(updateParam.Locked);
  118. }
  119. strikeoutAnnot.SetModifyDate(PDFHelp.GetCurrentPdfTime());
  120. strikeoutAnnot.UpdateAp();
  121. return true;
  122. }
  123. return false;
  124. }
  125. internal override bool Remove()
  126. {
  127. if (MakeAnnotValid(CurrentParam))
  128. {
  129. Annot.RemoveAnnot();
  130. return true;
  131. }
  132. return false;
  133. }
  134. }
  135. }