SignatureHistory.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. using ComPDFKit.PDFAnnotation.Form;
  2. using ComPDFKit.PDFPage;
  3. using ComPDFKit.Tool.Help;
  4. namespace ComPDFKit.Tool.UndoManger
  5. {
  6. public class SignatureHistory: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. SignatureParam currentParam = CurrentParam as SignatureParam;
  38. if (currentParam == null || PDFDoc == null || !PDFDoc.IsValid())
  39. {
  40. return false;
  41. }
  42. CPDFPage pdfPage = PDFDoc.PageAtIndex(currentParam.PageIndex);
  43. CPDFSignatureWidget signWidget = pdfPage.CreateWidget(C_WIDGET_TYPE.WIDGET_SIGNATUREFIELDS) as CPDFSignatureWidget;
  44. if (signWidget != null)
  45. {
  46. int annotIndex = pdfPage.GetAnnotCount() - 1;
  47. if (!string.IsNullOrEmpty(currentParam.FieldName))
  48. {
  49. signWidget.SetFieldName(currentParam.FieldName);
  50. }
  51. if(currentParam.HasLineColor)
  52. {
  53. if (currentParam.LineColor != null && currentParam.LineColor.Length == 3)
  54. {
  55. signWidget.SetWidgetBorderRGBColor(currentParam.LineColor);
  56. }
  57. }
  58. if (currentParam.HasBgColor)
  59. {
  60. if (currentParam.BgColor != null && currentParam.BgColor.Length == 3)
  61. {
  62. signWidget.SetWidgetBgRGBColor(currentParam.BgColor);
  63. }
  64. }
  65. signWidget.SetBorderWidth((float)currentParam.LineWidth);
  66. signWidget.SetWidgetBorderStyle(currentParam.BorderStyle);
  67. signWidget.SetRect(currentParam.ClientRect);
  68. signWidget.SetFlags(currentParam.Flags);
  69. signWidget.SetIsLocked(currentParam.Locked);
  70. signWidget.SetIsReadOnly(currentParam.IsReadOnly);
  71. signWidget.SetIsHidden(currentParam.IsHidden);
  72. signWidget.SetCreationDate(PDFHelp.GetCurrentPdfTime());
  73. signWidget.UpdateFormAp();
  74. signWidget.ReleaseAnnot();
  75. if (currentParam != null)
  76. {
  77. currentParam.AnnotIndex = annotIndex;
  78. }
  79. if (PreviousParam != null)
  80. {
  81. PreviousParam.AnnotIndex = annotIndex;
  82. }
  83. return true;
  84. }
  85. return false;
  86. }
  87. internal override bool Update(bool isUndo)
  88. {
  89. if (CurrentParam as SignatureParam == null || PreviousParam as SignatureParam == null)
  90. {
  91. return false;
  92. }
  93. if (MakeAnnotValid(CurrentParam))
  94. {
  95. CPDFSignatureWidget signWidget = Annot as CPDFSignatureWidget;
  96. if (signWidget == null || !signWidget.IsValid())
  97. {
  98. return false;
  99. }
  100. SignatureParam updateParam =( isUndo ? PreviousParam : CurrentParam) as SignatureParam;
  101. SignatureParam checkParam = (isUndo ? CurrentParam : PreviousParam) as SignatureParam;
  102. if (updateParam.FieldName != checkParam.FieldName)
  103. {
  104. signWidget.SetFieldName(updateParam.FieldName);
  105. }
  106. if (!CheckArrayEqual(updateParam.LineColor, checkParam.LineColor))
  107. {
  108. if (updateParam.HasLineColor)
  109. {
  110. if (updateParam.LineColor != null && updateParam.LineColor.Length == 3)
  111. {
  112. signWidget.SetWidgetBorderRGBColor(updateParam.LineColor);
  113. }
  114. }
  115. else
  116. {
  117. signWidget.ClearWidgetBorderRGBColor();
  118. }
  119. }
  120. if (!CheckArrayEqual(updateParam.BgColor, checkParam.BgColor))
  121. {
  122. if (updateParam.HasBgColor)
  123. {
  124. if (updateParam.BgColor != null && updateParam.BgColor.Length == 3)
  125. {
  126. signWidget.SetWidgetBgRGBColor(updateParam.BgColor);
  127. }
  128. }
  129. else
  130. {
  131. signWidget.ClearWidgetBgRGBColor();
  132. }
  133. }
  134. if (updateParam.LineWidth != checkParam.LineWidth)
  135. {
  136. signWidget.SetBorderWidth((float)updateParam.LineWidth);
  137. }
  138. if(updateParam.BorderStyle != checkParam.BorderStyle)
  139. {
  140. signWidget.SetWidgetBorderStyle(updateParam.BorderStyle);
  141. }
  142. if(!updateParam.ClientRect.Equals(checkParam.ClientRect))
  143. {
  144. signWidget.SetRect(updateParam.ClientRect);
  145. }
  146. if (updateParam.Flags != checkParam.Flags)
  147. {
  148. signWidget.SetFlags(updateParam.Flags);
  149. }
  150. if (updateParam.Locked != checkParam.Locked)
  151. {
  152. signWidget.SetIsLocked(updateParam.Locked);
  153. }
  154. if (updateParam.IsReadOnly != checkParam.IsReadOnly)
  155. {
  156. signWidget.SetIsReadOnly(updateParam.IsReadOnly);
  157. }
  158. if (updateParam.IsHidden != checkParam.IsHidden)
  159. {
  160. signWidget.SetIsHidden(updateParam.IsHidden);
  161. }
  162. signWidget.SetModifyDate(PDFHelp.GetCurrentPdfTime());
  163. signWidget.UpdateFormAp();
  164. return true;
  165. }
  166. return false;
  167. }
  168. internal override bool Remove()
  169. {
  170. if (MakeAnnotValid(CurrentParam))
  171. {
  172. Annot.RemoveAnnot();
  173. return true;
  174. }
  175. return false;
  176. }
  177. }
  178. }