123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- using ComPDFKit.PDFAnnotation.Form;
- using ComPDFKit.PDFPage;
- using ComPDFKit.Tool.Help;
- namespace ComPDFKit.Tool.UndoManger
- {
- public class SignatureHistory:AnnotHistory
- {
- public override int GetAnnotIndex()
- {
- if (CurrentParam != null)
- {
- return CurrentParam.AnnotIndex;
- }
- return base.GetAnnotIndex();
- }
- public override int GetPageIndex()
- {
- if (CurrentParam != null)
- {
- return CurrentParam.PageIndex;
- }
- return base.GetPageIndex();
- }
- public override void SetAnnotIndex(int newIndex)
- {
- if (CurrentParam != null)
- {
- CurrentParam.AnnotIndex = newIndex;
- }
- if (PreviousParam != null)
- {
- PreviousParam.AnnotIndex = newIndex;
- }
- }
- internal override bool Add()
- {
- SignatureParam currentParam = CurrentParam as SignatureParam;
- if (currentParam == null || PDFDoc == null || !PDFDoc.IsValid())
- {
- return false;
- }
- CPDFPage pdfPage = PDFDoc.PageAtIndex(currentParam.PageIndex);
- CPDFSignatureWidget signWidget = pdfPage.CreateWidget(C_WIDGET_TYPE.WIDGET_SIGNATUREFIELDS) as CPDFSignatureWidget;
- if (signWidget != null)
- {
- int annotIndex = pdfPage.GetAnnotCount() - 1;
- if (!string.IsNullOrEmpty(currentParam.FieldName))
- {
- signWidget.SetFieldName(currentParam.FieldName);
- }
- if(currentParam.HasLineColor)
- {
- if (currentParam.LineColor != null && currentParam.LineColor.Length == 3)
- {
- signWidget.SetWidgetBorderRGBColor(currentParam.LineColor);
- }
- }
- if (currentParam.HasBgColor)
- {
- if (currentParam.BgColor != null && currentParam.BgColor.Length == 3)
- {
- signWidget.SetWidgetBgRGBColor(currentParam.BgColor);
- }
- }
- signWidget.SetBorderWidth((float)currentParam.LineWidth);
- signWidget.SetWidgetBorderStyle(currentParam.BorderStyle);
- signWidget.SetRect(currentParam.ClientRect);
- signWidget.SetFlags(currentParam.Flags);
- signWidget.SetIsLocked(currentParam.Locked);
- signWidget.SetIsReadOnly(currentParam.IsReadOnly);
- signWidget.SetIsHidden(currentParam.IsHidden);
- signWidget.SetCreationDate(PDFHelp.GetCurrentPdfTime());
- signWidget.UpdateFormAp();
- signWidget.ReleaseAnnot();
- if (currentParam != null)
- {
- currentParam.AnnotIndex = annotIndex;
- }
- if (PreviousParam != null)
- {
- PreviousParam.AnnotIndex = annotIndex;
- }
- return true;
- }
- return false;
- }
- internal override bool Update(bool isUndo)
- {
- if (CurrentParam as SignatureParam == null || PreviousParam as SignatureParam == null)
- {
- return false;
- }
- if (MakeAnnotValid(CurrentParam))
- {
- CPDFSignatureWidget signWidget = Annot as CPDFSignatureWidget;
- if (signWidget == null || !signWidget.IsValid())
- {
- return false;
- }
- SignatureParam updateParam =( isUndo ? PreviousParam : CurrentParam) as SignatureParam;
- SignatureParam checkParam = (isUndo ? CurrentParam : PreviousParam) as SignatureParam;
- if (updateParam.FieldName != checkParam.FieldName)
- {
- signWidget.SetFieldName(updateParam.FieldName);
- }
- if (!CheckArrayEqual(updateParam.LineColor, checkParam.LineColor))
- {
- if (updateParam.HasLineColor)
- {
- if (updateParam.LineColor != null && updateParam.LineColor.Length == 3)
- {
- signWidget.SetWidgetBorderRGBColor(updateParam.LineColor);
- }
- }
- else
- {
- signWidget.ClearWidgetBorderRGBColor();
- }
- }
- if (!CheckArrayEqual(updateParam.BgColor, checkParam.BgColor))
- {
- if (updateParam.HasBgColor)
- {
- if (updateParam.BgColor != null && updateParam.BgColor.Length == 3)
- {
- signWidget.SetWidgetBgRGBColor(updateParam.BgColor);
- }
- }
- else
- {
- signWidget.ClearWidgetBgRGBColor();
- }
- }
- if (updateParam.LineWidth != checkParam.LineWidth)
- {
- signWidget.SetBorderWidth((float)updateParam.LineWidth);
- }
- if(updateParam.BorderStyle != checkParam.BorderStyle)
- {
- signWidget.SetWidgetBorderStyle(updateParam.BorderStyle);
- }
- if(!updateParam.ClientRect.Equals(checkParam.ClientRect))
- {
- signWidget.SetRect(updateParam.ClientRect);
- }
- if (updateParam.Flags != checkParam.Flags)
- {
- signWidget.SetFlags(updateParam.Flags);
- }
- if (updateParam.Locked != checkParam.Locked)
- {
- signWidget.SetIsLocked(updateParam.Locked);
- }
- if (updateParam.IsReadOnly != checkParam.IsReadOnly)
- {
- signWidget.SetIsReadOnly(updateParam.IsReadOnly);
- }
- if (updateParam.IsHidden != checkParam.IsHidden)
- {
- signWidget.SetIsHidden(updateParam.IsHidden);
- }
- signWidget.SetModifyDate(PDFHelp.GetCurrentPdfTime());
- signWidget.UpdateFormAp();
- return true;
- }
- return false;
- }
- internal override bool Remove()
- {
- if (MakeAnnotValid(CurrentParam))
- {
- Annot.RemoveAnnot();
- return true;
- }
- return false;
- }
- }
- }
|