StraightnessProperty.xaml.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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.Contains("Courier"))
  138. {
  139. FontCombox.SelectedIndex = 1;
  140. }
  141. else if (fontName == "Arial" || fontName.Contains("Helvetica"))
  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. case AnnotAttrib.NoteText:
  159. NoteTextBox.Text= annotEvent.Attribs[attrib].ToString();
  160. break;
  161. default:
  162. break;
  163. }
  164. }
  165. C_LINE_TYPE headLineType = C_LINE_TYPE.LINETYPE_NONE;
  166. C_LINE_TYPE tailLineType = C_LINE_TYPE.LINETYPE_NONE;
  167. if(annotEvent.Attribs.ContainsKey(AnnotAttrib.LineStart))
  168. {
  169. headLineType = (C_LINE_TYPE)annotEvent.Attribs[AnnotAttrib.LineStart];
  170. }
  171. if (annotEvent.Attribs.ContainsKey(AnnotAttrib.LineEnd))
  172. {
  173. tailLineType = (C_LINE_TYPE)annotEvent.Attribs[AnnotAttrib.LineEnd];
  174. }
  175. LineType lineType = new LineType()
  176. {
  177. HeadLineType = headLineType,
  178. TailLineType = tailLineType
  179. };
  180. CPDFArrowControl.LineType = lineType;
  181. bool isBold=false;
  182. bool isItalic=false;
  183. if (annotEvent.Attribs.ContainsKey(AnnotAttrib.IsBold))
  184. {
  185. isBold = (bool)annotEvent.Attribs[AnnotAttrib.IsBold];
  186. }
  187. if (annotEvent.Attribs.ContainsKey(AnnotAttrib.IsItalic))
  188. {
  189. isItalic = (bool)annotEvent.Attribs[AnnotAttrib.IsItalic];
  190. }
  191. SetFontStyle(isBold, isItalic);
  192. }
  193. LineEvent =annotEvent;
  194. }
  195. public void SetAnnotArgsData(LineMeasureArgs annotArgs)
  196. {
  197. Dictionary<AnnotAttrib, object> attribDict = new Dictionary<AnnotAttrib, object>();
  198. attribDict[AnnotAttrib.Color] = annotArgs.LineColor;
  199. attribDict[AnnotAttrib.Transparency] = annotArgs.Transparency;
  200. attribDict[AnnotAttrib.Thickness] = annotArgs.LineWidth;
  201. attribDict[AnnotAttrib.LineStyle] = annotArgs.LineDash;
  202. attribDict[AnnotAttrib.LineStart] = annotArgs.HeadLineType;
  203. attribDict[AnnotAttrib.LineEnd] = annotArgs.TailLineType;
  204. attribDict[AnnotAttrib.FontColor] = annotArgs.FontColor;
  205. attribDict[AnnotAttrib.FontName] = annotArgs.FontName;
  206. attribDict[AnnotAttrib.IsBold] = annotArgs.IsBold;
  207. attribDict[AnnotAttrib.IsItalic] = annotArgs.IsItalic;
  208. attribDict[AnnotAttrib.FontSize] = annotArgs.FontSize;
  209. attribDict[AnnotAttrib.NoteText] = annotArgs.Content;
  210. AnnotAttribEvent annotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annotArgs, attribDict);
  211. SetAnnotEventData(annotEvent);
  212. }
  213. public void SetFontStyle(bool isBold, bool isItalic)
  214. {
  215. if (isBold == false && isItalic == false)
  216. {
  217. FontStyleCombox.SelectedIndex = 0;
  218. return;
  219. }
  220. if (isBold && isItalic == false)
  221. {
  222. FontStyleCombox.SelectedIndex = 1;
  223. return;
  224. }
  225. if (isBold == false && isItalic)
  226. {
  227. FontStyleCombox.SelectedIndex = 2;
  228. return;
  229. }
  230. if (isBold && isItalic)
  231. {
  232. FontStyleCombox.SelectedIndex = 3;
  233. }
  234. }
  235. private void SetFontSize(double size)
  236. {
  237. int index = SizeList.IndexOf((int)size);
  238. FontSizeComboBox.SelectedIndex = index;
  239. }
  240. private void CPDFThicknessControl_ThicknessChanged(object sender, EventArgs e)
  241. {
  242. LineEvent?.UpdateAttrib(AnnotAttrib.Thickness, CPDFThicknessControl.Thickness);
  243. LineEvent?.UpdateAnnot();
  244. }
  245. private void CPDFLineStyleControl_LineStyleChanged(object sender, EventArgs e)
  246. {
  247. LineEvent?.UpdateAttrib(AnnotAttrib.LineStyle, CPDFLineStyleControl.DashStyle);
  248. LineEvent?.UpdateAnnot();
  249. }
  250. private void CPDFArrowControl_ArrowChanged(object sender, EventArgs e)
  251. {
  252. LineEvent?.UpdateAttrib(AnnotAttrib.LineStart, CPDFArrowControl.LineType.HeadLineType);
  253. LineEvent?.UpdateAttrib(AnnotAttrib.LineEnd, CPDFArrowControl.LineType.TailLineType);
  254. LineEvent?.UpdateAnnot();
  255. }
  256. private void FontColorPickerControl_ColorChanged(object sender, EventArgs e)
  257. {
  258. SolidColorBrush checkBrush = FontColorPickerControl.GetBrush() as SolidColorBrush;
  259. if (checkBrush != null)
  260. {
  261. LineEvent?.UpdateAttrib(AnnotAttrib.FontColor, checkBrush.Color);
  262. LineEvent?.UpdateAnnot();
  263. }
  264. }
  265. private void UserControl_Loaded(object sender, RoutedEventArgs e)
  266. {
  267. Binding SizeListbinding = new Binding();
  268. SizeListbinding.Source = this;
  269. SizeListbinding.Path = new System.Windows.PropertyPath("SizeList");
  270. FontSizeComboBox.SetBinding(ComboBox.ItemsSourceProperty, SizeListbinding);
  271. IsLoadedData = true;
  272. }
  273. private void UserControl_Unloaded(object sender, RoutedEventArgs e)
  274. {
  275. IsLoadedData = false;
  276. }
  277. }
  278. }