CPDFNoteUI.xaml.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using compdfkit_tools.Common;
  2. using compdfkit_tools.Data;
  3. using ComPDFKitViewer.AnnotEvent;
  4. using ComPDFKitViewer;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows;
  11. using System.Windows.Controls;
  12. using System.Windows.Data;
  13. using System.Windows.Documents;
  14. using System.Windows.Input;
  15. using System.Windows.Media;
  16. using System.Windows.Media.Imaging;
  17. using System.Windows.Navigation;
  18. using System.Windows.Shapes;
  19. namespace compdfkit_tools.PDFControlUI
  20. {
  21. /// <summary>
  22. /// CPDFNoteUI.xaml 的交互逻辑
  23. /// </summary>
  24. public partial class CPDFNoteUI : UserControl
  25. {
  26. public event EventHandler<CPDFAnnotationData> PropertyChanged;
  27. private AnnotAttribEvent annotAttribEvent;
  28. public CPDFNoteUI()
  29. {
  30. InitializeComponent();
  31. ColorPickerControl.ColorChanged += ColorPickerControl_ColorChanged;
  32. CPDFAnnotationPreviewerControl.DrawNotePreview(GetNoteData());
  33. }
  34. private void ColorPickerControl_ColorChanged(object sender, EventArgs e)
  35. {
  36. if (annotAttribEvent == null)
  37. {
  38. PropertyChanged?.Invoke(this, GetNoteData());
  39. }
  40. else
  41. {
  42. annotAttribEvent.UpdateAttrib(AnnotAttrib.Color, ((SolidColorBrush)ColorPickerControl.Brush).Color);
  43. annotAttribEvent.UpdateAnnot();
  44. }
  45. CPDFAnnotationPreviewerControl.DrawNotePreview(GetNoteData());
  46. }
  47. private void NoteTextBox_TextChanged(object sender, TextChangedEventArgs e)
  48. {
  49. if (annotAttribEvent == null)
  50. {
  51. PropertyChanged?.Invoke(this, GetNoteData());
  52. }
  53. else
  54. {
  55. annotAttribEvent.UpdateAttrib(AnnotAttrib.NoteText, NoteTextBox.Text);
  56. annotAttribEvent.UpdateAnnot();
  57. }
  58. }
  59. public void SetPresentAnnotAttrib(AnnotAttribEvent annotAttribEvent)
  60. {
  61. this.annotAttribEvent = null;
  62. ColorPickerControl.Brush = new SolidColorBrush((Color)annotAttribEvent.Attribs[AnnotAttrib.Color]);
  63. NoteTextBox.Text = (string)annotAttribEvent.Attribs[AnnotAttrib.NoteText];
  64. this.annotAttribEvent = annotAttribEvent;
  65. }
  66. public CPDFNoteData GetNoteData()
  67. {
  68. CPDFNoteData pdfNoteData = new CPDFNoteData();
  69. pdfNoteData.AnnotationType = CPDFAnnotationType.Note;
  70. pdfNoteData.BorderColor = ((SolidColorBrush)ColorPickerControl.Brush).Color;
  71. pdfNoteData.Note = NoteTextBox.Text;
  72. return pdfNoteData;
  73. }
  74. }
  75. }