MultilineProperty.xaml.cs 11 KB

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