CPDFShapeUI.xaml.cs 31 KB

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