CPDFNoteUI.xaml.cs 3.7 KB

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