SquigglyAnnotHistory.cs 4.2 KB

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