MultilineProperty.xaml.cs 11 KB

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