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