StraightnessProperty.xaml.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. using ComPDFKit.PDFAnnotation;
  2. using Compdfkit_Tools.Common;
  3. using Compdfkit_Tools.Data;
  4. using ComPDFKitViewer;
  5. using ComPDFKitViewer.AnnotEvent;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Collections.ObjectModel;
  9. using System.Diagnostics;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows;
  14. using System.Windows.Controls;
  15. using System.Windows.Data;
  16. using System.Windows.Documents;
  17. using System.Windows.Input;
  18. using System.Windows.Media;
  19. using System.Windows.Media.Imaging;
  20. using System.Windows.Navigation;
  21. using System.Windows.Shapes;
  22. namespace Compdfkit_Tools.Measure.Property
  23. {
  24. /// <summary>
  25. /// StraightnessProperty.xaml 的交互逻辑
  26. /// </summary>
  27. public partial class StraightnessProperty : UserControl
  28. {
  29. private AnnotAttribEvent LineEvent { get; set; }
  30. public ObservableCollection<int> SizeList { get; set; } = new ObservableCollection<int>
  31. {
  32. 6,8,9,10,12,14,18,20,24,26,28,32,30,32,48,72
  33. };
  34. bool IsLoadedData = false;
  35. public StraightnessProperty()
  36. {
  37. InitializeComponent();
  38. }
  39. private void NoteTextBox_TextChanged(object sender, TextChangedEventArgs e)
  40. {
  41. LineEvent.UpdateAttrib(AnnotAttrib.NoteText, NoteTextBox.Text);
  42. LineEvent.UpdateAnnot();
  43. }
  44. private void FontStyleCombox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  45. {
  46. int selectIndex = Math.Max(0, FontStyleCombox.SelectedIndex);
  47. bool isBold = false;
  48. bool isItalic = false;
  49. switch (selectIndex)
  50. {
  51. case 0:
  52. isBold = false;
  53. isItalic = false;
  54. break;
  55. case 1:
  56. isBold = true;
  57. isItalic = false;
  58. break;
  59. case 2:
  60. isBold = false;
  61. isItalic = true;
  62. break;
  63. case 3:
  64. isBold = true;
  65. isItalic = true;
  66. break;
  67. default:
  68. break;
  69. }
  70. LineEvent?.UpdateAttrib(AnnotAttrib.IsBold, isBold);
  71. LineEvent?.UpdateAttrib(AnnotAttrib.IsItalic, isItalic);
  72. LineEvent?.UpdateAnnot();
  73. }
  74. private void FontSizeComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  75. {
  76. if (IsLoadedData)
  77. {
  78. LineEvent.UpdateAttrib(AnnotAttrib.FontSize, (sender as ComboBox).SelectedItem);
  79. LineEvent.UpdateAnnot();
  80. }
  81. }
  82. private void FontCombox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  83. {
  84. ComboBoxItem selectItem = FontCombox.SelectedItem as ComboBoxItem;
  85. if (selectItem != null && selectItem.Content != null)
  86. {
  87. LineEvent?.UpdateAttrib(AnnotAttrib.FontName, selectItem.Content.ToString());
  88. LineEvent?.UpdateAnnot();
  89. }
  90. }
  91. private void BorderColorPickerControl_ColorChanged(object sender, EventArgs e)
  92. {
  93. SolidColorBrush checkBrush = BorderColorPickerControl.GetBrush() as SolidColorBrush;
  94. if (checkBrush != null)
  95. {
  96. LineEvent?.UpdateAttrib(AnnotAttrib.Color, checkBrush.Color);
  97. LineEvent?.UpdateAnnot();
  98. }
  99. }
  100. private void CPDFOpacityControl_OpacityChanged(object sender, EventArgs e)
  101. {
  102. LineEvent?.UpdateAttrib(AnnotAttrib.Transparency, CPDFOpacityControl.OpacityValue/100D);
  103. LineEvent?.UpdateAnnot();
  104. }
  105. public void SetAnnotEventData(AnnotAttribEvent annotEvent)
  106. {
  107. LineEvent = null;
  108. if(annotEvent!=null)
  109. {
  110. foreach(AnnotAttrib attrib in annotEvent.Attribs.Keys)
  111. {
  112. switch(attrib)
  113. {
  114. case AnnotAttrib.Color:
  115. BorderColorPickerControl.SetCheckedForColor((Color)annotEvent.Attribs[attrib]);
  116. break;
  117. case AnnotAttrib.Transparency:
  118. double transparennt= Convert.ToDouble(annotEvent.Attribs[attrib]);
  119. if(transparennt>1)
  120. {
  121. transparennt =(transparennt / 255D);
  122. }
  123. CPDFOpacityControl.OpacityValue = (int)(transparennt*100);
  124. break;
  125. case AnnotAttrib.Thickness:
  126. CPDFThicknessControl.Thickness = Convert.ToInt16(annotEvent.Attribs[attrib]);
  127. break;
  128. case AnnotAttrib.LineStyle:
  129. CPDFLineStyleControl.DashStyle= (DashStyle)(annotEvent.Attribs[attrib]);
  130. break;
  131. case AnnotAttrib.FontColor:
  132. FontColorPickerControl.SetCheckedForColor((Color)annotEvent.Attribs[attrib]);
  133. break;
  134. case AnnotAttrib.FontName:
  135. {
  136. string fontName= (string)annotEvent.Attribs[AnnotAttrib.FontName];
  137. if (fontName == "Courier New")
  138. {
  139. FontCombox.SelectedIndex = 1;
  140. }
  141. else if (fontName == "Arial")
  142. {
  143. FontCombox.SelectedIndex = 0;
  144. }
  145. else if (fontName.Contains("Times"))
  146. {
  147. FontCombox.SelectedIndex = 2;
  148. }
  149. else
  150. {
  151. FontCombox.SelectedIndex = -1;
  152. }
  153. }
  154. break;
  155. case AnnotAttrib.FontSize:
  156. SetFontSize(Convert.ToDouble(annotEvent.Attribs[attrib]));
  157. break;
  158. default:
  159. break;
  160. }
  161. }
  162. C_LINE_TYPE headLineType = C_LINE_TYPE.LINETYPE_NONE;
  163. C_LINE_TYPE tailLineType = C_LINE_TYPE.LINETYPE_NONE;
  164. if(annotEvent.Attribs.ContainsKey(AnnotAttrib.LineStart))
  165. {
  166. headLineType = (C_LINE_TYPE)annotEvent.Attribs[AnnotAttrib.LineStart];
  167. }
  168. if (annotEvent.Attribs.ContainsKey(AnnotAttrib.LineEnd))
  169. {
  170. tailLineType = (C_LINE_TYPE)annotEvent.Attribs[AnnotAttrib.LineEnd];
  171. }
  172. LineType lineType = new LineType()
  173. {
  174. HeadLineType = headLineType,
  175. TailLineType = tailLineType
  176. };
  177. CPDFArrowControl.LineType = lineType;
  178. bool isBold=false;
  179. bool isItalic=false;
  180. if (annotEvent.Attribs.ContainsKey(AnnotAttrib.IsBold))
  181. {
  182. isBold = (bool)annotEvent.Attribs[AnnotAttrib.IsBold];
  183. }
  184. if (annotEvent.Attribs.ContainsKey(AnnotAttrib.IsItalic))
  185. {
  186. isItalic = (bool)annotEvent.Attribs[AnnotAttrib.IsItalic];
  187. }
  188. SetFontStyle(isBold, isItalic);
  189. }
  190. LineEvent =annotEvent;
  191. }
  192. public void SetAnnotArgsData(LineMeasureArgs annotArgs)
  193. {
  194. Dictionary<AnnotAttrib, object> attribDict = new Dictionary<AnnotAttrib, object>();
  195. attribDict[AnnotAttrib.Color] = annotArgs.LineColor;
  196. attribDict[AnnotAttrib.Transparency] = annotArgs.Transparency;
  197. attribDict[AnnotAttrib.Thickness] = annotArgs.LineWidth;
  198. attribDict[AnnotAttrib.LineStyle] = annotArgs.LineDash;
  199. attribDict[AnnotAttrib.LineStart] = annotArgs.HeadLineType;
  200. attribDict[AnnotAttrib.LineEnd] = annotArgs.TailLineType;
  201. attribDict[AnnotAttrib.FontColor] = annotArgs.FontColor;
  202. attribDict[AnnotAttrib.FontName] = annotArgs.FontName;
  203. attribDict[AnnotAttrib.IsBold] = annotArgs.IsBold;
  204. attribDict[AnnotAttrib.IsItalic] = annotArgs.IsItalic;
  205. attribDict[AnnotAttrib.FontSize] = annotArgs.FontSize;
  206. attribDict[AnnotAttrib.NoteText] = annotArgs.Content;
  207. AnnotAttribEvent annotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annotArgs, attribDict);
  208. SetAnnotEventData(annotEvent);
  209. }
  210. public void SetFontStyle(bool isBold, bool isItalic)
  211. {
  212. if (isBold == false && isItalic == false)
  213. {
  214. FontStyleCombox.SelectedIndex = 0;
  215. return;
  216. }
  217. if (isBold && isItalic == false)
  218. {
  219. FontStyleCombox.SelectedIndex = 1;
  220. return;
  221. }
  222. if (isBold == false && isItalic)
  223. {
  224. FontStyleCombox.SelectedIndex = 2;
  225. return;
  226. }
  227. if (isBold && isItalic)
  228. {
  229. FontStyleCombox.SelectedIndex = 3;
  230. }
  231. }
  232. private void SetFontSize(double size)
  233. {
  234. int index = SizeList.IndexOf((int)size);
  235. FontSizeComboBox.SelectedIndex = index;
  236. }
  237. private void CPDFThicknessControl_ThicknessChanged(object sender, EventArgs e)
  238. {
  239. LineEvent?.UpdateAttrib(AnnotAttrib.Thickness, CPDFThicknessControl.Thickness);
  240. LineEvent?.UpdateAnnot();
  241. }
  242. private void CPDFLineStyleControl_LineStyleChanged(object sender, EventArgs e)
  243. {
  244. LineEvent?.UpdateAttrib(AnnotAttrib.LineStyle, CPDFLineStyleControl.DashStyle);
  245. LineEvent?.UpdateAnnot();
  246. }
  247. private void CPDFArrowControl_ArrowChanged(object sender, EventArgs e)
  248. {
  249. LineEvent?.UpdateAttrib(AnnotAttrib.LineStart, CPDFArrowControl.LineType.HeadLineType);
  250. LineEvent?.UpdateAttrib(AnnotAttrib.LineEnd, CPDFArrowControl.LineType.TailLineType);
  251. LineEvent?.UpdateAnnot();
  252. }
  253. private void FontColorPickerControl_ColorChanged(object sender, EventArgs e)
  254. {
  255. SolidColorBrush checkBrush = FontColorPickerControl.GetBrush() as SolidColorBrush;
  256. if (checkBrush != null)
  257. {
  258. LineEvent?.UpdateAttrib(AnnotAttrib.FontColor, checkBrush.Color);
  259. LineEvent?.UpdateAnnot();
  260. }
  261. }
  262. private void UserControl_Loaded(object sender, RoutedEventArgs e)
  263. {
  264. Binding SizeListbinding = new Binding();
  265. SizeListbinding.Source = this;
  266. SizeListbinding.Path = new System.Windows.PropertyPath("SizeList");
  267. FontSizeComboBox.SetBinding(ComboBox.ItemsSourceProperty, SizeListbinding);
  268. IsLoadedData = true;
  269. }
  270. private void UserControl_Unloaded(object sender, RoutedEventArgs e)
  271. {
  272. IsLoadedData = false;
  273. }
  274. }
  275. }