AnnotationListItem.xaml.cs 11 KB

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