CPDFMarkupUI.xaml.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. using Compdfkit_Tools.Helper;
  11. namespace Compdfkit_Tools.PDFControlUI
  12. {
  13. public partial class CPDFMarkupUI : UserControl
  14. {
  15. private CPDFAnnotationType currentAnnotationType;
  16. private AnnotParam annotParam;
  17. private CPDFMarkupAnnotation markupAnnot;
  18. private PDFViewControl viewControl;
  19. public event EventHandler<CPDFAnnotationData> PropertyChanged;
  20. public CPDFMarkupUI()
  21. {
  22. InitializeComponent();
  23. ColorPickerControl.ColorChanged -= ColorPickerControl_ColorChanged;
  24. CPDFOpacityControl.OpacityChanged -= CPDFOpacityControl_OpacityChanged;
  25. ColorPickerControl.ColorChanged += ColorPickerControl_ColorChanged;
  26. CPDFOpacityControl.OpacityChanged += CPDFOpacityControl_OpacityChanged;
  27. }
  28. private void CPDFOpacityControl_OpacityChanged(object sender, EventArgs e)
  29. {
  30. if (annotParam == null)
  31. {
  32. PropertyChanged?.Invoke(this, GetMarkupData());
  33. }
  34. else
  35. {
  36. if(markupAnnot!=null && markupAnnot.IsValid())
  37. {
  38. markupAnnot.SetTransparency((byte)(CPDFOpacityControl.OpacityValue / 100.0 * 255));
  39. if (viewControl != null && viewControl.PDFViewTool != null)
  40. {
  41. viewControl.UpdateAnnotFrame();
  42. }
  43. }
  44. }
  45. CPDFAnnotationPreviewerControl.DrawMarkUpPreview(GetMarkupData());
  46. }
  47. private void ColorPickerControl_ColorChanged(object sender, EventArgs e)
  48. {
  49. if (annotParam == null)
  50. {
  51. PropertyChanged?.Invoke(this, GetMarkupData());
  52. }
  53. else
  54. {
  55. SolidColorBrush colorBrush = ColorPickerControl.Brush as SolidColorBrush;
  56. if (markupAnnot != null && markupAnnot.IsValid() && colorBrush!=null)
  57. {
  58. markupAnnot.SetColor(new byte[3]
  59. {
  60. colorBrush.Color.R,
  61. colorBrush.Color.G,
  62. colorBrush.Color.B
  63. });
  64. if (viewControl != null && viewControl.PDFViewTool != null)
  65. {
  66. viewControl.UpdateAnnotFrame();
  67. }
  68. }
  69. }
  70. CPDFAnnotationPreviewerControl.DrawMarkUpPreview(GetMarkupData());
  71. }
  72. private void NoteTextBox_TextChanged(object sender, TextChangedEventArgs e)
  73. {
  74. if (annotParam == null)
  75. {
  76. PropertyChanged?.Invoke(this, GetMarkupData());
  77. }
  78. else
  79. {
  80. if (markupAnnot != null && markupAnnot.IsValid())
  81. {
  82. markupAnnot.SetContent(NoteTextBox.Text);
  83. if (viewControl != null && viewControl.PDFViewTool != null)
  84. {
  85. viewControl.UpdateAnnotFrame();
  86. }
  87. }
  88. }
  89. }
  90. public CPDFMarkupData GetMarkupData()
  91. {
  92. CPDFMarkupData pdfMarkupData = new CPDFMarkupData();
  93. pdfMarkupData.AnnotationType = currentAnnotationType;
  94. pdfMarkupData.Color = ((SolidColorBrush)ColorPickerControl.Brush).Color;
  95. pdfMarkupData.Opacity = CPDFOpacityControl.OpacityValue / 100.0;
  96. pdfMarkupData.Note = NoteTextBox.Text;
  97. return pdfMarkupData;
  98. }
  99. public void SetPresentAnnotAttrib(AnnotParam param,CPDFMarkupAnnotation markup,PDFViewControl view)
  100. {
  101. this.annotParam = null;
  102. this.markupAnnot = null;
  103. this.viewControl = null;
  104. if(param!=null)
  105. {
  106. if(param is HighlightParam)
  107. {
  108. HighlightParam highlightParam = (HighlightParam)param;
  109. Color newColor = Color.FromRgb(
  110. highlightParam.HighlightColor[0],
  111. highlightParam.HighlightColor[1],
  112. highlightParam.HighlightColor[2]);
  113. ColorPickerControl.Brush = new SolidColorBrush(newColor);
  114. ColorPickerControl.SetCheckedForColor(newColor);
  115. }
  116. if(param is UnderlineParam)
  117. {
  118. UnderlineParam underlineParam = (UnderlineParam)param;
  119. Color newColor = Color.FromRgb(
  120. underlineParam.UnderlineColor[0],
  121. underlineParam.UnderlineColor[1],
  122. underlineParam.UnderlineColor[2]);
  123. ColorPickerControl.Brush = new SolidColorBrush(newColor);
  124. ColorPickerControl.SetCheckedForColor(newColor);
  125. }
  126. if (param is StrikeoutParam)
  127. {
  128. StrikeoutParam strikeoutParam = (StrikeoutParam)param;
  129. Color newColor = Color.FromRgb(
  130. strikeoutParam.StrikeoutColor[0],
  131. strikeoutParam.StrikeoutColor[1],
  132. strikeoutParam.StrikeoutColor[2]);
  133. ColorPickerControl.Brush = new SolidColorBrush(newColor);
  134. ColorPickerControl.SetCheckedForColor(newColor);
  135. }
  136. if(param is SquigglyParam)
  137. {
  138. SquigglyParam squigglyParam= (SquigglyParam)param;
  139. Color newColor = Color.FromRgb(
  140. squigglyParam.SquigglyColor[0],
  141. squigglyParam.SquigglyColor[1],
  142. squigglyParam.SquigglyColor[2]);
  143. ColorPickerControl.Brush = new SolidColorBrush(newColor);
  144. ColorPickerControl.SetCheckedForColor(newColor);
  145. }
  146. CPDFOpacityControl.OpacityValue = (int)(param.Transparency / 255D * 100);
  147. NoteTextBox.Text = param.Content;
  148. }
  149. this.annotParam = param;
  150. this.markupAnnot = markup;
  151. this.viewControl = view;
  152. CPDFAnnotationPreviewerControl.DrawMarkUpPreview(GetMarkupData());
  153. }
  154. public void InitWithAnnotationType(CPDFAnnotationType annotationType)
  155. {
  156. currentAnnotationType = annotationType;
  157. switch (annotationType)
  158. {
  159. case CPDFAnnotationType.Highlight:
  160. TitleTextBlock.Text = LanguageHelper.PropertyPanelManager.GetString("Title_Highlight");
  161. break;
  162. case CPDFAnnotationType.Underline:
  163. TitleTextBlock.Text = LanguageHelper.PropertyPanelManager.GetString("Title_Underline");
  164. break;
  165. case CPDFAnnotationType.Strikeout:
  166. TitleTextBlock.Text = LanguageHelper.PropertyPanelManager.GetString("Title_Strikeout");
  167. break;
  168. case CPDFAnnotationType.Squiggly:
  169. TitleTextBlock.Text = LanguageHelper.PropertyPanelManager.GetString("Title_Squiggly");
  170. break;
  171. default:
  172. throw new ArgumentException("Not Excepted Argument");
  173. }
  174. CPDFAnnotationPreviewerControl.DrawMarkUpPreview(GetMarkupData());
  175. }
  176. }
  177. }