CPDFShapeUI.xaml.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. using ComPDFKit.PDFAnnotation;
  2. using ComPDFKit.Tool;
  3. using ComPDFKit.Controls.Common;
  4. using ComPDFKit.Controls.Data;
  5. using ComPDFKit.Controls.PDFControl;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Windows;
  10. using System.Windows.Controls;
  11. using System.Windows.Media;
  12. using ComPDFKit.Controls.Helper;
  13. using ComPDFKit.Tool.Help;
  14. using ComPDFKit.Tool.UndoManger;
  15. using ComPDFKitViewer.Helper;
  16. namespace ComPDFKit.Controls.PDFControlUI
  17. {
  18. public partial class CPDFShapeUI : UserControl
  19. {
  20. private CPDFAnnotationType currentAnnotationType;
  21. private AnnotParam annotParam;
  22. private CPDFAnnotation annotCore;
  23. private PDFViewControl viewControl;
  24. public event EventHandler<CPDFAnnotationData> PropertyChanged;
  25. public CPDFShapeUI()
  26. {
  27. InitializeComponent();
  28. BorderColorPickerControl.ColorChanged -= BorderColorPickerControl_ColorChanged;
  29. CPDFOpacityControl.OpacityChanged -= CPDFOpacityControl_OpacityChanged;
  30. CPDFThicknessControl.ThicknessChanged -= CPDFThicknessControl_ThicknessChanged;
  31. CPDFLineStyleControl.LineStyleChanged -= CPDFLineStyleControl_LineStyleChanged;
  32. BorderColorPickerControl.ColorChanged += BorderColorPickerControl_ColorChanged;
  33. CPDFOpacityControl.OpacityChanged += CPDFOpacityControl_OpacityChanged;
  34. CPDFThicknessControl.ThicknessChanged += CPDFThicknessControl_ThicknessChanged;
  35. CPDFLineStyleControl.LineStyleChanged += CPDFLineStyleControl_LineStyleChanged;
  36. CPDFAnnotationPreviewerControl.DrawShapePreview(GetShapeData());
  37. }
  38. private AnnotHistory GetHistory()
  39. {
  40. if (annotCore != null && annotCore.IsValid())
  41. {
  42. switch (annotCore.Type)
  43. {
  44. case C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE:
  45. return new SquareAnnotHistory();
  46. case C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE:
  47. return new CircleAnnotHistory();
  48. case C_ANNOTATION_TYPE.C_ANNOTATION_LINE:
  49. return new LineAnnotHistory();
  50. }
  51. }
  52. return new AnnotHistory();
  53. }
  54. private void BorderColorPickerControl_ColorChanged(object sender, EventArgs e)
  55. {
  56. if (annotParam == null)
  57. {
  58. PropertyChanged?.Invoke(this, GetShapeData());
  59. }
  60. else
  61. {
  62. SolidColorBrush borderBrush=BorderColorPickerControl.Brush as SolidColorBrush;
  63. if(annotCore!=null && annotCore.IsValid() && borderBrush!=null)
  64. {
  65. byte[] color = new byte[3]
  66. {
  67. borderBrush.Color.R,
  68. borderBrush.Color.G,
  69. borderBrush.Color.B
  70. };
  71. if (viewControl != null)
  72. {
  73. AnnotHistory history = GetHistory();
  74. history.PDFDoc = viewControl.GetCPDFViewer().GetDocument();
  75. history.Action = HistoryAction.Update;
  76. if (annotCore.Type == C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE)
  77. {
  78. CPDFSquareAnnotation squareAnnot = annotCore as CPDFSquareAnnotation;
  79. if (squareAnnot == null || squareAnnot.LineColor.SequenceEqual(color)) return;
  80. history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, squareAnnot);
  81. squareAnnot?.SetLineColor(color);
  82. history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, squareAnnot);
  83. }
  84. if (annotCore.Type == C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE)
  85. {
  86. CPDFCircleAnnotation circleAnnot = annotCore as CPDFCircleAnnotation;
  87. if (circleAnnot == null || circleAnnot.LineColor.SequenceEqual(color)) return;
  88. history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, circleAnnot);
  89. circleAnnot?.SetLineColor(color);
  90. history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, circleAnnot);
  91. }
  92. if (annotCore.Type == C_ANNOTATION_TYPE.C_ANNOTATION_LINE)
  93. {
  94. CPDFLineAnnotation lineAnnot = annotCore as CPDFLineAnnotation;
  95. if (lineAnnot == null || lineAnnot.LineColor.SequenceEqual(color)) return;
  96. history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, lineAnnot);
  97. lineAnnot?.SetLineColor(color);
  98. history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, lineAnnot);
  99. }
  100. annotCore.UpdateAp();
  101. viewControl.GetCPDFViewer().UndoManager.AddHistory(history);
  102. viewControl.UpdateAnnotFrame();
  103. }
  104. }
  105. }
  106. CPDFAnnotationPreviewerControl.DrawShapePreview(GetShapeData());
  107. }
  108. private void FillColorPickerControl_ColorChanged(object sender, EventArgs e)
  109. {
  110. if (annotParam == null)
  111. {
  112. PropertyChanged?.Invoke(this, GetShapeData());
  113. }
  114. else
  115. {
  116. SolidColorBrush fillBrush = FillColorPickerControl.Brush as SolidColorBrush;
  117. if (annotCore != null && annotCore.IsValid() && fillBrush != null)
  118. {
  119. byte[] color = new byte[3]
  120. {
  121. fillBrush.Color.R,
  122. fillBrush.Color.G,
  123. fillBrush.Color.B
  124. };
  125. if (viewControl != null && viewControl.PDFViewTool != null)
  126. {
  127. AnnotHistory history = GetHistory();
  128. history.PDFDoc = viewControl.GetCPDFViewer().GetDocument();
  129. history.Action = HistoryAction.Update;
  130. if (annotCore.Type == C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE)
  131. {
  132. CPDFSquareAnnotation squareAnnot = annotCore as CPDFSquareAnnotation;
  133. if (squareAnnot == null || squareAnnot.BgColor.SequenceEqual(color)) return;
  134. history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, squareAnnot);
  135. squareAnnot?.SetBgColor(color);
  136. history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, squareAnnot);
  137. }
  138. if (annotCore.Type == C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE)
  139. {
  140. CPDFCircleAnnotation circleAnnot = annotCore as CPDFCircleAnnotation;
  141. if (circleAnnot == null || circleAnnot.BgColor.SequenceEqual(color)) return;
  142. history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, circleAnnot);
  143. circleAnnot?.SetBgColor(color);
  144. history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, circleAnnot);
  145. }
  146. if (annotCore.Type == C_ANNOTATION_TYPE.C_ANNOTATION_LINE)
  147. {
  148. CPDFLineAnnotation lineAnnot = annotCore as CPDFLineAnnotation;
  149. if (lineAnnot == null || lineAnnot.BgColor.SequenceEqual(color)) return;
  150. history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, lineAnnot);
  151. lineAnnot?.SetBgColor(color);
  152. history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, lineAnnot);
  153. }
  154. annotCore.UpdateAp();
  155. viewControl.GetCPDFViewer().UndoManager.AddHistory(history);
  156. viewControl.UpdateAnnotFrame();
  157. }
  158. }
  159. }
  160. CPDFAnnotationPreviewerControl.DrawShapePreview(GetShapeData());
  161. }
  162. private void CPDFThicknessControl_ThicknessChanged(object sender, EventArgs e)
  163. {
  164. if (annotParam == null)
  165. {
  166. PropertyChanged?.Invoke(this, GetShapeData());
  167. }
  168. else
  169. {
  170. if (annotCore != null && annotCore.IsValid())
  171. {
  172. if (viewControl != null && Math.Abs(CPDFThicknessControl.Thickness - annotCore.GetBorderWidth()) > 0.01)
  173. {
  174. AnnotHistory history = GetHistory();
  175. history.PDFDoc = viewControl.GetCPDFViewer().GetDocument();
  176. history.Action = HistoryAction.Update;
  177. if (annotCore.Type == C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE)
  178. {
  179. CPDFSquareAnnotation squareAnnot = annotCore as CPDFSquareAnnotation;
  180. history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, squareAnnot);
  181. squareAnnot?.SetLineWidth(CPDFThicknessControl.Thickness);
  182. history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, squareAnnot);
  183. }
  184. if (annotCore.Type == C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE)
  185. {
  186. CPDFCircleAnnotation circleAnnot = annotCore as CPDFCircleAnnotation;
  187. history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, circleAnnot);
  188. circleAnnot?.SetLineWidth(CPDFThicknessControl.Thickness);
  189. history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, circleAnnot);
  190. }
  191. if (annotCore.Type == C_ANNOTATION_TYPE.C_ANNOTATION_LINE)
  192. {
  193. CPDFLineAnnotation lineAnnot = annotCore as CPDFLineAnnotation;
  194. history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, lineAnnot);
  195. lineAnnot?.SetLineWidth(CPDFThicknessControl.Thickness);
  196. history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, lineAnnot);
  197. }
  198. annotCore.UpdateAp();
  199. viewControl.GetCPDFViewer().UndoManager.AddHistory(history);
  200. viewControl.UpdateAnnotFrame();
  201. }
  202. }
  203. }
  204. CPDFAnnotationPreviewerControl.DrawShapePreview(GetShapeData());
  205. }
  206. private void CPDFOpacityControl_OpacityChanged(object sender, EventArgs e)
  207. {
  208. if (annotParam == null)
  209. {
  210. PropertyChanged?.Invoke(this, GetShapeData());
  211. }
  212. else
  213. {
  214. double opacity = CPDFOpacityControl.OpacityValue / 100.0;
  215. if (opacity > 0 && opacity <= 1)
  216. {
  217. opacity = opacity * 255;
  218. }
  219. if (annotCore != null && annotCore.IsValid())
  220. {
  221. if (viewControl != null && Math.Abs(opacity - annotCore.GetTransparency()) > 0.01)
  222. {
  223. AnnotHistory history = GetHistory();
  224. history.PDFDoc = viewControl.GetCPDFViewer().GetDocument();
  225. history.Action = HistoryAction.Update;
  226. if (annotCore.Type == C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE)
  227. {
  228. CPDFSquareAnnotation squareAnnot = annotCore as CPDFSquareAnnotation;
  229. history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, squareAnnot);
  230. squareAnnot?.SetTransparency((byte)opacity);
  231. history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, squareAnnot);
  232. }
  233. if (annotCore.Type == C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE)
  234. {
  235. CPDFCircleAnnotation circleAnnot = annotCore as CPDFCircleAnnotation;
  236. history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, circleAnnot);
  237. circleAnnot?.SetTransparency((byte)opacity);
  238. history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, circleAnnot);
  239. }
  240. if (annotCore.Type == C_ANNOTATION_TYPE.C_ANNOTATION_LINE)
  241. {
  242. CPDFLineAnnotation lineAnnot = annotCore as CPDFLineAnnotation;
  243. history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, lineAnnot);
  244. lineAnnot?.SetTransparency((byte)opacity);
  245. history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, lineAnnot);
  246. }
  247. annotCore.UpdateAp();
  248. viewControl.GetCPDFViewer().UndoManager.AddHistory(history);
  249. viewControl.UpdateAnnotFrame();
  250. }
  251. }
  252. }
  253. CPDFAnnotationPreviewerControl.DrawShapePreview(GetShapeData());
  254. }
  255. private void CPDFLineStyleControl_LineStyleChanged(object sender, EventArgs e)
  256. {
  257. if (annotParam == null)
  258. {
  259. PropertyChanged?.Invoke(this, GetShapeData());
  260. }
  261. else
  262. {
  263. if (annotCore != null && annotCore.IsValid())
  264. {
  265. float[] dashArray = null;
  266. C_BORDER_STYLE borderStyle;
  267. if (CPDFLineStyleControl.DashStyle == DashStyles.Solid || CPDFLineStyleControl.DashStyle == null)
  268. {
  269. dashArray = new float[0];
  270. borderStyle = C_BORDER_STYLE.BS_SOLID;
  271. }
  272. else
  273. {
  274. List<float> floatArray = new List<float>();
  275. foreach (double num in CPDFLineStyleControl.DashStyle.Dashes)
  276. {
  277. floatArray.Add((float)num);
  278. }
  279. dashArray = floatArray.ToArray();
  280. borderStyle = C_BORDER_STYLE.BS_DASHDED;
  281. }
  282. if (viewControl != null && viewControl.PDFViewTool != null)
  283. {
  284. AnnotHistory history = GetHistory();
  285. history.PDFDoc = viewControl.GetCPDFViewer().GetDocument();
  286. history.Action = HistoryAction.Update;
  287. if (annotCore.Type == C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE)
  288. {
  289. CPDFSquareAnnotation squareAnnot = annotCore as CPDFSquareAnnotation;
  290. if(squareAnnot == null || squareAnnot.Dash.SequenceEqual(dashArray))return;
  291. history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, squareAnnot);
  292. squareAnnot.SetBorderStyle(borderStyle, dashArray);
  293. history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, squareAnnot);
  294. }
  295. if (annotCore.Type == C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE)
  296. {
  297. CPDFCircleAnnotation circleAnnot = annotCore as CPDFCircleAnnotation;
  298. if (circleAnnot == null || circleAnnot.Dash.SequenceEqual(dashArray)) return;
  299. history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, circleAnnot);
  300. circleAnnot.SetBorderStyle(borderStyle, dashArray);
  301. history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, circleAnnot);
  302. }
  303. if (annotCore.Type == C_ANNOTATION_TYPE.C_ANNOTATION_LINE)
  304. {
  305. CPDFLineAnnotation lineAnnot = annotCore as CPDFLineAnnotation;
  306. if (lineAnnot == null || lineAnnot.Dash.SequenceEqual(dashArray)) return;
  307. history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, lineAnnot);
  308. lineAnnot.SetBorderStyle(borderStyle, dashArray);
  309. history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, lineAnnot);
  310. }
  311. annotCore.UpdateAp();
  312. viewControl.UpdateAnnotFrame();
  313. viewControl.GetCPDFViewer().UndoManager.AddHistory(history);
  314. }
  315. }
  316. }
  317. CPDFAnnotationPreviewerControl.DrawShapePreview(GetShapeData());
  318. }
  319. private void CPDFArrowControl_ArrowChanged(object sender, EventArgs e)
  320. {
  321. if (annotParam == null)
  322. {
  323. PropertyChanged?.Invoke(PropertyChanged, GetShapeData());
  324. }
  325. else
  326. {
  327. if (annotCore != null && annotCore.IsValid())
  328. {
  329. if(annotCore.Type==C_ANNOTATION_TYPE.C_ANNOTATION_LINE)
  330. {
  331. CPDFLineAnnotation lineAnnot= annotCore as CPDFLineAnnotation;
  332. if(lineAnnot!=null && viewControl != null)
  333. {
  334. if(lineAnnot.HeadLineType != CPDFArrowControl.LineType.HeadLineType || lineAnnot.TailLineType != CPDFArrowControl.LineType.TailLineType)
  335. {
  336. LineAnnotHistory history = new LineAnnotHistory();
  337. history.PDFDoc = viewControl.GetCPDFViewer().GetDocument();
  338. history.Action = HistoryAction.Update;
  339. history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, lineAnnot);
  340. lineAnnot.SetLineType(CPDFArrowControl.LineType.HeadLineType, CPDFArrowControl.LineType.TailLineType);
  341. lineAnnot.UpdateAp();
  342. history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, lineAnnot);
  343. viewControl.GetCPDFViewer().UndoManager.AddHistory(history);
  344. viewControl.UpdateAnnotFrame();
  345. }
  346. }
  347. }
  348. }
  349. }
  350. CPDFAnnotationPreviewerControl.DrawShapePreview(GetShapeData());
  351. }
  352. private void NoteTextBox_TextChanged(object sender, TextChangedEventArgs e)
  353. {
  354. if (annotParam == null)
  355. {
  356. PropertyChanged?.Invoke(this, GetShapeData());
  357. }
  358. else
  359. {
  360. if (annotCore != null && annotCore.IsValid())
  361. {
  362. if (viewControl != null && annotCore.GetContent()!=NoteTextBox.Text)
  363. {
  364. AnnotHistory history = GetHistory();
  365. history.PDFDoc = viewControl.GetCPDFViewer().GetDocument();
  366. history.Action = HistoryAction.Update;
  367. history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, annotCore);
  368. annotCore.SetContent(NoteTextBox.Text);
  369. viewControl.UpdateAnnotFrame();
  370. history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, annotCore);
  371. viewControl.GetCPDFViewer().UndoManager.AddHistory(history);
  372. }
  373. }
  374. }
  375. }
  376. public CPDFAnnotationData GetShapeData()
  377. {
  378. if (currentAnnotationType == CPDFAnnotationType.Circle || currentAnnotationType == CPDFAnnotationType.Square)
  379. {
  380. CPDFShapeData pdfShapeData = new CPDFShapeData();
  381. pdfShapeData.AnnotationType = currentAnnotationType;
  382. pdfShapeData.BorderColor = ((SolidColorBrush)BorderColorPickerControl.Brush).Color;
  383. pdfShapeData.FillColor = ((SolidColorBrush)FillColorPickerControl.Brush).Color;
  384. pdfShapeData.Opacity = CPDFOpacityControl.OpacityValue / 100.0;
  385. pdfShapeData.Thickness = CPDFThicknessControl.Thickness;
  386. pdfShapeData.DashStyle = CPDFLineStyleControl.DashStyle;
  387. pdfShapeData.Note = NoteTextBox.Text;
  388. return pdfShapeData;
  389. }
  390. else
  391. {
  392. CPDFLineShapeData pdfLineShapeData = new CPDFLineShapeData();
  393. pdfLineShapeData.AnnotationType = currentAnnotationType;
  394. pdfLineShapeData.BorderColor = ((SolidColorBrush)BorderColorPickerControl.Brush).Color;
  395. pdfLineShapeData.Opacity = CPDFOpacityControl.OpacityValue / 100.0;
  396. pdfLineShapeData.LineType = CPDFArrowControl.LineType;
  397. pdfLineShapeData.Thickness = CPDFThicknessControl.Thickness;
  398. pdfLineShapeData.DashStyle = CPDFLineStyleControl.DashStyle;
  399. pdfLineShapeData.LineType = CPDFArrowControl.LineType;
  400. pdfLineShapeData.Note = NoteTextBox.Text;
  401. return pdfLineShapeData;
  402. }
  403. }
  404. public void SetPresentAnnotAttrib(AnnotParam param,CPDFAnnotation annot,PDFViewControl view)
  405. {
  406. annotParam = null;
  407. annotCore = null;
  408. viewControl = null;
  409. if(param != null)
  410. {
  411. if(param is SquareParam)
  412. {
  413. SquareParam squareParam= (SquareParam)param;
  414. CPDFThicknessControl.Thickness = (int)squareParam.LineWidth;
  415. if (squareParam.LineColor != null)
  416. {
  417. BorderColorPickerControl.Brush = new SolidColorBrush(Color.FromRgb(
  418. squareParam.LineColor[0],
  419. squareParam.LineColor[1],
  420. squareParam.LineColor[2]));
  421. BorderColorPickerControl.SetCheckedForColor(Color.FromRgb(
  422. squareParam.LineColor[0],
  423. squareParam.LineColor[1],
  424. squareParam.LineColor[2]));
  425. }
  426. if (squareParam.BgColor!=null)
  427. {
  428. FillColorPickerControl.Brush = new SolidColorBrush(Color.FromRgb(
  429. squareParam.BgColor[0],
  430. squareParam.BgColor[1],
  431. squareParam.BgColor[2]));
  432. FillColorPickerControl.SetCheckedForColor(Color.FromRgb(
  433. squareParam.BgColor[0],
  434. squareParam.BgColor[1],
  435. squareParam.BgColor[2]));
  436. }
  437. if (squareParam.BorderStyle == C_BORDER_STYLE.BS_SOLID)
  438. {
  439. CPDFLineStyleControl.DashStyle = DashStyles.Solid;
  440. }
  441. else
  442. {
  443. List<double> dashArray = new List<double>();
  444. foreach (double num in squareParam.LineDash)
  445. {
  446. dashArray.Add(num);
  447. }
  448. CPDFLineStyleControl.DashStyle = new DashStyle(dashArray, 0);
  449. }
  450. }
  451. if(param is CircleParam)
  452. {
  453. CircleParam circleParam= (CircleParam)param;
  454. CPDFThicknessControl.Thickness = (int)circleParam.LineWidth;
  455. if (circleParam.LineColor != null)
  456. {
  457. BorderColorPickerControl.Brush = new SolidColorBrush(Color.FromRgb(
  458. circleParam.LineColor[0],
  459. circleParam.LineColor[1],
  460. circleParam.LineColor[2]));
  461. BorderColorPickerControl.SetCheckedForColor(Color.FromRgb(
  462. circleParam.LineColor[0],
  463. circleParam.LineColor[1],
  464. circleParam.LineColor[2]));
  465. }
  466. if (circleParam.BgColor!=null)
  467. {
  468. FillColorPickerControl.Brush = new SolidColorBrush(Color.FromRgb(
  469. circleParam.BgColor[0],
  470. circleParam.BgColor[1],
  471. circleParam.BgColor[2]));
  472. FillColorPickerControl.SetCheckedForColor(Color.FromRgb(
  473. circleParam.BgColor[0],
  474. circleParam.BgColor[1],
  475. circleParam.BgColor[2]));
  476. }
  477. if (circleParam.BorderStyle == C_BORDER_STYLE.BS_SOLID)
  478. {
  479. CPDFLineStyleControl.DashStyle = DashStyles.Solid;
  480. }
  481. else
  482. {
  483. List<double> dashArray = new List<double>();
  484. foreach (double num in circleParam.LineDash)
  485. {
  486. dashArray.Add(num);
  487. }
  488. CPDFLineStyleControl.DashStyle = new DashStyle(dashArray, 0);
  489. }
  490. }
  491. if(param is LineParam)
  492. {
  493. LineParam lineParam= (LineParam)param;
  494. CPDFThicknessControl.Thickness = (int)lineParam.LineWidth;
  495. if (lineParam.LineColor != null)
  496. {
  497. BorderColorPickerControl.Brush = new SolidColorBrush(Color.FromRgb(
  498. lineParam.LineColor[0],
  499. lineParam.LineColor[1],
  500. lineParam.LineColor[2]));
  501. BorderColorPickerControl.SetCheckedForColor(Color.FromRgb(
  502. lineParam.LineColor[0],
  503. lineParam.LineColor[1],
  504. lineParam.LineColor[2]));
  505. }
  506. if (lineParam.BgColor != null)
  507. {
  508. FillColorPickerControl.Brush = new SolidColorBrush(Color.FromRgb(
  509. lineParam.BgColor[0],
  510. lineParam.BgColor[1],
  511. lineParam.BgColor[2]));
  512. FillColorPickerControl.SetCheckedForColor(Color.FromRgb(
  513. lineParam.BgColor[0],
  514. lineParam.BgColor[1],
  515. lineParam.BgColor[2]));
  516. }
  517. if(lineParam.BorderStyle == C_BORDER_STYLE.BS_SOLID)
  518. {
  519. CPDFLineStyleControl.DashStyle = DashStyles.Solid;
  520. }
  521. else
  522. {
  523. List<double> dashArray = new List<double>();
  524. foreach (double num in lineParam.LineDash)
  525. {
  526. dashArray.Add(num);
  527. }
  528. CPDFLineStyleControl.DashStyle = new DashStyle(dashArray, 0);
  529. }
  530. LineType lineType = new LineType()
  531. {
  532. HeadLineType = lineParam.HeadLineType,
  533. TailLineType = lineParam.TailLineType
  534. };
  535. CPDFArrowControl.LineType = lineType;
  536. }
  537. CPDFOpacityControl.OpacityValue = (int)Math.Ceiling(param.Transparency * 100 / 255.0);
  538. NoteTextBox.Text = param.Content;
  539. }
  540. annotParam = param;
  541. annotCore = annot;
  542. viewControl = view;
  543. CPDFAnnotationPreviewerControl.DrawShapePreview(GetShapeData());
  544. }
  545. public void InitWhenRectAndRound()
  546. {
  547. FillColorStackPanel.Visibility = Visibility.Visible;
  548. ArrowStackPanel.Visibility = Visibility.Collapsed;
  549. FillColorPickerControl.ColorChanged -= FillColorPickerControl_ColorChanged;
  550. FillColorPickerControl.ColorChanged += FillColorPickerControl_ColorChanged;
  551. CPDFArrowControl.ArrowChanged -= CPDFArrowControl_ArrowChanged;
  552. }
  553. public void InitWhenArrowAndLine()
  554. {
  555. FillColorStackPanel.Visibility = Visibility.Collapsed;
  556. ArrowStackPanel.Visibility = Visibility.Visible;
  557. CPDFArrowControl.ArrowChanged -= CPDFArrowControl_ArrowChanged;
  558. CPDFArrowControl.ArrowChanged += CPDFArrowControl_ArrowChanged;
  559. FillColorPickerControl.ColorChanged -= FillColorPickerControl_ColorChanged;
  560. LineType lineType;
  561. if (currentAnnotationType == CPDFAnnotationType.Arrow)
  562. {
  563. lineType = new LineType()
  564. {
  565. HeadLineType = C_LINE_TYPE.LINETYPE_NONE,
  566. TailLineType = C_LINE_TYPE.LINETYPE_ARROW
  567. };
  568. }
  569. else
  570. {
  571. lineType = new LineType()
  572. {
  573. HeadLineType = C_LINE_TYPE.LINETYPE_NONE,
  574. TailLineType = C_LINE_TYPE.LINETYPE_NONE
  575. };
  576. }
  577. CPDFArrowControl.LineType = lineType;
  578. }
  579. public void InitWithAnnotationType(CPDFAnnotationType annotationType)
  580. {
  581. currentAnnotationType = annotationType;
  582. switch (annotationType)
  583. {
  584. case CPDFAnnotationType.Square:
  585. TitleTextBlock.Text = LanguageHelper.PropertyPanelManager.GetString("Title_Square");
  586. InitWhenRectAndRound();
  587. break;
  588. case CPDFAnnotationType.Circle:
  589. TitleTextBlock.Text = LanguageHelper.PropertyPanelManager.GetString("Title_Circle");
  590. InitWhenRectAndRound();
  591. break;
  592. case CPDFAnnotationType.Arrow:
  593. TitleTextBlock.Text = LanguageHelper.PropertyPanelManager.GetString("Title_Arrow");
  594. InitWhenArrowAndLine();
  595. break;
  596. case CPDFAnnotationType.Line:
  597. TitleTextBlock.Text = LanguageHelper.PropertyPanelManager.GetString("Title_Line");
  598. InitWhenArrowAndLine();
  599. break;
  600. default:
  601. throw new ArgumentException("Not Excepted Argument");
  602. }
  603. CPDFAnnotationPreviewerControl.DrawShapePreview(GetShapeData());
  604. }
  605. }
  606. }