AnnotationListItem.xaml.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. using ComPDFKit.Import;
  2. using ComPDFKit.PDFAnnotation;
  3. using ComPDFKit.PDFDocument;
  4. using ComPDFKit.PDFPage;
  5. using ComPDFKitViewer.AnnotEvent;
  6. using ComPDFKitViewer.PdfViewer;
  7. using PDF_Office.Helper;
  8. using PDF_Office.Model.BOTA;
  9. using PDF_Office.ViewModels.BOTA;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.IO;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Text.RegularExpressions;
  16. using System.Threading.Tasks;
  17. using System.Windows;
  18. using System.Windows.Controls;
  19. using System.Windows.Data;
  20. using System.Windows.Documents;
  21. using System.Windows.Input;
  22. using System.Windows.Media;
  23. using System.Windows.Media.Imaging;
  24. using System.Windows.Navigation;
  25. using System.Windows.Shapes;
  26. namespace PDF_Office.Views.BOTA
  27. {
  28. /// <summary>
  29. /// AnnotationListItem.xaml 的交互逻辑
  30. /// </summary>
  31. public partial class AnnotationListItem : UserControl
  32. {
  33. //private Brush strikeoutColor = new SolidColorBrush(Color.FromRgb(0xFF, 0xBB, 0x00));
  34. public AnnotationListItem()
  35. {
  36. InitializeComponent();
  37. }
  38. private void GridIco_Loaded(object sender, RoutedEventArgs e)
  39. {
  40. Grid grid = e.Source as Grid;
  41. var args = grid.DataContext as AnnotationHandlerEventArgs;
  42. AnnotHandlerEventArgs data = args.AnnotHandlerEventArgs;
  43. if (data == null)
  44. {
  45. return;
  46. }
  47. switch (data.EventType)
  48. {
  49. case AnnotArgsType.AnnotFreeText:
  50. BtnAnnotFreeText.Visibility = Visibility.Visible;
  51. TxbMarkUpContent.Foreground = new SolidColorBrush((data as FreeTextAnnotArgs).FontColor);
  52. break;
  53. case AnnotArgsType.AnnotHighlight:
  54. BtnHighlight.Visibility = Visibility.Visible;
  55. PathHighlight.Fill = new SolidColorBrush((data as TextHighlightAnnotArgs).Color);
  56. //TxbContext.Text = data.Content;
  57. if (!string.IsNullOrEmpty(TxbContext.Text))
  58. {
  59. TxbContext.Background = new SolidColorBrush((data as TextHighlightAnnotArgs).Color);
  60. }
  61. break;
  62. case AnnotArgsType.AnnotFreehand:
  63. BtnFreeHand.Visibility = Visibility.Visible;
  64. PathFreehand.Fill = new SolidColorBrush((data as FreehandAnnotArgs).InkColor);
  65. ImageContext.Visibility = Visibility.Visible;
  66. TxbContext.Visibility = Visibility.Collapsed;
  67. //var encoder = new PngBitmapEncoder();
  68. //encoder.Frames.Add(BitmapFrame.Create((BitmapSource)ImageContext.Source));
  69. //FileStream file = new FileStream(String.Format($@"C:\Users\oyxh\Desktop\images\PDFText\{data.AnnotIndex}.png"), FileMode.Create);
  70. //encoder.Save(file);
  71. //file.Close();
  72. break;
  73. case AnnotArgsType.AnnotSquiggly://波浪线
  74. AnnotSquiggly.Visibility = Visibility.Visible;
  75. AnnotSquigglycolor.Stroke = new SolidColorBrush((data as TextSquigglyAnnotArgs).Color);
  76. #region TO DO
  77. //TextDecoration mySquiggly = new TextDecoration();
  78. //Pen myPen = new Pen();
  79. //myPen.Brush = new SolidColorBrush((data as TextSquigglyAnnotArgs).Color);
  80. //myPen.Brush.Opacity = 0.8;
  81. //myPen.Thickness = 2;
  82. //myPen.DashStyle = DashStyles.Dash;
  83. //mySquiggly.Pen = myPen;
  84. //mySquiggly.PenThicknessUnit = TextDecorationUnit.FontRecommended;
  85. //TextDecorationCollection myCollection = new TextDecorationCollection();
  86. //myCollection.Add(mySquiggly);
  87. //TxbContext.TextDecorations = myCollection;
  88. #endregion TO DO
  89. break;
  90. case AnnotArgsType.AnnotStamp:
  91. BtnAnnotStamp.Visibility = Visibility.Visible;
  92. break;
  93. case AnnotArgsType.AnnotStrikeout://删除线
  94. BtnAnnotStrikeout.Visibility = Visibility.Visible;
  95. PathStrikeoutyColor.Fill = new SolidColorBrush((data as TextStrikeoutAnnotArgs).Color);
  96. #region to do
  97. //TextDecoration myStrikeout = new TextDecoration();
  98. //Pen myPen2 = new Pen();
  99. //myPen2.Brush = new SolidColorBrush((data as TextStrikeoutAnnotArgs).Color);
  100. //myPen2.Brush.Opacity = 0.8;
  101. //myPen2.Thickness = 1;
  102. //myStrikeout.Pen = myPen2;
  103. //myStrikeout.PenOffset = -3;
  104. //myStrikeout.PenThicknessUnit = TextDecorationUnit.FontRecommended;
  105. //TextDecorationCollection myCollection2 = new TextDecorationCollection();
  106. //myCollection2.Add(myStrikeout);
  107. //因为波浪线无法实现 暂时只显示文字 不显示下划线,删除线等
  108. //TxbContext.TextDecorations = myCollection2;
  109. #endregion to do
  110. break;
  111. case AnnotArgsType.AnnotSticky://便签
  112. BtnAnnotSticky.Visibility = Visibility;
  113. PathSticky.Fill = new SolidColorBrush((data as StickyAnnotArgs).Color);
  114. break;
  115. case AnnotArgsType.AnnotUnderline:
  116. BtnUnderLine.Visibility = Visibility.Visible;
  117. RectangleUnderline.Fill = new SolidColorBrush((data as TextUnderlineAnnotArgs).Color);
  118. #region TO DO
  119. //TextDecoration myUnderline = new TextDecoration();
  120. //Pen myPen1 = new Pen();
  121. //myPen1.Brush = new SolidColorBrush((data as TextUnderlineAnnotArgs).Color);
  122. //myPen1.Brush.Opacity = 0.8;
  123. //myPen1.Thickness = 2;
  124. //myUnderline.Pen = myPen1;
  125. //myUnderline.PenThicknessUnit = TextDecorationUnit.FontRecommended;
  126. //TextDecorationCollection myCollection1 = new TextDecorationCollection();
  127. //myCollection1.Add(myUnderline);
  128. //TxbContext.TextDecorations = myCollection1;
  129. #endregion TO DO
  130. break;
  131. case AnnotArgsType.AnnotLine:
  132. if ((data as LineAnnotArgs).HeadLineType >= (C_LINE_TYPE)1 || (data as LineAnnotArgs).TailLineType >= (C_LINE_TYPE)1)
  133. {
  134. BtnSharpArrow.Visibility = Visibility.Visible;
  135. PathArrow.Fill = new SolidColorBrush((data as LineAnnotArgs).LineColor);
  136. }
  137. else
  138. {
  139. PathSharpLine.Fill = new SolidColorBrush((data as LineAnnotArgs).LineColor);
  140. BtnSharpLine.Visibility = Visibility.Visible;
  141. }
  142. ///对于形状注释等只有Note 的处理
  143. if (!string.IsNullOrEmpty(data.Content) && string.IsNullOrEmpty(data.MarkupContent))
  144. {
  145. TxbMarkUpContent.Text = Regex.Replace(data.Content, "[\r\n]", " ");
  146. TxbContext.Text = "";
  147. }
  148. break;
  149. case AnnotArgsType.AnnotSquare:
  150. BtnAnnotSquare.Visibility = Visibility.Visible;
  151. RectAnnotSquare.Stroke = new SolidColorBrush((data as SquareAnnotArgs).LineColor);
  152. RectAnnotSquare.Fill = new SolidColorBrush((data as SquareAnnotArgs).BgColor);
  153. ///对于形状注释等只有Note 的处理
  154. if (!string.IsNullOrEmpty(data.Content) && string.IsNullOrEmpty(data.MarkupContent))
  155. {
  156. TxbMarkUpContent.Text = Regex.Replace(data.Content, "[\r\n]", " ");
  157. TxbContext.Text = "";
  158. }
  159. break;
  160. case AnnotArgsType.AnnotCircle:
  161. BtnAnnotCircle.Visibility = Visibility.Visible;
  162. EllipseCircle.Stroke = new SolidColorBrush((data as CircleAnnotArgs).LineColor);
  163. EllipseCircle.Fill = new SolidColorBrush((data as CircleAnnotArgs).BgColor);
  164. ///对于形状注释等只有Note 的处理
  165. if (!string.IsNullOrEmpty(data.Content) && string.IsNullOrEmpty(data.MarkupContent))
  166. {
  167. TxbMarkUpContent.Text = Regex.Replace(data.Content, "[\r\n]", " ");
  168. TxbContext.Text = "";
  169. }
  170. break;
  171. default:
  172. break;
  173. }
  174. }
  175. }
  176. }