StraightnessProperty.xaml.cs 12 KB

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