CPDFAnnotationControl.xaml.cs 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054
  1. using Compdfkit_Tools.Data;
  2. using Compdfkit_Tools.PDFControlUI;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Media.Imaging;
  8. using Compdfkit_Tools.Annotation.PDFAnnotationPanel.PDFAnnotationUI;
  9. using System.IO;
  10. using System.Windows.Ink;
  11. using Compdfkit_Tools.Annotation.PDFAnnotationUI;
  12. using Microsoft.Win32;
  13. using System.Windows.Media;
  14. using Compdfkit_Tools.Properties;
  15. using static ComPDFKit.Tool.CPDFToolManager;
  16. using ComPDFKit.PDFAnnotation;
  17. using ComPDFKit.Tool;
  18. using ComPDFKit.Tool.Help;
  19. using ComPDFKit.Tool.SettingParam;
  20. using ComPDFKit.Import;
  21. using ComPDFKitViewer.BaseObject;
  22. using ComPDFKitViewer.Widget;
  23. using ComPDFKit.PDFDocument;
  24. namespace Compdfkit_Tools.PDFControl
  25. {
  26. public partial class CPDFAnnotationControl : UserControl
  27. {
  28. private bool isTempPanel = false;
  29. private CPDFAnnotationType currentAnnotationType = CPDFAnnotationType.Unknow;
  30. private PDFViewControl pdfViewerControl;
  31. private UIElement annotationPanel = null;
  32. private UIElement tempAnnotationPanel = null;
  33. private CPDFMarkupUI pdfHighlightUI;
  34. private CPDFMarkupUI pdfUnderlineUI;
  35. private CPDFMarkupUI pdfSquigglyUI;
  36. private CPDFMarkupUI pdfStrikeoutUI;
  37. private CPDFShapeUI pdfSquareUI;
  38. private CPDFShapeUI pdfCircleUI;
  39. private CPDFShapeUI pdfLineUI;
  40. private CPDFShapeUI pdfArrowUI;
  41. private CPDFFreehandUI pdfFreehandUI;
  42. private CPDFFreeTextUI pdfFreeTextUI;
  43. private CPDFNoteUI pdfNoteUI;
  44. private CPDFStampUI pdfStampUI;
  45. private CPDFSignatureUI pdfSignatureUI;
  46. private CPDFLinkUI pdfLinkUI;
  47. private bool disableClean;
  48. public event EventHandler ClearAnnotationBar;
  49. public CPDFAnnotationControl()
  50. {
  51. InitializeComponent();
  52. }
  53. public void SetPDFViewer(PDFViewControl pdfViewer)
  54. {
  55. if (this.pdfViewerControl != null)
  56. {
  57. UnLoadPDFViewHandler();
  58. }
  59. this.pdfViewerControl = pdfViewer;
  60. LoadPDFViewHandler();
  61. }
  62. public void LoadPDFViewHandler()
  63. {
  64. if (this.pdfViewerControl != null)
  65. {
  66. pdfViewerControl.PDFToolManager.MouseLeftButtonDownHandler += PDFToolManager_MouseLeftButtonDownHandler; ;
  67. //this.pdfViewerControl.AnnotActiveHandler += PDFViewer_AnnotActiveHandler;
  68. //this.pdfViewerControl.AnnotEditHandler -= PdfViewer_AnnotEditHandler;
  69. //this.pdfViewerControl.AnnotEditHandler += PdfViewer_AnnotEditHandler;
  70. }
  71. }
  72. //private void PdfViewer_AnnotEditHandler(object sender, List<AnnotEditEvent> e)
  73. //{
  74. // if (e != null && e.Count > 0)
  75. // {
  76. // if (e[0].EditAction == ActionType.Del)
  77. // {
  78. // if (pdfViewerControl.MouseMode == MouseModes.AnnotCreate && pdfViewerControl.ToolManager.CurrentAnnotArgs is EraseArgs)
  79. // {
  80. // return;
  81. // }
  82. // SetAnnotEventData(null);
  83. // }
  84. // if (e[0].EditAction == ActionType.Modify && e[0].EditAnnotArgs != null && e[0].EditAnnotArgs.EventType == AnnotArgsType.AnnotSticky)
  85. // {
  86. // CPDFNoteUI tempUI = annotationPanel as CPDFNoteUI;
  87. // if (tempUI == null || tempUI.annotAttribEvent == null)
  88. // {
  89. // tempUI = tempAnnotationPanel as CPDFNoteUI;
  90. // }
  91. // if (tempUI == null || tempUI.annotAttribEvent == null)
  92. // {
  93. // tempUI = pdfNoteUI;
  94. // }
  95. // if (tempUI != null && tempUI.annotAttribEvent != null)
  96. // {
  97. // AnnotAttribEvent oldEvent = tempUI.annotAttribEvent;
  98. // oldEvent.Attribs[AnnotAttrib.NoteText] = e[0].EditAnnotArgs.Content;
  99. // tempUI.SetPresentAnnotAttrib(oldEvent);
  100. // }
  101. // }
  102. // if (e[0].EditAction == ActionType.Add && e[0].EditAnnotArgs.EventType == AnnotArgsType.AnnotStamp)
  103. // {
  104. // pdfViewerControl.SetMouseMode(MouseModes.PanTool);
  105. // }
  106. // }
  107. //}
  108. public void UnLoadPDFViewHandler()
  109. {
  110. if (this.pdfViewerControl != null)
  111. {
  112. //this.pdfViewerControl.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
  113. }
  114. }
  115. private void AnnotationControl_Loaded(object sender, RoutedEventArgs e)
  116. {
  117. LoadPDFViewHandler();
  118. }
  119. private void AnnotationControl_Unloaded(object sender, RoutedEventArgs e)
  120. {
  121. UnLoadPDFViewHandler();
  122. }
  123. private UIElement GetAnnotationPanel()
  124. {
  125. return AnnotationPanelContainer.Child;
  126. }
  127. private void SetAnnotationPanel(UIElement newChild)
  128. {
  129. AnnotationPanelContainer.Child = newChild;
  130. }
  131. private void ExpandPanel()
  132. {
  133. AnnotationPanelContainer.Visibility = Visibility.Visible;
  134. }
  135. private void ChangeAnnotationData()
  136. {
  137. switch (currentAnnotationType)
  138. {
  139. case CPDFAnnotationType.Highlight:
  140. case CPDFAnnotationType.Underline:
  141. case CPDFAnnotationType.Squiggly:
  142. case CPDFAnnotationType.Strikeout:
  143. (annotationPanel as CPDFMarkupUI).PropertyChanged -= CPDFAnnotationControl_PropertyChanged;
  144. (annotationPanel as CPDFMarkupUI).PropertyChanged += CPDFAnnotationControl_PropertyChanged;
  145. SetAnnotationProperty((annotationPanel as CPDFMarkupUI).GetMarkupData());
  146. break;
  147. case CPDFAnnotationType.Square:
  148. case CPDFAnnotationType.Circle:
  149. case CPDFAnnotationType.Line:
  150. case CPDFAnnotationType.Arrow:
  151. (annotationPanel as CPDFShapeUI).PropertyChanged -= CPDFAnnotationControl_PropertyChanged;
  152. (annotationPanel as CPDFShapeUI).PropertyChanged += CPDFAnnotationControl_PropertyChanged;
  153. SetAnnotationProperty((annotationPanel as CPDFShapeUI).GetShapeData());
  154. break;
  155. case CPDFAnnotationType.Note:
  156. (annotationPanel as CPDFNoteUI).PropertyChanged -= CPDFAnnotationControl_PropertyChanged;
  157. (annotationPanel as CPDFNoteUI).PropertyChanged += CPDFAnnotationControl_PropertyChanged;
  158. SetAnnotationProperty((annotationPanel as CPDFNoteUI).GetNoteData());
  159. break;
  160. case CPDFAnnotationType.Freehand:
  161. (annotationPanel as CPDFFreehandUI).PropertyChanged -= CPDFAnnotationControl_PropertyChanged;
  162. (annotationPanel as CPDFFreehandUI).PropertyChanged += CPDFAnnotationControl_PropertyChanged;
  163. SetAnnotationProperty((annotationPanel as CPDFFreehandUI).GetFreehandData());
  164. break;
  165. case CPDFAnnotationType.FreeText:
  166. (annotationPanel as CPDFFreeTextUI).PropertyChanged -= CPDFAnnotationControl_PropertyChanged;
  167. (annotationPanel as CPDFFreeTextUI).PropertyChanged += CPDFAnnotationControl_PropertyChanged;
  168. SetAnnotationProperty((annotationPanel as CPDFFreeTextUI).GetFreeTextData());
  169. break;
  170. case CPDFAnnotationType.Stamp:
  171. (annotationPanel as CPDFStampUI).PropertyChanged -= CPDFAnnotationControl_PropertyChanged;
  172. (annotationPanel as CPDFStampUI).PropertyChanged += CPDFAnnotationControl_PropertyChanged;
  173. break;
  174. case CPDFAnnotationType.Signature:
  175. (annotationPanel as CPDFSignatureUI).PropertyChanged -= CPDFAnnotationControl_PropertyChanged;
  176. (annotationPanel as CPDFSignatureUI).PropertyChanged += CPDFAnnotationControl_PropertyChanged;
  177. break;
  178. default:
  179. break;
  180. }
  181. }
  182. private void SetAnnotationProperty(CPDFAnnotationData pdfAnnotationData = null)
  183. {
  184. if (pdfAnnotationData == null)
  185. {
  186. pdfViewerControl.PDFToolManager.SetToolType(ToolType.Pan);
  187. return;
  188. }
  189. CPDFAnnotationType annotationType = pdfAnnotationData.AnnotationType;
  190. AnnotParam annotHandlerEventArgs = null;
  191. pdfViewerControl.PDFToolManager.SetToolType(ToolType.CreateAnnot);
  192. switch (annotationType)
  193. {
  194. case CPDFAnnotationType.Highlight:
  195. {
  196. CPDFMarkupData highlightData = pdfAnnotationData as CPDFMarkupData;
  197. annotHandlerEventArgs = new HighlightParam();
  198. byte[] Color = new byte[] { highlightData.Color.R, highlightData.Color.G, highlightData.Color.B };
  199. annotHandlerEventArgs.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_HIGHLIGHT;
  200. (annotHandlerEventArgs as HighlightParam).HighlightColor = Color;
  201. (annotHandlerEventArgs as HighlightParam).Transparency = Convert.ToByte(highlightData.Opacity * 255);
  202. (annotHandlerEventArgs as HighlightParam).Content = highlightData.Note;
  203. (annotHandlerEventArgs as HighlightParam).Author = highlightData.Author;
  204. (annotHandlerEventArgs as HighlightParam).Locked = highlightData.IsLocked;
  205. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_HIGHLIGHT);
  206. }
  207. break;
  208. case CPDFAnnotationType.Underline:
  209. {
  210. CPDFMarkupData underlineData = pdfAnnotationData as CPDFMarkupData;
  211. annotHandlerEventArgs = new UnderlineParam();
  212. byte[] Color = new byte[] { underlineData.Color.R, underlineData.Color.G, underlineData.Color.B };
  213. annotHandlerEventArgs.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_UNDERLINE;
  214. (annotHandlerEventArgs as UnderlineParam).UnderlineColor = Color;
  215. (annotHandlerEventArgs as UnderlineParam).Transparency = Convert.ToByte(underlineData.Opacity * 255);
  216. (annotHandlerEventArgs as UnderlineParam).Author = underlineData.Author;
  217. (annotHandlerEventArgs as UnderlineParam).Content = underlineData.Note;
  218. (annotHandlerEventArgs as UnderlineParam).Locked = underlineData.IsLocked;
  219. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_UNDERLINE);
  220. }
  221. break;
  222. case CPDFAnnotationType.Strikeout:
  223. {
  224. CPDFMarkupData strikeoutData = pdfAnnotationData as CPDFMarkupData;
  225. annotHandlerEventArgs = new StrikeoutParam();
  226. byte[] Color = new byte[] { strikeoutData.Color.R, strikeoutData.Color.G, strikeoutData.Color.B };
  227. annotHandlerEventArgs.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_STRIKEOUT;
  228. (annotHandlerEventArgs as StrikeoutParam).StrikeoutColor = Color;
  229. (annotHandlerEventArgs as StrikeoutParam).Transparency = Convert.ToByte(strikeoutData.Opacity * 255);
  230. (annotHandlerEventArgs as StrikeoutParam).Locked = strikeoutData.IsLocked;
  231. (annotHandlerEventArgs as StrikeoutParam).Author = strikeoutData.Author;
  232. (annotHandlerEventArgs as StrikeoutParam).Content = strikeoutData.Note;
  233. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_STRIKEOUT);
  234. }
  235. break;
  236. case CPDFAnnotationType.Squiggly:
  237. {
  238. CPDFMarkupData squigglyData = pdfAnnotationData as CPDFMarkupData;
  239. annotHandlerEventArgs = new SquigglyParam();
  240. byte[] Color = new byte[] { squigglyData.Color.R, squigglyData.Color.G, squigglyData.Color.B };
  241. annotHandlerEventArgs.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_SQUIGGLY;
  242. (annotHandlerEventArgs as SquigglyParam).SquigglyColor = Color;
  243. (annotHandlerEventArgs as SquigglyParam).Transparency = Convert.ToByte(squigglyData.Opacity * 255);
  244. (annotHandlerEventArgs as SquigglyParam).Locked = squigglyData.IsLocked;
  245. (annotHandlerEventArgs as SquigglyParam).Author = squigglyData.Author;
  246. (annotHandlerEventArgs as SquigglyParam).Content = squigglyData.Note;
  247. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_SQUIGGLY);
  248. }
  249. break;
  250. case CPDFAnnotationType.Square:
  251. {
  252. CPDFShapeData squareData = pdfAnnotationData as CPDFShapeData;
  253. annotHandlerEventArgs = new SquareParam();
  254. annotHandlerEventArgs.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE;
  255. byte[] LineColor = new byte[] { squareData.BorderColor.R, squareData.BorderColor.G, squareData.BorderColor.B };
  256. (annotHandlerEventArgs as SquareParam).LineColor = LineColor;
  257. if(squareData.FillColor!=Colors.Transparent)
  258. {
  259. byte[] FillColor = new byte[] { squareData.FillColor.R, squareData.FillColor.G, squareData.FillColor.B };
  260. (annotHandlerEventArgs as SquareParam).BgColor = FillColor;
  261. (annotHandlerEventArgs as SquareParam).HasBgColor = true;
  262. }
  263. (annotHandlerEventArgs as SquareParam).LineWidth = squareData.Thickness;
  264. (annotHandlerEventArgs as SquareParam).Transparency = Convert.ToByte(squareData.Opacity * 255);
  265. ParamConverter.ParseDashStyle(squareData.DashStyle, out float[] LineDash, out C_BORDER_STYLE BorderStyle);
  266. (annotHandlerEventArgs as SquareParam).LineDash = LineDash;
  267. (annotHandlerEventArgs as SquareParam).BorderStyle = BorderStyle;
  268. (annotHandlerEventArgs as SquareParam).Author = squareData.Author;
  269. (annotHandlerEventArgs as SquareParam).Content = squareData.Note;
  270. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE);
  271. }
  272. break;
  273. case CPDFAnnotationType.Circle:
  274. {
  275. CPDFShapeData cicleData = pdfAnnotationData as CPDFShapeData;
  276. annotHandlerEventArgs = new CircleParam();
  277. annotHandlerEventArgs.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE;
  278. byte[] LineColor = new byte[] { cicleData.BorderColor.R, cicleData.BorderColor.G, cicleData.BorderColor.B };
  279. (annotHandlerEventArgs as CircleParam).LineColor = LineColor;
  280. if(cicleData.FillColor!=Colors.Transparent)
  281. {
  282. byte[] BgColor = new byte[] { cicleData.FillColor.R, cicleData.FillColor.G, cicleData.FillColor.B };
  283. (annotHandlerEventArgs as CircleParam).BgColor = BgColor;
  284. (annotHandlerEventArgs as CircleParam).HasBgColor=true;
  285. }
  286. (annotHandlerEventArgs as CircleParam).LineWidth = cicleData.Thickness;
  287. (annotHandlerEventArgs as CircleParam).Transparency = Convert.ToByte(cicleData.Opacity * 255);
  288. ParamConverter.ParseDashStyle(cicleData.DashStyle, out float[] LineDash, out C_BORDER_STYLE BorderStyle);
  289. (annotHandlerEventArgs as CircleParam).LineDash = LineDash;
  290. (annotHandlerEventArgs as CircleParam).BorderStyle = BorderStyle;
  291. (annotHandlerEventArgs as CircleParam).Author = cicleData.Author;
  292. (annotHandlerEventArgs as CircleParam).Content = cicleData.Note;
  293. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE);
  294. }
  295. break;
  296. case CPDFAnnotationType.Arrow:
  297. case CPDFAnnotationType.Line:
  298. {
  299. CPDFLineShapeData lineData = pdfAnnotationData as CPDFLineShapeData;
  300. annotHandlerEventArgs = new LineParam();
  301. annotHandlerEventArgs.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_LINE;
  302. byte[] LineColor = new byte[] { lineData.BorderColor.R, lineData.BorderColor.G, lineData.BorderColor.B };
  303. (annotHandlerEventArgs as LineParam).LineColor = LineColor;
  304. (annotHandlerEventArgs as LineParam).LineWidth = lineData.Thickness;
  305. (annotHandlerEventArgs as LineParam).Transparency = Convert.ToByte(lineData.Opacity * 255);
  306. ParamConverter.ParseDashStyle(lineData.DashStyle, out float[] LineDash, out C_BORDER_STYLE BorderStyle);
  307. (annotHandlerEventArgs as LineParam).LineDash = LineDash;
  308. (annotHandlerEventArgs as LineParam).BorderStyle = BorderStyle;
  309. (annotHandlerEventArgs as LineParam).HeadLineType = lineData.LineType.HeadLineType;
  310. (annotHandlerEventArgs as LineParam).TailLineType = lineData.LineType.TailLineType;
  311. (annotHandlerEventArgs as LineParam).Author = lineData.Author;
  312. (annotHandlerEventArgs as LineParam).Content = lineData.Note;
  313. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_LINE);
  314. }
  315. break;
  316. case CPDFAnnotationType.Note:
  317. {
  318. CPDFNoteData noteData = pdfAnnotationData as CPDFNoteData;
  319. annotHandlerEventArgs = new StickyNoteParam();
  320. annotHandlerEventArgs.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_TEXT;
  321. byte[] StickyNoteColor = new byte[] { noteData.BorderColor.R, noteData.BorderColor.G, noteData.BorderColor.B };
  322. (annotHandlerEventArgs as StickyNoteParam).StickyNoteColor = StickyNoteColor;
  323. (annotHandlerEventArgs as StickyNoteParam).Content = noteData.Note;
  324. (annotHandlerEventArgs as StickyNoteParam).Transparency = 1;
  325. (annotHandlerEventArgs as StickyNoteParam).Author = noteData.Author;
  326. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_TEXT);
  327. }
  328. break;
  329. case CPDFAnnotationType.Freehand:
  330. {
  331. CPDFFreehandData freehandData = pdfAnnotationData as CPDFFreehandData;
  332. annotHandlerEventArgs = new InkParam();
  333. annotHandlerEventArgs.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_INK;
  334. byte[] LineColor = new byte[] { freehandData.BorderColor.R, freehandData.BorderColor.G, freehandData.BorderColor.B };
  335. (annotHandlerEventArgs as InkParam).InkColor = LineColor;
  336. (annotHandlerEventArgs as InkParam).Thickness = freehandData.Thickness;
  337. (annotHandlerEventArgs as InkParam).Transparency = Convert.ToByte(freehandData.Opacity * 255);
  338. (annotHandlerEventArgs as InkParam).Content = freehandData.Note;
  339. (annotHandlerEventArgs as InkParam).Author = freehandData.Author;
  340. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_INK);
  341. }
  342. break;
  343. case CPDFAnnotationType.FreeText:
  344. {
  345. CPDFFreeTextData freeTextData = pdfAnnotationData as CPDFFreeTextData;
  346. annotHandlerEventArgs = new FreeTextParam();
  347. annotHandlerEventArgs.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_FREETEXT;
  348. (annotHandlerEventArgs as FreeTextParam).Transparency = Convert.ToByte(freeTextData.Opacity * 255);
  349. (annotHandlerEventArgs as FreeTextParam).FontName = freeTextData.FontFamily.ToString();
  350. byte[] FontColor = new byte[] { freeTextData.BorderColor.R, freeTextData.BorderColor.G, freeTextData.BorderColor.B };
  351. (annotHandlerEventArgs as FreeTextParam).FontColor = FontColor;
  352. (annotHandlerEventArgs as FreeTextParam).IsBold = freeTextData.IsBold;
  353. (annotHandlerEventArgs as FreeTextParam).IsItalic = freeTextData.IsItalic;
  354. (annotHandlerEventArgs as FreeTextParam).FontSize = freeTextData.FontSize;
  355. switch (freeTextData.TextAlignment)
  356. {
  357. case TextAlignment.Left:
  358. (annotHandlerEventArgs as FreeTextParam).Alignment = C_TEXT_ALIGNMENT.ALIGNMENT_LEFT;
  359. break;
  360. case TextAlignment.Right:
  361. (annotHandlerEventArgs as FreeTextParam).Alignment = C_TEXT_ALIGNMENT.ALIGNMENT_RIGHT;
  362. break;
  363. case TextAlignment.Center:
  364. (annotHandlerEventArgs as FreeTextParam).Alignment = C_TEXT_ALIGNMENT.ALIGNMENT_CENTER;
  365. break;
  366. default:
  367. break;
  368. }
  369. (annotHandlerEventArgs as FreeTextParam).Content = freeTextData.Note;
  370. (annotHandlerEventArgs as FreeTextParam).Author = freeTextData.Author;
  371. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_FREETEXT);
  372. }
  373. break;
  374. case CPDFAnnotationType.Stamp:
  375. {
  376. StampParam stampParam = new StampParam();
  377. annotHandlerEventArgs.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_STAMP;
  378. CPDFStampData stampData = pdfAnnotationData as CPDFStampData;
  379. SetStamp(ref stampParam, stampData);
  380. annotHandlerEventArgs = stampParam;
  381. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_STAMP);
  382. }
  383. break;
  384. case CPDFAnnotationType.Signature:
  385. AnnotParam signatureParam = new AnnotParam();
  386. CPDFSignatureData SignatureData = pdfAnnotationData as CPDFSignatureData;
  387. SetSignature(ref signatureParam, SignatureData);
  388. annotHandlerEventArgs = signatureParam;
  389. break;
  390. case CPDFAnnotationType.Link:
  391. if (annotHandlerEventArgs != null)
  392. {
  393. annotHandlerEventArgs.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_LINK;
  394. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_LINK);
  395. }
  396. break;
  397. case CPDFAnnotationType.Unknow:
  398. pdfViewerControl.PDFToolManager.SetToolType(ToolType.Pan);
  399. return;
  400. default:
  401. break;
  402. }
  403. pdfViewerControl.PDFToolManager.SetToolType(ToolType.CreateAnnot);
  404. DefaultSettingParam defaultSettingParam = pdfViewerControl.PDFViewTool.GetDefaultSettingParam();
  405. defaultSettingParam.SetAnnotParam(annotHandlerEventArgs);
  406. }
  407. public void SetSignature(ref AnnotParam annotParam, CPDFSignatureData stamp)
  408. {
  409. switch (stamp.Type)
  410. {
  411. case SignatureType.TextType:
  412. case SignatureType.ImageType:
  413. {
  414. annotParam = new StampParam();
  415. annotParam.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_STAMP;
  416. (annotParam as StampParam).Transparency = 1;
  417. (annotParam as StampParam).StampType = C_STAMP_TYPE.IMAGE_STAMP;
  418. if (!string.IsNullOrEmpty(stamp.SourcePath))
  419. {
  420. BitmapImage image = new BitmapImage(new Uri(stamp.SourcePath));
  421. PngBitmapEncoder encoder = new PngBitmapEncoder();
  422. encoder.Frames.Add(BitmapFrame.Create(image));
  423. MemoryStream memoryStream = new MemoryStream();
  424. encoder.Save(memoryStream);
  425. (annotParam as StampParam).ImageStream = memoryStream;
  426. }
  427. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_STAMP);
  428. }
  429. break;
  430. case SignatureType.Drawing:
  431. {
  432. annotParam = new InkParam();
  433. annotParam.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_INK;
  434. List<List<Point>> RawPointList = GetPoints(stamp.DrawingPath);
  435. List<CPoint> linqList = new List<CPoint>();
  436. if (RawPointList != null && RawPointList.Count > 0)
  437. {
  438. List<List<CPoint>> inkPath = new List<List<CPoint>>();
  439. foreach (List<Point> inkPoints in RawPointList)
  440. {
  441. List<CPoint> ink = new List<CPoint>();
  442. foreach (Point point in inkPoints)
  443. {
  444. ink.Add(new CPoint((float)point.X, (float)point.Y));
  445. linqList.Add(new CPoint((float)point.X, (float)point.Y));
  446. }
  447. if (ink.Count > 0)
  448. {
  449. inkPath.Add(ink);
  450. }
  451. }
  452. if (inkPath.Count > 0)
  453. {
  454. (annotParam as InkParam).InkPath = inkPath;
  455. }
  456. }
  457. (annotParam as InkParam).Thickness = stamp.inkThickness;
  458. byte[] InkColor = new byte[] { stamp.inkColor.R, stamp.inkColor.G, stamp.inkColor.B };
  459. (annotParam as InkParam).InkColor = InkColor;
  460. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_INK);
  461. }
  462. break;
  463. default:
  464. break;
  465. }
  466. }
  467. private List<List<Point>> GetPoints(string Path)
  468. {
  469. StrokeCollection Strokes;
  470. List<List<Point>> RawPointList = new List<List<Point>>();
  471. using (FileStream strokeStream = File.OpenRead(Path))
  472. {
  473. Strokes = new StrokeCollection(strokeStream);
  474. }
  475. for (int kk = 0; kk < Strokes.Count; kk++)
  476. {
  477. List<Point> p = new List<Point>();
  478. RawPointList.Add(p);
  479. for (int gg = 0; gg < Strokes[kk].StylusPoints.Count; gg++)
  480. {
  481. var point = Strokes[kk].StylusPoints[gg].ToPoint();
  482. if (point.X >= 0 && point.Y >= 0)
  483. RawPointList[kk].Add(point);
  484. }
  485. }
  486. return RawPointList;
  487. }
  488. private void SetStamp(ref StampParam stampParam, CPDFStampData stamp)
  489. {
  490. stampParam.StampText = stamp.StampText;
  491. stampParam.Author = stamp.Author;
  492. stampParam.Transparency = Convert.ToByte(stamp.Opacity * 255);
  493. stampParam.DateText = stamp.StampTextDate;
  494. stampParam.TextStampColor = stamp.TextColor;
  495. stampParam.TextStampShape = stamp.TextSharp;
  496. if (!string.IsNullOrEmpty(stamp.SourcePath))
  497. {
  498. BitmapImage image = new BitmapImage(new Uri(stamp.SourcePath));
  499. PngBitmapEncoder encoder = new PngBitmapEncoder();
  500. encoder.Frames.Add(BitmapFrame.Create(image));
  501. MemoryStream memoryStream = new MemoryStream();
  502. encoder.Save(memoryStream);
  503. stampParam.ImageStream = memoryStream;
  504. }
  505. else
  506. {
  507. var i = pdfStampUI.CustomStampList.IndexOf(stamp);
  508. Settings.Default.CustomStampList.RemoveAt(i);
  509. Settings.Default.Save();
  510. pdfStampUI.LoadSettings();
  511. return;
  512. }
  513. stampParam.StampType = stamp.Type;
  514. }
  515. public void AnnotationCancel()
  516. {
  517. this.pdfViewerControl.PDFToolManager.SetToolType(ToolType.Pan);
  518. ClearPanel();
  519. }
  520. private void CPDFAnnotationControl_PropertyChanged(object sender, CPDFAnnotationData e)
  521. {
  522. SetAnnotationProperty(e);
  523. }
  524. public void InitAnnotationPanel(CPDFAnnotationType annotationType)
  525. {
  526. switch (annotationType)
  527. {
  528. case CPDFAnnotationType.Highlight:
  529. if (pdfHighlightUI == null)
  530. {
  531. pdfHighlightUI = new CPDFMarkupUI();
  532. }
  533. annotationPanel = pdfHighlightUI;
  534. (annotationPanel as CPDFMarkupUI).InitWithAnnotationType(annotationType);
  535. break;
  536. case CPDFAnnotationType.Underline:
  537. if (pdfUnderlineUI == null)
  538. {
  539. pdfUnderlineUI = new CPDFMarkupUI();
  540. }
  541. annotationPanel = pdfUnderlineUI;
  542. (annotationPanel as CPDFMarkupUI).InitWithAnnotationType(annotationType);
  543. break;
  544. case CPDFAnnotationType.Strikeout:
  545. if (pdfStrikeoutUI == null)
  546. {
  547. pdfStrikeoutUI = new CPDFMarkupUI();
  548. }
  549. annotationPanel = pdfStrikeoutUI;
  550. (annotationPanel as CPDFMarkupUI).InitWithAnnotationType(annotationType);
  551. break;
  552. case CPDFAnnotationType.Squiggly:
  553. if (pdfSquigglyUI == null)
  554. {
  555. pdfSquigglyUI = new CPDFMarkupUI();
  556. }
  557. annotationPanel = pdfSquigglyUI;
  558. (annotationPanel as CPDFMarkupUI).InitWithAnnotationType(annotationType);
  559. break;
  560. case CPDFAnnotationType.Square:
  561. if (pdfSquareUI == null)
  562. {
  563. pdfSquareUI = new CPDFShapeUI();
  564. }
  565. annotationPanel = pdfSquareUI;
  566. (annotationPanel as CPDFShapeUI).InitWithAnnotationType(annotationType);
  567. break;
  568. case CPDFAnnotationType.Circle:
  569. if (pdfCircleUI == null)
  570. {
  571. pdfCircleUI = new CPDFShapeUI();
  572. }
  573. annotationPanel = pdfCircleUI;
  574. (annotationPanel as CPDFShapeUI).InitWithAnnotationType(annotationType);
  575. break;
  576. case CPDFAnnotationType.Arrow:
  577. if (pdfArrowUI == null)
  578. {
  579. pdfArrowUI = new CPDFShapeUI();
  580. }
  581. annotationPanel = pdfArrowUI;
  582. (annotationPanel as CPDFShapeUI).InitWithAnnotationType(annotationType);
  583. break;
  584. case CPDFAnnotationType.Line:
  585. if (pdfLineUI == null)
  586. {
  587. pdfLineUI = new CPDFShapeUI();
  588. }
  589. annotationPanel = pdfLineUI;
  590. (annotationPanel as CPDFShapeUI).InitWithAnnotationType(annotationType);
  591. break;
  592. case CPDFAnnotationType.Freehand:
  593. if (pdfFreehandUI == null)
  594. {
  595. pdfFreehandUI = new CPDFFreehandUI();
  596. pdfFreehandUI.EraseClickHandler += PdfFreehandUI_EraseClickHandler;
  597. pdfFreehandUI.EraseChangeHandler += PdfFreehandUI_EraseChangeHandler;
  598. }
  599. annotationPanel = pdfFreehandUI;
  600. break;
  601. case CPDFAnnotationType.FreeText:
  602. if (pdfFreeTextUI == null)
  603. {
  604. pdfFreeTextUI = new CPDFFreeTextUI();
  605. }
  606. annotationPanel = pdfFreeTextUI;
  607. break;
  608. case CPDFAnnotationType.Note:
  609. if (pdfNoteUI == null)
  610. {
  611. pdfNoteUI = new CPDFNoteUI();
  612. }
  613. annotationPanel = pdfNoteUI;
  614. break;
  615. case CPDFAnnotationType.Stamp:
  616. if (pdfStampUI == null)
  617. {
  618. pdfStampUI = new CPDFStampUI();
  619. }
  620. annotationPanel = pdfStampUI;
  621. break;
  622. case CPDFAnnotationType.Signature:
  623. if (pdfSignatureUI == null)
  624. {
  625. pdfSignatureUI = new CPDFSignatureUI();
  626. }
  627. annotationPanel = pdfSignatureUI;
  628. break;
  629. case CPDFAnnotationType.Link:
  630. if (pdfLinkUI == null)
  631. {
  632. pdfLinkUI = new CPDFLinkUI();
  633. }
  634. LinkParam linkAnnotArgs = new LinkParam();
  635. if (this.pdfViewerControl != null && pdfViewerControl.PDFViewTool != null && pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument() != null)
  636. {
  637. pdfViewerControl.PDFToolManager.SetToolType(ToolType.CreateAnnot);
  638. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_LINK);
  639. pdfLinkUI.InitLinkAnnotArgs(linkAnnotArgs, pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument().PageCount);
  640. }
  641. annotationPanel = pdfLinkUI;
  642. break;
  643. case CPDFAnnotationType.Audio:
  644. //SoundAnnotArgs soundArgs = new SoundAnnotArgs();
  645. //OpenFileDialog openAudioDialog = new OpenFileDialog();
  646. //openAudioDialog.Filter = "Wave Files(*.wav)|*.wav|All Files(*.*;)|*.*;";
  647. //if (openAudioDialog.ShowDialog() == true)
  648. //{
  649. // soundArgs.SoundFilePath = openAudioDialog.FileName;
  650. // this.pdfViewerControl.SetMouseMode(MouseModes.AnnotCreate);
  651. // pdfViewerControl.SetToolParam(soundArgs);
  652. //}
  653. //else
  654. //{
  655. // this.pdfViewerControl.SetMouseMode(MouseModes.PanTool);
  656. // ClearAnnotationBar?.Invoke(this, EventArgs.Empty);
  657. //}
  658. ClearPanel();
  659. break;
  660. case CPDFAnnotationType.Image:
  661. //StampAnnotArgs stampArgs = new StampAnnotArgs();
  662. //stampArgs.Opacity = 1;
  663. //stampArgs.Type = StampType.IMAGE_STAMP;
  664. //OpenFileDialog openFileDialog = new OpenFileDialog();
  665. //openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
  666. //if (openFileDialog.ShowDialog() == true)
  667. //{
  668. // stampArgs.ImagePath = openFileDialog.FileName;
  669. // this.pdfViewerControl?.SetMouseMode(MouseModes.AnnotCreate);
  670. // this.pdfViewerControl?.SetToolParam(stampArgs);
  671. //}
  672. //else
  673. //{
  674. // this.pdfViewerControl.SetMouseMode(MouseModes.PanTool);
  675. //}
  676. //ClearAnnotationBar?.Invoke(this, EventArgs.Empty);
  677. ClearPanel();
  678. break;
  679. default:
  680. break;
  681. }
  682. }
  683. private void PdfFreehandUI_EraseChangeHandler(object sender, double e)
  684. {
  685. //if (pdfViewerControl != null && eraseArgs != null)
  686. //{
  687. // eraseArgs.Thickness = e;
  688. //}
  689. }
  690. private void PdfFreehandUI_EraseClickHandler(object sender, bool e)
  691. {
  692. //if (pdfViewerControl != null)
  693. //{
  694. // CPDFFreehandUI freehandUI = sender as CPDFFreehandUI;
  695. // if (e)
  696. // {
  697. // annotArgs = pdfViewerControl.ToolManager.CurrentAnnotArgs;
  698. // eraseArgs = new EraseArgs();
  699. // eraseArgs.UIBorderColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
  700. // eraseArgs.UIFillColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
  701. // if (freehandUI != null)
  702. // {
  703. // eraseArgs.Thickness = freehandUI.GetEraseThickness();
  704. // }
  705. // else
  706. // {
  707. // eraseArgs.Thickness = 1;
  708. // }
  709. // disableClean = true;
  710. // pdfViewerControl.PDFToolManager.SetToolType(ToolType.CreateAnnot);
  711. // pdfViewerControl.SetToolParam(eraseArgs);
  712. // disableClean = false;
  713. // EmptyMessage.Visibility = Visibility.Collapsed;
  714. // }
  715. // else
  716. // {
  717. // pdfViewerControl.PDFToolManager.SetToolType(ToolType.CreateAnnot);
  718. // FreehandAnnotArgs freehandAnnotArgs = annotArgs as FreehandAnnotArgs;
  719. // if (freehandAnnotArgs == null)
  720. // {
  721. // freehandAnnotArgs = new FreehandAnnotArgs();
  722. // freehandAnnotArgs.InkColor = Colors.Red;
  723. // freehandAnnotArgs.Transparency = 1;
  724. // freehandAnnotArgs.LineWidth = 1;
  725. // annotArgs = freehandAnnotArgs;
  726. // }
  727. // if (freehandUI != null)
  728. // {
  729. // freehandUI.PropertyChanged -= CPDFAnnotationControl_PropertyChanged;
  730. // Dictionary<AnnotAttrib, object> attribDict = new Dictionary<AnnotAttrib, object>();
  731. // attribDict[AnnotAttrib.Color] = freehandAnnotArgs.InkColor;
  732. // attribDict[AnnotAttrib.Transparency] = freehandAnnotArgs.Transparency;
  733. // attribDict[AnnotAttrib.Thickness] = freehandAnnotArgs.LineWidth;
  734. // attribDict[AnnotAttrib.NoteText] = freehandAnnotArgs.Content;
  735. // AnnotAttribEvent annotEvent = AnnotAttribEvent.GetAnnotAttribEvent(freehandAnnotArgs, attribDict);
  736. // freehandUI.SetPresentAnnotAttrib(annotEvent);
  737. // freehandUI.PropertyChanged += CPDFAnnotationControl_PropertyChanged;
  738. // freehandUI.ClearAnnotAttribEvent();
  739. // }
  740. // pdfViewerControl.SetToolParam(freehandAnnotArgs);
  741. // }
  742. //}
  743. }
  744. public void CreatTempAnnotationPanel(BaseAnnot baseAnnot)
  745. {
  746. switch (baseAnnot.CurrentType)
  747. {
  748. case C_ANNOTATION_TYPE.C_ANNOTATION_HIGHLIGHT:
  749. {
  750. tempAnnotationPanel = new CPDFMarkupUI();
  751. (tempAnnotationPanel as CPDFMarkupUI).InitWithAnnotationType(CPDFAnnotationType.Highlight);
  752. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  753. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  754. baseAnnot.GetAnnotData().PageIndex,
  755. baseAnnot.GetAnnotData().Annot);
  756. (tempAnnotationPanel as CPDFMarkupUI).SetPresentAnnotAttrib(annotParam, baseAnnot.GetAnnotData().Annot as CPDFMarkupAnnotation, pdfViewerControl);
  757. }
  758. break;
  759. case C_ANNOTATION_TYPE.C_ANNOTATION_UNDERLINE:
  760. {
  761. tempAnnotationPanel = new CPDFMarkupUI();
  762. (tempAnnotationPanel as CPDFMarkupUI).InitWithAnnotationType(CPDFAnnotationType.Underline);
  763. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  764. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  765. baseAnnot.GetAnnotData().PageIndex,
  766. baseAnnot.GetAnnotData().Annot);
  767. (tempAnnotationPanel as CPDFMarkupUI).SetPresentAnnotAttrib(annotParam, baseAnnot.GetAnnotData().Annot as CPDFMarkupAnnotation, pdfViewerControl);
  768. }
  769. break;
  770. case C_ANNOTATION_TYPE.C_ANNOTATION_STRIKEOUT:
  771. {
  772. tempAnnotationPanel = new CPDFMarkupUI();
  773. (tempAnnotationPanel as CPDFMarkupUI).InitWithAnnotationType(CPDFAnnotationType.Strikeout);
  774. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  775. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  776. baseAnnot.GetAnnotData().PageIndex,
  777. baseAnnot.GetAnnotData().Annot);
  778. (tempAnnotationPanel as CPDFMarkupUI).SetPresentAnnotAttrib(annotParam, baseAnnot.GetAnnotData().Annot as CPDFMarkupAnnotation, pdfViewerControl);
  779. }
  780. break;
  781. case C_ANNOTATION_TYPE.C_ANNOTATION_SQUIGGLY:
  782. {
  783. tempAnnotationPanel = new CPDFMarkupUI();
  784. (tempAnnotationPanel as CPDFMarkupUI).InitWithAnnotationType(CPDFAnnotationType.Squiggly);
  785. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  786. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  787. baseAnnot.GetAnnotData().PageIndex,
  788. baseAnnot.GetAnnotData().Annot);
  789. (tempAnnotationPanel as CPDFMarkupUI).SetPresentAnnotAttrib(annotParam, baseAnnot.GetAnnotData().Annot as CPDFMarkupAnnotation, pdfViewerControl);
  790. }
  791. break;
  792. case C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE:
  793. {
  794. tempAnnotationPanel = new CPDFShapeUI();
  795. (tempAnnotationPanel as CPDFShapeUI).InitWithAnnotationType(CPDFAnnotationType.Square);
  796. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  797. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  798. baseAnnot.GetAnnotData().PageIndex,
  799. baseAnnot.GetAnnotData().Annot);
  800. (tempAnnotationPanel as CPDFShapeUI).SetPresentAnnotAttrib(annotParam, baseAnnot.GetAnnotData().Annot, pdfViewerControl);
  801. }
  802. break;
  803. case C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE:
  804. {
  805. tempAnnotationPanel = new CPDFShapeUI();
  806. (tempAnnotationPanel as CPDFShapeUI).InitWithAnnotationType(CPDFAnnotationType.Circle);
  807. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  808. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  809. baseAnnot.GetAnnotData().PageIndex,
  810. baseAnnot.GetAnnotData().Annot);
  811. (tempAnnotationPanel as CPDFShapeUI).SetPresentAnnotAttrib(annotParam, baseAnnot.GetAnnotData().Annot, pdfViewerControl);
  812. }
  813. break;
  814. case C_ANNOTATION_TYPE.C_ANNOTATION_LINE:
  815. {
  816. tempAnnotationPanel = new CPDFShapeUI();
  817. (tempAnnotationPanel as CPDFShapeUI).InitWithAnnotationType(CPDFAnnotationType.Line);
  818. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  819. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  820. baseAnnot.GetAnnotData().PageIndex,
  821. baseAnnot.GetAnnotData().Annot);
  822. (tempAnnotationPanel as CPDFShapeUI).SetPresentAnnotAttrib(annotParam, baseAnnot.GetAnnotData().Annot, pdfViewerControl);
  823. }
  824. break;
  825. case C_ANNOTATION_TYPE.C_ANNOTATION_INK:
  826. {
  827. CPDFFreehandUI tempFreehandPanel = new CPDFFreehandUI();
  828. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  829. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  830. baseAnnot.GetAnnotData().PageIndex,
  831. baseAnnot.GetAnnotData().Annot);
  832. tempFreehandPanel.SetPresentAnnotAttrib(annotParam, baseAnnot.GetAnnotData().Annot, pdfViewerControl.PDFToolManager.GetDocument(), pdfViewerControl);
  833. tempFreehandPanel.EraseClickHandler += PdfFreehandUI_EraseClickHandler;
  834. tempFreehandPanel.EraseChangeHandler += PdfFreehandUI_EraseChangeHandler;
  835. tempAnnotationPanel = tempFreehandPanel;
  836. }
  837. break;
  838. case C_ANNOTATION_TYPE.C_ANNOTATION_FREETEXT:
  839. {
  840. tempAnnotationPanel = new CPDFFreeTextUI();
  841. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  842. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  843. baseAnnot.GetAnnotData().PageIndex,
  844. baseAnnot.GetAnnotData().Annot);
  845. (tempAnnotationPanel as CPDFFreeTextUI).SetPresentAnnotAttrib(annotParam as FreeTextParam, baseAnnot.GetAnnotData().Annot as CPDFFreeTextAnnotation, pdfViewerControl);
  846. }
  847. break;
  848. case C_ANNOTATION_TYPE.C_ANNOTATION_TEXT:
  849. {
  850. tempAnnotationPanel = new CPDFNoteUI();
  851. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  852. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  853. baseAnnot.GetAnnotData().PageIndex,
  854. baseAnnot.GetAnnotData().Annot);
  855. (tempAnnotationPanel as CPDFNoteUI).SetPresentAnnotAttrib(annotParam as StickyNoteParam, baseAnnot.GetAnnotData().Annot as CPDFTextAnnotation, pdfViewerControl);
  856. }
  857. break;
  858. case C_ANNOTATION_TYPE.C_ANNOTATION_STAMP:
  859. {
  860. tempAnnotationPanel = new CPDFTempStampUI();
  861. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  862. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  863. baseAnnot.GetAnnotData().PageIndex,
  864. baseAnnot.GetAnnotData().Annot);
  865. (tempAnnotationPanel as CPDFTempStampUI).SetPresentAnnotAttrib(annotParam as StampParam , baseAnnot.GetAnnotData().Annot as CPDFStampAnnotation , pdfViewerControl.PDFToolManager.GetDocument(), pdfViewerControl);
  866. }
  867. break;
  868. case C_ANNOTATION_TYPE.C_ANNOTATION_LINK:
  869. {
  870. tempAnnotationPanel = new CPDFLinkUI();
  871. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  872. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  873. baseAnnot.GetAnnotData().PageIndex,
  874. baseAnnot.GetAnnotData().Annot);
  875. (tempAnnotationPanel as CPDFLinkUI).SetPresentAnnotAttrib(annotParam as LinkParam, baseAnnot.GetAnnotData().Annot as CPDFLinkAnnotation, pdfViewerControl, pdfViewerControl.PDFToolManager.GetDocument().PageCount);
  876. }
  877. break;
  878. case C_ANNOTATION_TYPE.C_ANNOTATION_SOUND:
  879. tempAnnotationPanel = null;
  880. break;
  881. default:
  882. break;
  883. }
  884. }
  885. public void LoadAnnotationPanel(CPDFAnnotationType annotationType)
  886. {
  887. this.pdfViewerControl.PDFToolManager.SetToolType(ToolType.Pan);
  888. currentAnnotationType = annotationType;
  889. annotationPanel = GetAnnotationPanel();
  890. InitAnnotationPanel(annotationType);
  891. ShowCurrentAnnotPanel();
  892. }
  893. private void ShowCurrentAnnotPanel()
  894. {
  895. if (annotationPanel != null)
  896. {
  897. if (annotationPanel is CPDFFreehandUI)
  898. {
  899. (annotationPanel as CPDFFreehandUI)?.SetEraseCheck(false);
  900. }
  901. SetAnnotationPanel(annotationPanel);
  902. ExpandPanel();
  903. ChangeAnnotationData();
  904. EmptyMessage.Visibility = Visibility.Collapsed;
  905. }
  906. else
  907. {
  908. EmptyMessage.Visibility = Visibility.Visible;
  909. SetAnnotationPanel(null);
  910. if (pdfViewerControl != null)
  911. {
  912. EmptyMessage.Visibility = Visibility.Collapsed;
  913. }
  914. }
  915. }
  916. private void ShowTempAnnotPanel()
  917. {
  918. BaseAnnot baseAnnot = pdfViewerControl.PDFToolManager.GetCacheHitTestAnnot();
  919. if (baseAnnot != null)
  920. {
  921. CreatTempAnnotationPanel(baseAnnot);
  922. SetAnnotationPanel(tempAnnotationPanel);
  923. ExpandPanel();
  924. if (tempAnnotationPanel != null)
  925. {
  926. EmptyMessage.Visibility = Visibility.Collapsed;
  927. }
  928. else
  929. {
  930. EmptyMessage.Visibility = Visibility.Visible;
  931. }
  932. }
  933. }
  934. private void PDFToolManager_MouseLeftButtonDownHandler(object sender, MouseEventObject e)
  935. {
  936. SetAnnotEventData();
  937. }
  938. public void ClearPanel()
  939. {
  940. annotationPanel = null;
  941. SetAnnotationPanel(annotationPanel);
  942. EmptyMessage.Visibility = Visibility.Visible;
  943. }
  944. public void SetAnnotEventData()
  945. {
  946. if (pdfViewerControl.PDFToolManager != null)
  947. {
  948. if (pdfViewerControl.PDFToolManager.GetCacheHitTestAnnot() == null && isTempPanel)
  949. {
  950. ShowCurrentAnnotPanel();
  951. isTempPanel = false;
  952. }
  953. else if (pdfViewerControl.PDFToolManager.GetCacheHitTestAnnot() != null)
  954. {
  955. ShowTempAnnotPanel();
  956. isTempPanel = true;
  957. }
  958. }
  959. else
  960. {
  961. if (pdfViewerControl != null && pdfViewerControl.PDFToolManager.GetToolType() == ToolType.CreateAnnot)
  962. {
  963. ShowCurrentAnnotPanel();
  964. isTempPanel = false;
  965. }
  966. else if (annotationPanel is CPDFStampUI && currentAnnotationType == CPDFAnnotationType.Stamp)
  967. {
  968. ShowCurrentAnnotPanel();
  969. }
  970. else if (annotationPanel is CPDFSignatureUI && currentAnnotationType == CPDFAnnotationType.Signature)
  971. {
  972. ShowCurrentAnnotPanel();
  973. }
  974. else if (disableClean == false)
  975. {
  976. ClearPanel();
  977. }
  978. }
  979. }
  980. }
  981. }