CPDFNoteUI.xaml.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. ColorPickerControl.ColorChanged += ColorPickerControl_ColorChanged;
  23. CPDFAnnotationPreviewerControl.DrawNotePreview(GetNoteData());
  24. }
  25. private void ColorPickerControl_ColorChanged(object sender, EventArgs e)
  26. {
  27. if (stickyParam == null)
  28. {
  29. PropertyChanged?.Invoke(this, GetNoteData());
  30. }
  31. else
  32. {
  33. SolidColorBrush colorBrush= ColorPickerControl.Brush as SolidColorBrush;
  34. if (textAnnot!=null && textAnnot.IsValid() && colorBrush!=null)
  35. {
  36. textAnnot.SetColor(new byte[3]
  37. {
  38. colorBrush.Color.R,
  39. colorBrush.Color.G,
  40. colorBrush.Color.B
  41. });
  42. if (viewControl != null && viewControl.PDFViewTool != null)
  43. {
  44. viewControl.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. viewControl.UpdateAnnotFrame();
  64. }
  65. }
  66. }
  67. }
  68. public void SetPresentAnnotAttrib(StickyNoteParam param,CPDFTextAnnotation annot,PDFViewControl view)
  69. {
  70. this.stickyParam = null;
  71. this.viewControl = null;
  72. this.textAnnot = null;
  73. if(param != null)
  74. {
  75. ColorPickerControl.Brush = new SolidColorBrush(Color.FromRgb(
  76. param.StickyNoteColor[0],
  77. param.StickyNoteColor[1],
  78. param.StickyNoteColor[2]));
  79. NoteTextBox.Text = param.Content;
  80. ColorPickerControl.SetCheckedForColor(Color.FromRgb(
  81. param.StickyNoteColor[0],
  82. param.StickyNoteColor[1],
  83. param.StickyNoteColor[2]));
  84. }
  85. this.stickyParam = param;
  86. this.textAnnot=annot;
  87. this.viewControl = view;
  88. }
  89. public CPDFNoteData GetNoteData()
  90. {
  91. CPDFNoteData pdfNoteData = new CPDFNoteData();
  92. pdfNoteData.AnnotationType = CPDFAnnotationType.Note;
  93. pdfNoteData.BorderColor = ((SolidColorBrush)ColorPickerControl.Brush).Color;
  94. pdfNoteData.Note = NoteTextBox.Text;
  95. return pdfNoteData;
  96. }
  97. }
  98. }