TextFieldProperty.xaml.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. using Compdfkit_Tools.Common;
  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.ComponentModel;
  9. using System.Linq;
  10. using System.Security.AccessControl;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows;
  14. using System.Windows.Controls;
  15. using System.Windows.Data;
  16. using System.Windows.Documents;
  17. using System.Windows.Input;
  18. using System.Windows.Media;
  19. using System.Windows.Media.Imaging;
  20. using System.Windows.Navigation;
  21. using System.Windows.Shapes;
  22. namespace Compdfkit_Tools.PDFControl
  23. {
  24. /// <summary>
  25. /// TextFieldProperty.xaml 的交互逻辑
  26. /// </summary>
  27. public partial class TextFieldProperty : UserControl
  28. {
  29. private WidgetTextBoxArgs widgetArgs = null;
  30. private AnnotAttribEvent annotAttribEvent = null;
  31. public ObservableCollection<int> SizeList { get; set; } = new ObservableCollection<int>
  32. {
  33. 6,8,9,10,12,14,18,20,24,26,28,32,30,32,48,72
  34. };
  35. bool IsLoadedData = false;
  36. public TextFieldProperty()
  37. {
  38. InitializeComponent();
  39. }
  40. #region Loaded
  41. public void SetProperty(WidgetArgs Args, AnnotAttribEvent e)
  42. {
  43. widgetArgs = (WidgetTextBoxArgs)Args;
  44. annotAttribEvent = e;
  45. }
  46. private void UserControl_Loaded(object sender, RoutedEventArgs e)
  47. {
  48. Binding SizeListbinding = new Binding();
  49. SizeListbinding.Source = this;
  50. SizeListbinding.Path = new System.Windows.PropertyPath("SizeList");
  51. FontSizeCombox.SetBinding(ComboBox.ItemsSourceProperty, SizeListbinding);
  52. FieldNameText.Text = widgetArgs.FieldName;
  53. FormFieldCombox.SelectedIndex = (int)widgetArgs.FormField;
  54. BorderColorPickerControl.SetCheckedForColor(widgetArgs.LineColor);
  55. BackgroundColorPickerControl.SetCheckedForColor(widgetArgs.BgColor);
  56. TextColorPickerControl.SetCheckedForColor(widgetArgs.FontColor);
  57. SetFontName(widgetArgs.FontName);
  58. SetFontStyle(widgetArgs.IsItalic, widgetArgs.IsBold);
  59. SetFontSize(widgetArgs.FontSize);
  60. TextAlignmentCombox.SelectedIndex = (int)widgetArgs.Alignment;
  61. DefaultText.Text = widgetArgs.Text;
  62. chkMutiline.IsChecked = widgetArgs.IsMultiLine;
  63. IsLoadedData = true;
  64. }
  65. private void UserControl_Unloaded(object sender, RoutedEventArgs e)
  66. {
  67. IsLoadedData = false;
  68. }
  69. private void SetFontSize(double size)
  70. {
  71. int index = SizeList.IndexOf((int)size);
  72. FontSizeCombox.SelectedIndex = index;
  73. }
  74. private void SetFontStyle(bool IsItalic, bool IsBold)
  75. {
  76. int index = 0;
  77. if (IsItalic && IsBold)
  78. {
  79. index = 3;
  80. }
  81. else if (IsItalic)
  82. {
  83. index = 2;
  84. }
  85. else if (IsBold)
  86. {
  87. index = 1;
  88. }
  89. FontStyleCombox.SelectedIndex = index;
  90. }
  91. private void SetFontName(string fontName)
  92. {
  93. int index = -1;
  94. List<string> fontFamilyList = new List<string>() { "Helvetica", "Courier", "Times" };
  95. for (int i = 0; i < fontFamilyList.Count; i++)
  96. {
  97. if (fontFamilyList[i].ToLower().Contains(fontName.ToLower())
  98. || fontName.ToLower().Contains(fontFamilyList[i].ToLower()))
  99. {
  100. index = i;
  101. }
  102. }
  103. FontCombox.SelectedIndex = index;
  104. }
  105. #endregion
  106. #region Updata
  107. private void FieldNameText_TextChanged(object sender, TextChangedEventArgs e)
  108. {
  109. if (IsLoadedData)
  110. {
  111. annotAttribEvent.UpdateAttrib(AnnotAttrib.FieldName, (sender as TextBox).Text);
  112. annotAttribEvent.UpdateAnnot();
  113. }
  114. }
  115. private void FormFieldCombox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  116. {
  117. if (IsLoadedData)
  118. {
  119. annotAttribEvent.UpdateAttrib(AnnotAttrib.FormField, (sender as ComboBox).SelectedIndex);
  120. annotAttribEvent.UpdateAnnot();
  121. }
  122. }
  123. private void BorderColorPickerControl_ColorChanged(object sender, EventArgs e)
  124. {
  125. if (IsLoadedData)
  126. {
  127. annotAttribEvent.UpdateAttrib(AnnotAttrib.Color, ((SolidColorBrush)BorderColorPickerControl.Brush).Color);
  128. annotAttribEvent.UpdateAnnot();
  129. }
  130. }
  131. private void BackgroundColorPickerControl_ColorChanged(object sender, EventArgs e)
  132. {
  133. if (IsLoadedData)
  134. {
  135. annotAttribEvent.UpdateAttrib(AnnotAttrib.FillColor, ((SolidColorBrush)BackgroundColorPickerControl.Brush).Color);
  136. annotAttribEvent.UpdateAnnot();
  137. }
  138. }
  139. private void TextColorPickerControl_ColorChanged(object sender, EventArgs e)
  140. {
  141. if (IsLoadedData)
  142. {
  143. annotAttribEvent.UpdateAttrib(AnnotAttrib.FontColor, ((SolidColorBrush)TextColorPickerControl.Brush).Color);
  144. annotAttribEvent.UpdateAnnot();
  145. }
  146. }
  147. private void FontCombox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  148. {
  149. if (IsLoadedData)
  150. {
  151. annotAttribEvent.UpdateAttrib(AnnotAttrib.FontName, ((sender as ComboBox).SelectedItem as ComboBoxItem).Content.ToString());
  152. annotAttribEvent.UpdateAnnot();
  153. }
  154. }
  155. private void FontStyleCombox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  156. {
  157. if (IsLoadedData)
  158. {
  159. bool IsItalic = false;
  160. bool IsBold = false;
  161. switch ((sender as ComboBox).SelectedIndex)
  162. {
  163. case 0:
  164. break;
  165. case 1:
  166. IsBold = true;
  167. break;
  168. case 2:
  169. IsItalic = true;
  170. break;
  171. case 3:
  172. IsItalic = true;
  173. IsBold = true;
  174. break;
  175. default:
  176. break;
  177. }
  178. annotAttribEvent.UpdateAttrib(AnnotAttrib.IsBold, IsBold);
  179. annotAttribEvent.UpdateAttrib(AnnotAttrib.IsItalic, IsItalic);
  180. annotAttribEvent.UpdateAnnot();
  181. }
  182. }
  183. private void FontSizeCombox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  184. {
  185. if (IsLoadedData)
  186. {
  187. annotAttribEvent.UpdateAttrib(AnnotAttrib.FontSize, (sender as ComboBox).SelectedItem );
  188. annotAttribEvent.UpdateAnnot();
  189. }
  190. }
  191. private void TextAlignmentCombox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  192. {
  193. if (IsLoadedData)
  194. {
  195. annotAttribEvent.UpdateAttrib(AnnotAttrib.TextAlign, (sender as ComboBox).SelectedIndex);
  196. annotAttribEvent.UpdateAnnot();
  197. }
  198. }
  199. private void DefaultText_TextChanged(object sender, TextChangedEventArgs e)
  200. {
  201. if (IsLoadedData)
  202. {
  203. annotAttribEvent.UpdateAttrib(AnnotAttrib.Text, (sender as TextBox).Text);
  204. annotAttribEvent.UpdateAnnot();
  205. }
  206. }
  207. private void chkMutiline_Checked(object sender, RoutedEventArgs e)
  208. {
  209. if (IsLoadedData)
  210. {
  211. annotAttribEvent.UpdateAttrib(AnnotAttrib.IsMutilLine, true);
  212. annotAttribEvent.UpdateAnnot();
  213. }
  214. }
  215. private void chkMutiline_Unchecked(object sender, RoutedEventArgs e)
  216. {
  217. if (IsLoadedData)
  218. {
  219. annotAttribEvent.UpdateAttrib(AnnotAttrib.IsMutilLine, false);
  220. annotAttribEvent.UpdateAnnot();
  221. }
  222. }
  223. #endregion
  224. }
  225. }