CPDFNoteUI.xaml.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. using ComPDFKit.PDFAnnotation;
  2. using ComPDFKit.Tool;
  3. using ComPDFKit.Controls.Common;
  4. using ComPDFKit.Controls.Data;
  5. using ComPDFKit.Controls.PDFControl;
  6. using System;
  7. using System.Linq;
  8. using System.Windows.Controls;
  9. using System.Windows.Media;
  10. using ComPDFKit.Tool.Help;
  11. using ComPDFKit.Tool.UndoManger;
  12. using ComPDFKitViewer.Helper;
  13. namespace ComPDFKit.Controls.PDFControlUI
  14. {
  15. public partial class CPDFNoteUI : UserControl
  16. {
  17. public event EventHandler<CPDFAnnotationData> PropertyChanged;
  18. internal StickyNoteParam stickyParam { get;private set; }
  19. private CPDFTextAnnotation textAnnot;
  20. private PDFViewControl viewControl;
  21. public CPDFNoteUI()
  22. {
  23. InitializeComponent();
  24. ColorPickerControl.ColorChanged -= ColorPickerControl_ColorChanged;
  25. ColorPickerControl.ColorChanged += ColorPickerControl_ColorChanged;
  26. CPDFAnnotationPreviewerControl.DrawNotePreview(GetNoteData());
  27. }
  28. private void ColorPickerControl_ColorChanged(object sender, EventArgs e)
  29. {
  30. if (stickyParam == null)
  31. {
  32. PropertyChanged?.Invoke(this, GetNoteData());
  33. }
  34. else
  35. {
  36. SolidColorBrush colorBrush= ColorPickerControl.Brush as SolidColorBrush;
  37. if (textAnnot!=null && textAnnot.IsValid() && colorBrush!=null)
  38. {
  39. byte[] color = new byte[3]
  40. {
  41. colorBrush.Color.R,
  42. colorBrush.Color.G,
  43. colorBrush.Color.B
  44. };
  45. if (viewControl != null && !textAnnot.Color.SequenceEqual(color))
  46. {
  47. StickyNoteAnnotHistory history = new StickyNoteAnnotHistory();
  48. history.PDFDoc = viewControl.GetCPDFViewer().GetDocument();
  49. history.Action = HistoryAction.Update;
  50. history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, textAnnot.Page.PageIndex, textAnnot);
  51. textAnnot.SetColor(color);
  52. textAnnot.UpdateAp();
  53. viewControl.UpdateAnnotFrame();
  54. history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, textAnnot.Page.PageIndex, textAnnot);
  55. viewControl.GetCPDFViewer().UndoManager.AddHistory(history);
  56. }
  57. }
  58. }
  59. CPDFAnnotationPreviewerControl.DrawNotePreview(GetNoteData());
  60. }
  61. private void NoteTextBox_TextChanged(object sender, TextChangedEventArgs e)
  62. {
  63. if (stickyParam == null)
  64. {
  65. PropertyChanged?.Invoke(this, GetNoteData());
  66. }
  67. else
  68. {
  69. if (textAnnot != null && textAnnot.IsValid())
  70. {
  71. if (viewControl != null && textAnnot.GetContent() != NoteTextBox.Text)
  72. {
  73. StickyNoteAnnotHistory history = new StickyNoteAnnotHistory();
  74. history.PDFDoc = viewControl.GetCPDFViewer().GetDocument();
  75. history.Action = HistoryAction.Update;
  76. history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, textAnnot.Page.PageIndex, textAnnot);
  77. textAnnot.SetContent(NoteTextBox.Text);
  78. viewControl.UpdateAnnotFrame();
  79. history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, textAnnot.Page.PageIndex, textAnnot);
  80. viewControl.GetCPDFViewer().UndoManager.AddHistory(history);
  81. }
  82. }
  83. }
  84. }
  85. public void SetPresentAnnotAttrib(StickyNoteParam param,CPDFTextAnnotation annot,PDFViewControl view)
  86. {
  87. this.stickyParam = null;
  88. this.viewControl = null;
  89. this.textAnnot = null;
  90. if(param != null)
  91. {
  92. ColorPickerControl.Brush = new SolidColorBrush(Color.FromRgb(
  93. param.StickyNoteColor[0],
  94. param.StickyNoteColor[1],
  95. param.StickyNoteColor[2]));
  96. NoteTextBox.Text = param.Content;
  97. ColorPickerControl.SetCheckedForColor(Color.FromRgb(
  98. param.StickyNoteColor[0],
  99. param.StickyNoteColor[1],
  100. param.StickyNoteColor[2]));
  101. }
  102. this.stickyParam = param;
  103. this.textAnnot=annot;
  104. this.viewControl = view;
  105. }
  106. public CPDFNoteData GetNoteData()
  107. {
  108. CPDFNoteData pdfNoteData = new CPDFNoteData();
  109. pdfNoteData.AnnotationType = CPDFAnnotationType.Note;
  110. pdfNoteData.BorderColor = ((SolidColorBrush)ColorPickerControl.Brush).Color;
  111. pdfNoteData.Note = NoteTextBox.Text;
  112. return pdfNoteData;
  113. }
  114. }
  115. }