MultilineProperty.xaml.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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);
  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. public 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.Contains("Courier"))
  183. {
  184. FontCombox.SelectedIndex = 1;
  185. }
  186. else if (fontName == "Arial" || fontName.Contains("Helvetica"))
  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. case AnnotAttrib.NoteText:
  204. NoteTextBox.Text = annotEvent.Attribs[attrib].ToString();
  205. break;
  206. default:
  207. break;
  208. }
  209. }
  210. bool isBold = false;
  211. bool isItalic = false;
  212. if (annotEvent.Attribs.ContainsKey(AnnotAttrib.IsBold))
  213. {
  214. isBold = (bool)annotEvent.Attribs[AnnotAttrib.IsBold];
  215. }
  216. if (annotEvent.Attribs.ContainsKey(AnnotAttrib.IsItalic))
  217. {
  218. isItalic = (bool)annotEvent.Attribs[AnnotAttrib.IsItalic];
  219. }
  220. SetFontStyle(isBold, isItalic);
  221. }
  222. MultilineEvent = annotEvent;
  223. }
  224. public void SetFontStyle(bool isBold, bool isItalic)
  225. {
  226. if (isBold == false && isItalic == false)
  227. {
  228. FontStyleCombox.SelectedIndex = 0;
  229. return;
  230. }
  231. if (isBold && isItalic == false)
  232. {
  233. FontStyleCombox.SelectedIndex = 1;
  234. return;
  235. }
  236. if (isBold == false && isItalic)
  237. {
  238. FontStyleCombox.SelectedIndex = 2;
  239. return;
  240. }
  241. if (isBold && isItalic)
  242. {
  243. FontStyleCombox.SelectedIndex = 3;
  244. }
  245. }
  246. private void SetFontSize(double size)
  247. {
  248. int index = SizeList.IndexOf((int)size);
  249. FontSizeComboBox.SelectedIndex = index;
  250. }
  251. private void UserControl_Loaded(object sender, RoutedEventArgs e)
  252. {
  253. Binding SizeListbinding = new Binding();
  254. SizeListbinding.Source = this;
  255. SizeListbinding.Path = new System.Windows.PropertyPath("SizeList");
  256. FontSizeComboBox.SetBinding(ComboBox.ItemsSourceProperty, SizeListbinding);
  257. IsLoadedData = true;
  258. }
  259. private void UserControl_Unloaded(object sender, RoutedEventArgs e)
  260. {
  261. IsLoadedData = false;
  262. }
  263. }
  264. }