CPDFMarkupUI.xaml.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using Compdfkit_Tools.Common;
  2. using Compdfkit_Tools.Data;
  3. using ComPDFKitViewer;
  4. using ComPDFKitViewer.AnnotEvent;
  5. using System;
  6. using System.Windows.Controls;
  7. using System.Windows.Media;
  8. using Compdfkit_Tools.Helper;
  9. namespace Compdfkit_Tools.PDFControlUI
  10. {
  11. public partial class CPDFMarkupUI : UserControl
  12. {
  13. private CPDFAnnotationType currentAnnotationType;
  14. private AnnotAttribEvent annotAttribEvent;
  15. public event EventHandler<CPDFAnnotationData> PropertyChanged;
  16. public CPDFMarkupUI()
  17. {
  18. InitializeComponent();
  19. ColorPickerControl.ColorChanged += ColorPickerControl_ColorChanged;
  20. CPDFOpacityControl.OpacityChanged += CPDFOpacityControl_OpacityChanged;
  21. }
  22. private void CPDFOpacityControl_OpacityChanged(object sender, EventArgs e)
  23. {
  24. if (annotAttribEvent == null)
  25. {
  26. PropertyChanged?.Invoke(this, GetMarkupData());
  27. }
  28. else
  29. {
  30. annotAttribEvent.UpdateAttrib(AnnotAttrib.Transparency, CPDFOpacityControl.OpacityValue / 100.0);
  31. annotAttribEvent.UpdateAnnot();
  32. }
  33. CPDFAnnotationPreviewerControl.DrawMarkUpPreview(GetMarkupData());
  34. }
  35. private void ColorPickerControl_ColorChanged(object sender, EventArgs e)
  36. {
  37. if (annotAttribEvent == null)
  38. {
  39. PropertyChanged?.Invoke(this, GetMarkupData());
  40. }
  41. else
  42. {
  43. annotAttribEvent.UpdateAttrib(AnnotAttrib.Color, ((SolidColorBrush)ColorPickerControl.Brush).Color);
  44. annotAttribEvent.UpdateAnnot();
  45. }
  46. CPDFAnnotationPreviewerControl.DrawMarkUpPreview(GetMarkupData());
  47. }
  48. private void NoteTextBox_TextChanged(object sender, TextChangedEventArgs e)
  49. {
  50. if (annotAttribEvent == null)
  51. {
  52. PropertyChanged?.Invoke(this, GetMarkupData());
  53. }
  54. else
  55. {
  56. annotAttribEvent.UpdateAttrib(AnnotAttrib.NoteText, NoteTextBox.Text);
  57. annotAttribEvent.UpdateAnnot();
  58. }
  59. }
  60. public CPDFMarkupData GetMarkupData()
  61. {
  62. CPDFMarkupData pdfMarkupData = new CPDFMarkupData();
  63. pdfMarkupData.AnnotationType = currentAnnotationType;
  64. pdfMarkupData.Color = ((SolidColorBrush)ColorPickerControl.Brush).Color;
  65. pdfMarkupData.Opacity = CPDFOpacityControl.OpacityValue / 100.0;
  66. pdfMarkupData.Note = NoteTextBox.Text;
  67. return pdfMarkupData;
  68. }
  69. public void SetPresentAnnotAttrib(AnnotAttribEvent annotAttribEvent)
  70. {
  71. this.annotAttribEvent = null;
  72. ColorPickerControl.Brush = new SolidColorBrush((Color)annotAttribEvent.Attribs[AnnotAttrib.Color]);
  73. ColorPickerControl.SetCheckedForColor((Color)annotAttribEvent.Attribs[AnnotAttrib.Color]);
  74. CPDFOpacityControl.OpacityValue = (int)((double)annotAttribEvent.Attribs[AnnotAttrib.Transparency] * 100);
  75. NoteTextBox.Text = (string)annotAttribEvent.Attribs[AnnotAttrib.NoteText];
  76. this.annotAttribEvent = annotAttribEvent;
  77. CPDFAnnotationPreviewerControl.DrawMarkUpPreview(GetMarkupData());
  78. }
  79. public void InitWithAnnotationType(CPDFAnnotationType annotationType)
  80. {
  81. currentAnnotationType = annotationType;
  82. switch (annotationType)
  83. {
  84. case CPDFAnnotationType.Highlight:
  85. TitleTextBlock.Text = LanguageHelper.PropertyPanelManager.GetString("Title_Highlight");
  86. break;
  87. case CPDFAnnotationType.Underline:
  88. TitleTextBlock.Text = LanguageHelper.PropertyPanelManager.GetString("Title_Underline");
  89. break;
  90. case CPDFAnnotationType.Strikeout:
  91. TitleTextBlock.Text = LanguageHelper.PropertyPanelManager.GetString("Title_Strikeout");
  92. break;
  93. case CPDFAnnotationType.Squiggly:
  94. TitleTextBlock.Text = LanguageHelper.PropertyPanelManager.GetString("Title_Squiggly");
  95. break;
  96. default:
  97. throw new ArgumentException("Not Excepted Argument");
  98. }
  99. CPDFAnnotationPreviewerControl.DrawMarkUpPreview(GetMarkupData());
  100. }
  101. }
  102. }