PolygonalProperty.xaml.cs 11 KB

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