MultilineProperty.xaml.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. using ComPDFKit.PDFAnnotation;
  2. using ComPDFKit.Controls.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. using ComPDFKit.Controls.PDFControl;
  20. using ComPDFKit.Tool;
  21. using CFontNameHelper = ComPDFKit.PDFAnnotation.CTextAttribute.CFontNameHelper;
  22. namespace ComPDFKit.Controls.Measure.Property
  23. {
  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. private PolyLineMeasureParam polyLineMeasureParam;
  33. public CPDFPolylineAnnotation Annotation{ get; set; }
  34. public PDFViewControl ViewControl{ get; set; }
  35. public MultilineProperty()
  36. {
  37. InitializeComponent();
  38. }
  39. private void NoteTextBox_TextChanged(object sender, TextChangedEventArgs e)
  40. {
  41. if (IsLoadedData)
  42. {
  43. if (Annotation != null && ViewControl != null)
  44. {
  45. Annotation.SetContent(NoteTextBox.Text);
  46. Annotation.UpdateAp();
  47. ViewControl?.UpdateAnnotFrame();
  48. }
  49. }
  50. }
  51. private void FontStyleCombox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  52. {
  53. if (!IsLoadedData) return;
  54. int selectIndex = Math.Max(0, FontStyleCombox.SelectedIndex);
  55. bool isBold = false;
  56. bool isItalic = false;
  57. switch (selectIndex)
  58. {
  59. case 0:
  60. isBold = false;
  61. isItalic = false;
  62. break;
  63. case 1:
  64. isBold = true;
  65. isItalic = false;
  66. break;
  67. case 2:
  68. isBold = false;
  69. isItalic = true;
  70. break;
  71. case 3:
  72. isBold = true;
  73. isItalic = true;
  74. break;
  75. default:
  76. break;
  77. }
  78. if(Annotation != null)
  79. {
  80. CTextAttribute textAttribute = Annotation.GetTextAttribute();
  81. var fontType = CFontNameHelper.GetFontType((FontCombox.SelectedItem as ComboBoxItem).Content.ToString());
  82. var newName = CFontNameHelper.ObtainFontName(fontType, isBold, isItalic);
  83. textAttribute.FontName = newName;
  84. Annotation.SetTextAttribute(textAttribute);
  85. Annotation.UpdateAp();
  86. ViewControl?.UpdateAnnotFrame();
  87. }
  88. }
  89. private void FontCombox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  90. {
  91. if (IsLoadedData)
  92. {
  93. if (Annotation != null && ViewControl != null)
  94. {
  95. ComboBoxItem selectItem = FontCombox.SelectedItem as ComboBoxItem;
  96. if (selectItem != null && selectItem.Content != null)
  97. {
  98. CTextAttribute textAttr = Annotation.GetTextAttribute();
  99. bool isBold = CFontNameHelper.IsBold(textAttr.FontName);
  100. bool isItalic = CFontNameHelper.IsItalic(textAttr.FontName);
  101. var fontType = CFontNameHelper.GetFontType(selectItem.Content.ToString());
  102. textAttr.FontName = CFontNameHelper.ObtainFontName(fontType, isBold, isItalic);
  103. Annotation.SetTextAttribute(textAttr);
  104. Annotation.UpdateAp();
  105. ViewControl.UpdateAnnotFrame();
  106. }
  107. }
  108. }
  109. }
  110. private void FontSizeCombox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  111. {
  112. if (IsLoadedData)
  113. {
  114. if (FontSizeComboBox.SelectedItem != null)
  115. {
  116. if (Annotation != null && ViewControl != null)
  117. {
  118. CTextAttribute textAttribute = Annotation.GetTextAttribute();
  119. textAttribute.FontSize = (float)Convert.ToDouble(FontSizeComboBox.SelectedItem);
  120. Annotation.SetTextAttribute(textAttribute);
  121. Annotation.UpdateAp();
  122. ViewControl?.UpdateAnnotFrame();
  123. }
  124. }
  125. }
  126. }
  127. private void BorderColorPickerControl_ColorChanged(object sender, EventArgs e)
  128. {
  129. if (IsLoadedData)
  130. {
  131. if (Annotation != null && ViewControl != null)
  132. {
  133. SolidColorBrush checkBrush = BorderColorPickerControl.GetBrush() as SolidColorBrush;
  134. if (checkBrush != null)
  135. {
  136. byte[] color = { checkBrush.Color.R, checkBrush.Color.G, checkBrush.Color.B };
  137. Annotation.SetLineColor(color);
  138. Annotation.UpdateAp();
  139. ViewControl.UpdateAnnotFrame();
  140. }
  141. }
  142. }
  143. }
  144. private void CPDFOpacityControl_OpacityChanged(object sender, EventArgs e)
  145. {
  146. if (IsLoadedData)
  147. {
  148. if (Annotation != null && ViewControl != null)
  149. {
  150. double opacity = CPDFOpacityControl.OpacityValue / 100.0;
  151. if (opacity > 0 && opacity <= 1)
  152. {
  153. opacity = opacity * 255;
  154. }
  155. if (Math.Abs(opacity - Annotation.GetTransparency()) > 0.01)
  156. {
  157. Annotation.SetTransparency((byte)opacity);
  158. Annotation.UpdateAp();
  159. ViewControl.UpdateAnnotFrame();
  160. }
  161. }
  162. }
  163. }
  164. private void CPDFThicknessControl_ThicknessChanged(object sender, EventArgs e)
  165. {
  166. if (IsLoadedData)
  167. {
  168. if (Annotation != null && ViewControl != null)
  169. {
  170. Annotation.SetLineWidth(CPDFThicknessControl.Thickness);
  171. Annotation.UpdateAp();
  172. ViewControl.UpdateAnnotFrame();
  173. }
  174. }
  175. }
  176. private void CPDFLineStyleControl_LineStyleChanged(object sender, EventArgs e)
  177. {
  178. if (!IsLoadedData) return;
  179. if (Annotation != null && ViewControl != null)
  180. {
  181. float[] dashArray = null;
  182. C_BORDER_STYLE borderStyle;
  183. if (CPDFLineStyleControl.DashStyle == DashStyles.Solid || CPDFLineStyleControl.DashStyle == null)
  184. {
  185. dashArray = new float[0];
  186. borderStyle = C_BORDER_STYLE.BS_SOLID;
  187. }
  188. else
  189. {
  190. List<float> floatArray = new List<float>();
  191. foreach (double num in CPDFLineStyleControl.DashStyle.Dashes)
  192. {
  193. floatArray.Add((float)num);
  194. }
  195. dashArray = floatArray.ToArray();
  196. borderStyle = C_BORDER_STYLE.BS_DASHDED;
  197. }
  198. Annotation.SetBorderStyle(borderStyle, dashArray);
  199. Annotation.UpdateAp();
  200. ViewControl.UpdateAnnotFrame();
  201. }
  202. }
  203. private void FontColorPickerControl_ColorChanged(object sender, EventArgs e)
  204. {
  205. if (!IsLoadedData) return;
  206. SolidColorBrush checkBrush = FontColorPickerControl.GetBrush() as SolidColorBrush;
  207. if (checkBrush != null && Annotation != null && ViewControl != null)
  208. {
  209. byte[] color = { checkBrush.Color.R, checkBrush.Color.G, checkBrush.Color.B };
  210. if (Annotation != null)
  211. {
  212. CTextAttribute textAttribute = Annotation.GetTextAttribute();
  213. textAttribute.FontColor = color;
  214. Annotation.SetTextAttribute(textAttribute);
  215. Annotation.UpdateAp();
  216. ViewControl.UpdateAnnotFrame();
  217. }
  218. }
  219. }
  220. public void SetFontStyle(bool isBold, bool isItalic)
  221. {
  222. if (isBold == false && isItalic == false)
  223. {
  224. FontStyleCombox.SelectedIndex = 0;
  225. return;
  226. }
  227. if (isBold && isItalic == false)
  228. {
  229. FontStyleCombox.SelectedIndex = 1;
  230. return;
  231. }
  232. if (isBold == false && isItalic)
  233. {
  234. FontStyleCombox.SelectedIndex = 2;
  235. return;
  236. }
  237. if (isBold && isItalic)
  238. {
  239. FontStyleCombox.SelectedIndex = 3;
  240. }
  241. }
  242. private void SetFontSize(double size)
  243. {
  244. int index = SizeList.IndexOf((int)size);
  245. FontSizeComboBox.SelectedIndex = index;
  246. }
  247. public void SetFontName(string fontName)
  248. {
  249. foreach (ComboBoxItem item in FontCombox.Items)
  250. {
  251. if (item.Content.ToString() == fontName)
  252. {
  253. FontCombox.SelectedItem = item;
  254. break;
  255. }
  256. }
  257. }
  258. private void UserControl_Loaded(object sender, RoutedEventArgs e)
  259. {
  260. Binding SizeListbinding = new Binding();
  261. SizeListbinding.Source = this;
  262. SizeListbinding.Path = new System.Windows.PropertyPath("SizeList");
  263. FontSizeComboBox.SetBinding(ComboBox.ItemsSourceProperty, SizeListbinding);
  264. IsLoadedData = true;
  265. }
  266. private void UserControl_Unloaded(object sender, RoutedEventArgs e)
  267. {
  268. IsLoadedData = false;
  269. }
  270. public void SetAnnotParam(PolyLineMeasureParam param, CPDFAnnotation annot, PDFViewControl viewControl)
  271. {
  272. Annotation = annot as CPDFPolylineAnnotation;
  273. ViewControl = viewControl;
  274. polyLineMeasureParam = param;
  275. if (param == null)
  276. {
  277. return;
  278. }
  279. Color lineColor = Color.FromRgb(param.LineColor[0], param.LineColor[1], param.LineColor[2]);
  280. BorderColorPickerControl.SetCheckedForColor(lineColor);
  281. CPDFThicknessControl.Thickness = (int)param.LineWidth;
  282. if (polyLineMeasureParam.BorderStyle == C_BORDER_STYLE.BS_SOLID)
  283. {
  284. CPDFLineStyleControl.DashStyle = DashStyles.Solid;
  285. }
  286. else
  287. {
  288. List<double> dashArray = new List<double>();
  289. foreach (double num in param.LineDash)
  290. {
  291. dashArray.Add(num);
  292. }
  293. CPDFLineStyleControl.DashStyle = new DashStyle(dashArray, 0);
  294. }
  295. double opacity = param.Transparency / 255.0 * 100.0;
  296. CPDFOpacityControl.OpacityValue = (int)Math.Ceiling(opacity);
  297. NoteTextBox.Text = param.Content;
  298. SetFontSize(param.FontSize);
  299. SetFontStyle(param.IsBold,param.IsItalic);
  300. SetFontName(param.FontName);
  301. }
  302. }
  303. }