CPDFAnnotationControl.xaml.cs 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032
  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 as HighlightParam).HighlightColor = Color;
  200. (annotHandlerEventArgs as HighlightParam).Transparency = Convert.ToByte(highlightData.Opacity * 255);
  201. (annotHandlerEventArgs as HighlightParam).Content = highlightData.Note;
  202. (annotHandlerEventArgs as HighlightParam).Author = highlightData.Author;
  203. (annotHandlerEventArgs as HighlightParam).Locked = highlightData.IsLocked;
  204. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_HIGHLIGHT);
  205. }
  206. break;
  207. case CPDFAnnotationType.Underline:
  208. {
  209. CPDFMarkupData underlineData = pdfAnnotationData as CPDFMarkupData;
  210. annotHandlerEventArgs = new UnderlineParam();
  211. byte[] Color = new byte[] { underlineData.Color.R, underlineData.Color.G, underlineData.Color.B };
  212. (annotHandlerEventArgs as UnderlineParam).UnderlineColor = Color;
  213. (annotHandlerEventArgs as UnderlineParam).Transparency = Convert.ToByte(underlineData.Opacity * 255);
  214. (annotHandlerEventArgs as UnderlineParam).Author = underlineData.Author;
  215. (annotHandlerEventArgs as UnderlineParam).Content = underlineData.Note;
  216. (annotHandlerEventArgs as UnderlineParam).Locked = underlineData.IsLocked;
  217. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_UNDERLINE);
  218. }
  219. break;
  220. case CPDFAnnotationType.Strikeout:
  221. {
  222. CPDFMarkupData strikeoutData = pdfAnnotationData as CPDFMarkupData;
  223. annotHandlerEventArgs = new StrikeoutParam();
  224. byte[] Color = new byte[] { strikeoutData.Color.R, strikeoutData.Color.G, strikeoutData.Color.B };
  225. (annotHandlerEventArgs as StrikeoutParam).StrikeoutColor = Color;
  226. (annotHandlerEventArgs as StrikeoutParam).Transparency = Convert.ToByte(strikeoutData.Opacity * 255);
  227. (annotHandlerEventArgs as StrikeoutParam).Locked = strikeoutData.IsLocked;
  228. (annotHandlerEventArgs as StrikeoutParam).Author = strikeoutData.Author;
  229. (annotHandlerEventArgs as StrikeoutParam).Content = strikeoutData.Note;
  230. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_STRIKEOUT);
  231. }
  232. break;
  233. case CPDFAnnotationType.Squiggly:
  234. {
  235. CPDFMarkupData squigglyData = pdfAnnotationData as CPDFMarkupData;
  236. annotHandlerEventArgs = new SquigglyParam();
  237. byte[] Color = new byte[] { squigglyData.Color.R, squigglyData.Color.G, squigglyData.Color.B };
  238. (annotHandlerEventArgs as SquigglyParam).SquigglyColor = Color;
  239. (annotHandlerEventArgs as SquigglyParam).Transparency = Convert.ToByte(squigglyData.Opacity * 255);
  240. (annotHandlerEventArgs as SquigglyParam).Locked = squigglyData.IsLocked;
  241. (annotHandlerEventArgs as SquigglyParam).Author = squigglyData.Author;
  242. (annotHandlerEventArgs as SquigglyParam).Content = squigglyData.Note;
  243. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_SQUIGGLY);
  244. }
  245. break;
  246. case CPDFAnnotationType.Square:
  247. {
  248. CPDFShapeData squareData = pdfAnnotationData as CPDFShapeData;
  249. annotHandlerEventArgs = new SquareParam();
  250. byte[] LineColor = new byte[] { squareData.BorderColor.R, squareData.BorderColor.G, squareData.BorderColor.B };
  251. (annotHandlerEventArgs as SquareParam).LineColor = LineColor;
  252. byte[] FillColor = new byte[] { squareData.FillColor.R, squareData.FillColor.G, squareData.FillColor.B };
  253. (annotHandlerEventArgs as SquareParam).BgColor = FillColor;
  254. (annotHandlerEventArgs as SquareParam).LineWidth = squareData.Thickness;
  255. (annotHandlerEventArgs as SquareParam).Transparency = Convert.ToByte(squareData.Opacity * 255);
  256. ParamConverter.ParseDashStyle(squareData.DashStyle, out float[] LineDash, out C_BORDER_STYLE BorderStyle);
  257. (annotHandlerEventArgs as SquareParam).LineDash = LineDash;
  258. (annotHandlerEventArgs as SquareParam).BorderStyle = BorderStyle;
  259. (annotHandlerEventArgs as SquareParam).Author = squareData.Author;
  260. (annotHandlerEventArgs as SquareParam).Content = squareData.Note;
  261. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE);
  262. }
  263. break;
  264. case CPDFAnnotationType.Circle:
  265. {
  266. CPDFShapeData cicleData = pdfAnnotationData as CPDFShapeData;
  267. annotHandlerEventArgs = new CircleParam();
  268. byte[] LineColor = new byte[] { cicleData.BorderColor.R, cicleData.BorderColor.G, cicleData.BorderColor.B };
  269. (annotHandlerEventArgs as CircleParam).LineColor = LineColor;
  270. byte[] BgColor = new byte[] { cicleData.FillColor.R, cicleData.FillColor.G, cicleData.FillColor.B };
  271. (annotHandlerEventArgs as CircleParam).BgColor = BgColor;
  272. (annotHandlerEventArgs as CircleParam).LineWidth = cicleData.Thickness;
  273. (annotHandlerEventArgs as CircleParam).Transparency = Convert.ToByte(cicleData.Opacity * 255);
  274. ParamConverter.ParseDashStyle(cicleData.DashStyle, out float[] LineDash, out C_BORDER_STYLE BorderStyle);
  275. (annotHandlerEventArgs as CircleParam).LineDash = LineDash;
  276. (annotHandlerEventArgs as CircleParam).BorderStyle = BorderStyle;
  277. (annotHandlerEventArgs as CircleParam).Author = cicleData.Author;
  278. (annotHandlerEventArgs as CircleParam).Content = cicleData.Note;
  279. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE);
  280. }
  281. break;
  282. case CPDFAnnotationType.Arrow:
  283. case CPDFAnnotationType.Line:
  284. {
  285. CPDFLineShapeData lineData = pdfAnnotationData as CPDFLineShapeData;
  286. annotHandlerEventArgs = new LineParam();
  287. byte[] LineColor = new byte[] { lineData.BorderColor.R, lineData.BorderColor.G, lineData.BorderColor.B };
  288. (annotHandlerEventArgs as LineParam).LineColor = LineColor;
  289. (annotHandlerEventArgs as LineParam).LineWidth = lineData.Thickness;
  290. (annotHandlerEventArgs as LineParam).Transparency = Convert.ToByte(lineData.Opacity * 255);
  291. ParamConverter.ParseDashStyle(lineData.DashStyle, out float[] LineDash, out C_BORDER_STYLE BorderStyle);
  292. (annotHandlerEventArgs as LineParam).LineDash = LineDash;
  293. (annotHandlerEventArgs as LineParam).BorderStyle = BorderStyle;
  294. (annotHandlerEventArgs as LineParam).HeadLineType = lineData.LineType.HeadLineType;
  295. (annotHandlerEventArgs as LineParam).TailLineType = lineData.LineType.TailLineType;
  296. (annotHandlerEventArgs as LineParam).Author = lineData.Author;
  297. (annotHandlerEventArgs as LineParam).Content = lineData.Note;
  298. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_LINE);
  299. }
  300. break;
  301. case CPDFAnnotationType.Note:
  302. {
  303. CPDFNoteData noteData = pdfAnnotationData as CPDFNoteData;
  304. annotHandlerEventArgs = new StickyNoteParam();
  305. byte[] StickyNoteColor = new byte[] { noteData.BorderColor.R, noteData.BorderColor.G, noteData.BorderColor.B };
  306. (annotHandlerEventArgs as StickyNoteParam).StickyNoteColor = StickyNoteColor;
  307. (annotHandlerEventArgs as StickyNoteParam).Content = noteData.Note;
  308. (annotHandlerEventArgs as StickyNoteParam).Transparency = 1;
  309. (annotHandlerEventArgs as StickyNoteParam).Author = noteData.Author;
  310. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_TEXT);
  311. }
  312. break;
  313. case CPDFAnnotationType.Freehand:
  314. {
  315. CPDFFreehandData freehandData = pdfAnnotationData as CPDFFreehandData;
  316. annotHandlerEventArgs = new InkParam();
  317. byte[] LineColor = new byte[] { freehandData.BorderColor.R, freehandData.BorderColor.G, freehandData.BorderColor.B };
  318. (annotHandlerEventArgs as InkParam).InkColor = LineColor;
  319. (annotHandlerEventArgs as InkParam).Thickness = freehandData.Thickness;
  320. (annotHandlerEventArgs as InkParam).Transparency = Convert.ToByte(freehandData.Opacity * 255);
  321. (annotHandlerEventArgs as InkParam).Content = freehandData.Note;
  322. (annotHandlerEventArgs as InkParam).Author = freehandData.Author;
  323. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_INK);
  324. }
  325. break;
  326. case CPDFAnnotationType.FreeText:
  327. {
  328. CPDFFreeTextData freeTextData = pdfAnnotationData as CPDFFreeTextData;
  329. annotHandlerEventArgs = new FreeTextParam();
  330. (annotHandlerEventArgs as FreeTextParam).Transparency = Convert.ToByte(freeTextData.Opacity * 255);
  331. (annotHandlerEventArgs as FreeTextParam).FontName = freeTextData.FontFamily.ToString();
  332. byte[] FontColor = new byte[] { freeTextData.BorderColor.R, freeTextData.BorderColor.G, freeTextData.BorderColor.B };
  333. (annotHandlerEventArgs as FreeTextParam).FontColor = FontColor;
  334. (annotHandlerEventArgs as FreeTextParam).IsBold = freeTextData.IsBold;
  335. (annotHandlerEventArgs as FreeTextParam).IsItalic = freeTextData.IsItalic;
  336. (annotHandlerEventArgs as FreeTextParam).FontSize = freeTextData.FontSize;
  337. switch (freeTextData.TextAlignment)
  338. {
  339. case TextAlignment.Left:
  340. (annotHandlerEventArgs as FreeTextParam).Alignment = C_TEXT_ALIGNMENT.ALIGNMENT_LEFT;
  341. break;
  342. case TextAlignment.Right:
  343. (annotHandlerEventArgs as FreeTextParam).Alignment = C_TEXT_ALIGNMENT.ALIGNMENT_RIGHT;
  344. break;
  345. case TextAlignment.Center:
  346. (annotHandlerEventArgs as FreeTextParam).Alignment = C_TEXT_ALIGNMENT.ALIGNMENT_CENTER;
  347. break;
  348. default:
  349. break;
  350. }
  351. (annotHandlerEventArgs as FreeTextParam).Content = freeTextData.Note;
  352. (annotHandlerEventArgs as FreeTextParam).Author = freeTextData.Author;
  353. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_FREETEXT);
  354. }
  355. break;
  356. case CPDFAnnotationType.Stamp:
  357. {
  358. StampParam stampParam = new StampParam();
  359. CPDFStampData stampData = pdfAnnotationData as CPDFStampData;
  360. SetStamp(ref stampParam, stampData);
  361. annotHandlerEventArgs = stampParam;
  362. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_STAMP);
  363. }
  364. break;
  365. case CPDFAnnotationType.Signature:
  366. AnnotParam signatureParam = new AnnotParam();
  367. CPDFSignatureData SignatureData = pdfAnnotationData as CPDFSignatureData;
  368. SetSignature(ref signatureParam, SignatureData);
  369. annotHandlerEventArgs = signatureParam;
  370. break;
  371. case CPDFAnnotationType.Link:
  372. if (annotHandlerEventArgs != null)
  373. {
  374. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_LINK);
  375. }
  376. break;
  377. case CPDFAnnotationType.Unknow:
  378. pdfViewerControl.PDFToolManager.SetToolType(ToolType.Pan);
  379. return;
  380. default:
  381. break;
  382. }
  383. pdfViewerControl.PDFToolManager.SetToolType(ToolType.CreateAnnot);
  384. DefaultSettingParam defaultSettingParam = pdfViewerControl.PDFViewTool.GetDefaultSettingParam();
  385. }
  386. public void SetSignature(ref AnnotParam annotParam, CPDFSignatureData stamp)
  387. {
  388. switch (stamp.Type)
  389. {
  390. case SignatureType.TextType:
  391. case SignatureType.ImageType:
  392. {
  393. annotParam = new StampParam();
  394. (annotParam as StampParam).Transparency = 1;
  395. (annotParam as StampParam).StampType = C_STAMP_TYPE.IMAGE_STAMP;
  396. if (!string.IsNullOrEmpty(stamp.SourcePath))
  397. {
  398. BitmapImage image = new BitmapImage(new Uri(stamp.SourcePath));
  399. PngBitmapEncoder encoder = new PngBitmapEncoder();
  400. encoder.Frames.Add(BitmapFrame.Create(image));
  401. MemoryStream memoryStream = new MemoryStream();
  402. encoder.Save(memoryStream);
  403. (annotParam as StampParam).ImageStream = memoryStream;
  404. }
  405. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_STAMP);
  406. }
  407. break;
  408. case SignatureType.Drawing:
  409. {
  410. annotParam = new InkParam();
  411. List<List<Point>> RawPointList = GetPoints(stamp.DrawingPath);
  412. List<CPoint> linqList = new List<CPoint>();
  413. if (RawPointList != null && RawPointList.Count > 0)
  414. {
  415. List<List<CPoint>> inkPath = new List<List<CPoint>>();
  416. foreach (List<Point> inkPoints in RawPointList)
  417. {
  418. List<CPoint> ink = new List<CPoint>();
  419. foreach (Point point in inkPoints)
  420. {
  421. ink.Add(new CPoint((float)point.X, (float)point.Y));
  422. linqList.Add(new CPoint((float)point.X, (float)point.Y));
  423. }
  424. if (ink.Count > 0)
  425. {
  426. inkPath.Add(ink);
  427. }
  428. }
  429. if (inkPath.Count > 0)
  430. {
  431. (annotParam as InkParam).InkPath = inkPath;
  432. }
  433. }
  434. (annotParam as InkParam).Thickness = stamp.inkThickness;
  435. byte[] InkColor = new byte[] { stamp.inkColor.R, stamp.inkColor.G, stamp.inkColor.B };
  436. (annotParam as InkParam).InkColor = InkColor;
  437. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_INK);
  438. }
  439. break;
  440. default:
  441. break;
  442. }
  443. }
  444. private List<List<Point>> GetPoints(string Path)
  445. {
  446. StrokeCollection Strokes;
  447. List<List<Point>> RawPointList = new List<List<Point>>();
  448. using (FileStream strokeStream = File.OpenRead(Path))
  449. {
  450. Strokes = new StrokeCollection(strokeStream);
  451. }
  452. for (int kk = 0; kk < Strokes.Count; kk++)
  453. {
  454. List<Point> p = new List<Point>();
  455. RawPointList.Add(p);
  456. for (int gg = 0; gg < Strokes[kk].StylusPoints.Count; gg++)
  457. {
  458. var point = Strokes[kk].StylusPoints[gg].ToPoint();
  459. if (point.X >= 0 && point.Y >= 0)
  460. RawPointList[kk].Add(point);
  461. }
  462. }
  463. return RawPointList;
  464. }
  465. private void SetStamp(ref StampParam stampParam, CPDFStampData stamp)
  466. {
  467. stampParam.StampText = stamp.StampText;
  468. stampParam.Author = stamp.Author;
  469. stampParam.Transparency = Convert.ToByte(stamp.Opacity * 255);
  470. stampParam.DateText = stamp.StampTextDate;
  471. stampParam.TextStampColor = stamp.TextColor;
  472. stampParam.TextStampShape = stamp.TextSharp;
  473. if (!string.IsNullOrEmpty(stamp.SourcePath))
  474. {
  475. BitmapImage image = new BitmapImage(new Uri(stamp.SourcePath));
  476. PngBitmapEncoder encoder = new PngBitmapEncoder();
  477. encoder.Frames.Add(BitmapFrame.Create(image));
  478. MemoryStream memoryStream = new MemoryStream();
  479. encoder.Save(memoryStream);
  480. stampParam.ImageStream = memoryStream;
  481. }
  482. else
  483. {
  484. var i = pdfStampUI.CustomStampList.IndexOf(stamp);
  485. Settings.Default.CustomStampList.RemoveAt(i);
  486. Settings.Default.Save();
  487. pdfStampUI.LoadSettings();
  488. return;
  489. }
  490. stampParam.StampType = stamp.Type;
  491. }
  492. public void AnnotationCancel()
  493. {
  494. this.pdfViewerControl.PDFToolManager.SetToolType(ToolType.Pan);
  495. ClearPanel();
  496. }
  497. private void CPDFAnnotationControl_PropertyChanged(object sender, CPDFAnnotationData e)
  498. {
  499. SetAnnotationProperty(e);
  500. }
  501. public void InitAnnotationPanel(CPDFAnnotationType annotationType)
  502. {
  503. switch (annotationType)
  504. {
  505. case CPDFAnnotationType.Highlight:
  506. if (pdfHighlightUI == null)
  507. {
  508. pdfHighlightUI = new CPDFMarkupUI();
  509. }
  510. annotationPanel = pdfHighlightUI;
  511. (annotationPanel as CPDFMarkupUI).InitWithAnnotationType(annotationType);
  512. break;
  513. case CPDFAnnotationType.Underline:
  514. if (pdfUnderlineUI == null)
  515. {
  516. pdfUnderlineUI = new CPDFMarkupUI();
  517. }
  518. annotationPanel = pdfUnderlineUI;
  519. (annotationPanel as CPDFMarkupUI).InitWithAnnotationType(annotationType);
  520. break;
  521. case CPDFAnnotationType.Strikeout:
  522. if (pdfStrikeoutUI == null)
  523. {
  524. pdfStrikeoutUI = new CPDFMarkupUI();
  525. }
  526. annotationPanel = pdfStrikeoutUI;
  527. (annotationPanel as CPDFMarkupUI).InitWithAnnotationType(annotationType);
  528. break;
  529. case CPDFAnnotationType.Squiggly:
  530. if (pdfSquigglyUI == null)
  531. {
  532. pdfSquigglyUI = new CPDFMarkupUI();
  533. }
  534. annotationPanel = pdfSquigglyUI;
  535. (annotationPanel as CPDFMarkupUI).InitWithAnnotationType(annotationType);
  536. break;
  537. case CPDFAnnotationType.Square:
  538. if (pdfSquareUI == null)
  539. {
  540. pdfSquareUI = new CPDFShapeUI();
  541. }
  542. annotationPanel = pdfSquareUI;
  543. (annotationPanel as CPDFShapeUI).InitWithAnnotationType(annotationType);
  544. break;
  545. case CPDFAnnotationType.Circle:
  546. if (pdfCircleUI == null)
  547. {
  548. pdfCircleUI = new CPDFShapeUI();
  549. }
  550. annotationPanel = pdfCircleUI;
  551. (annotationPanel as CPDFShapeUI).InitWithAnnotationType(annotationType);
  552. break;
  553. case CPDFAnnotationType.Arrow:
  554. if (pdfArrowUI == null)
  555. {
  556. pdfArrowUI = new CPDFShapeUI();
  557. }
  558. annotationPanel = pdfArrowUI;
  559. (annotationPanel as CPDFShapeUI).InitWithAnnotationType(annotationType);
  560. break;
  561. case CPDFAnnotationType.Line:
  562. if (pdfLineUI == null)
  563. {
  564. pdfLineUI = new CPDFShapeUI();
  565. }
  566. annotationPanel = pdfLineUI;
  567. (annotationPanel as CPDFShapeUI).InitWithAnnotationType(annotationType);
  568. break;
  569. case CPDFAnnotationType.Freehand:
  570. if (pdfFreehandUI == null)
  571. {
  572. pdfFreehandUI = new CPDFFreehandUI();
  573. pdfFreehandUI.EraseClickHandler += PdfFreehandUI_EraseClickHandler;
  574. pdfFreehandUI.EraseChangeHandler += PdfFreehandUI_EraseChangeHandler;
  575. }
  576. annotationPanel = pdfFreehandUI;
  577. break;
  578. case CPDFAnnotationType.FreeText:
  579. if (pdfFreeTextUI == null)
  580. {
  581. pdfFreeTextUI = new CPDFFreeTextUI();
  582. }
  583. annotationPanel = pdfFreeTextUI;
  584. break;
  585. case CPDFAnnotationType.Note:
  586. if (pdfNoteUI == null)
  587. {
  588. pdfNoteUI = new CPDFNoteUI();
  589. }
  590. annotationPanel = pdfNoteUI;
  591. break;
  592. case CPDFAnnotationType.Stamp:
  593. if (pdfStampUI == null)
  594. {
  595. pdfStampUI = new CPDFStampUI();
  596. }
  597. annotationPanel = pdfStampUI;
  598. break;
  599. case CPDFAnnotationType.Signature:
  600. if (pdfSignatureUI == null)
  601. {
  602. pdfSignatureUI = new CPDFSignatureUI();
  603. }
  604. annotationPanel = pdfSignatureUI;
  605. break;
  606. case CPDFAnnotationType.Link:
  607. if (pdfLinkUI == null)
  608. {
  609. pdfLinkUI = new CPDFLinkUI();
  610. }
  611. LinkParam linkAnnotArgs = new LinkParam();
  612. if (this.pdfViewerControl != null && pdfViewerControl.PDFViewTool != null && pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument() != null)
  613. {
  614. pdfViewerControl.PDFToolManager.SetToolType(ToolType.CreateAnnot);
  615. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_LINK);
  616. pdfLinkUI.InitLinkAnnotArgs(linkAnnotArgs, pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument().PageCount);
  617. }
  618. annotationPanel = pdfLinkUI;
  619. break;
  620. case CPDFAnnotationType.Audio:
  621. //SoundAnnotArgs soundArgs = new SoundAnnotArgs();
  622. //OpenFileDialog openAudioDialog = new OpenFileDialog();
  623. //openAudioDialog.Filter = "Wave Files(*.wav)|*.wav|All Files(*.*;)|*.*;";
  624. //if (openAudioDialog.ShowDialog() == true)
  625. //{
  626. // soundArgs.SoundFilePath = openAudioDialog.FileName;
  627. // this.pdfViewerControl.SetMouseMode(MouseModes.AnnotCreate);
  628. // pdfViewerControl.SetToolParam(soundArgs);
  629. //}
  630. //else
  631. //{
  632. // this.pdfViewerControl.SetMouseMode(MouseModes.PanTool);
  633. // ClearAnnotationBar?.Invoke(this, EventArgs.Empty);
  634. //}
  635. ClearPanel();
  636. break;
  637. case CPDFAnnotationType.Image:
  638. //StampAnnotArgs stampArgs = new StampAnnotArgs();
  639. //stampArgs.Opacity = 1;
  640. //stampArgs.Type = StampType.IMAGE_STAMP;
  641. //OpenFileDialog openFileDialog = new OpenFileDialog();
  642. //openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
  643. //if (openFileDialog.ShowDialog() == true)
  644. //{
  645. // stampArgs.ImagePath = openFileDialog.FileName;
  646. // this.pdfViewerControl?.SetMouseMode(MouseModes.AnnotCreate);
  647. // this.pdfViewerControl?.SetToolParam(stampArgs);
  648. //}
  649. //else
  650. //{
  651. // this.pdfViewerControl.SetMouseMode(MouseModes.PanTool);
  652. //}
  653. //ClearAnnotationBar?.Invoke(this, EventArgs.Empty);
  654. ClearPanel();
  655. break;
  656. default:
  657. break;
  658. }
  659. }
  660. private void PdfFreehandUI_EraseChangeHandler(object sender, double e)
  661. {
  662. //if (pdfViewerControl != null && eraseArgs != null)
  663. //{
  664. // eraseArgs.Thickness = e;
  665. //}
  666. }
  667. private void PdfFreehandUI_EraseClickHandler(object sender, bool e)
  668. {
  669. //if (pdfViewerControl != null)
  670. //{
  671. // CPDFFreehandUI freehandUI = sender as CPDFFreehandUI;
  672. // if (e)
  673. // {
  674. // annotArgs = pdfViewerControl.ToolManager.CurrentAnnotArgs;
  675. // eraseArgs = new EraseArgs();
  676. // eraseArgs.UIBorderColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
  677. // eraseArgs.UIFillColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
  678. // if (freehandUI != null)
  679. // {
  680. // eraseArgs.Thickness = freehandUI.GetEraseThickness();
  681. // }
  682. // else
  683. // {
  684. // eraseArgs.Thickness = 1;
  685. // }
  686. // disableClean = true;
  687. // pdfViewerControl.PDFToolManager.SetToolType(ToolType.CreateAnnot);
  688. // pdfViewerControl.SetToolParam(eraseArgs);
  689. // disableClean = false;
  690. // EmptyMessage.Visibility = Visibility.Collapsed;
  691. // }
  692. // else
  693. // {
  694. // pdfViewerControl.PDFToolManager.SetToolType(ToolType.CreateAnnot);
  695. // FreehandAnnotArgs freehandAnnotArgs = annotArgs as FreehandAnnotArgs;
  696. // if (freehandAnnotArgs == null)
  697. // {
  698. // freehandAnnotArgs = new FreehandAnnotArgs();
  699. // freehandAnnotArgs.InkColor = Colors.Red;
  700. // freehandAnnotArgs.Transparency = 1;
  701. // freehandAnnotArgs.LineWidth = 1;
  702. // annotArgs = freehandAnnotArgs;
  703. // }
  704. // if (freehandUI != null)
  705. // {
  706. // freehandUI.PropertyChanged -= CPDFAnnotationControl_PropertyChanged;
  707. // Dictionary<AnnotAttrib, object> attribDict = new Dictionary<AnnotAttrib, object>();
  708. // attribDict[AnnotAttrib.Color] = freehandAnnotArgs.InkColor;
  709. // attribDict[AnnotAttrib.Transparency] = freehandAnnotArgs.Transparency;
  710. // attribDict[AnnotAttrib.Thickness] = freehandAnnotArgs.LineWidth;
  711. // attribDict[AnnotAttrib.NoteText] = freehandAnnotArgs.Content;
  712. // AnnotAttribEvent annotEvent = AnnotAttribEvent.GetAnnotAttribEvent(freehandAnnotArgs, attribDict);
  713. // freehandUI.SetPresentAnnotAttrib(annotEvent);
  714. // freehandUI.PropertyChanged += CPDFAnnotationControl_PropertyChanged;
  715. // freehandUI.ClearAnnotAttribEvent();
  716. // }
  717. // pdfViewerControl.SetToolParam(freehandAnnotArgs);
  718. // }
  719. //}
  720. }
  721. public void CreatTempAnnotationPanel(BaseAnnot baseAnnot)
  722. {
  723. switch (baseAnnot.CurrentType)
  724. {
  725. case C_ANNOTATION_TYPE.C_ANNOTATION_HIGHLIGHT:
  726. {
  727. tempAnnotationPanel = new CPDFMarkupUI();
  728. (tempAnnotationPanel as CPDFMarkupUI).InitWithAnnotationType(CPDFAnnotationType.Highlight);
  729. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  730. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  731. baseAnnot.GetAnnotData().PageIndex,
  732. baseAnnot.GetAnnotData().Annot);
  733. (tempAnnotationPanel as CPDFMarkupUI).SetPresentAnnotAttrib(annotParam, baseAnnot.GetAnnotData().Annot as CPDFMarkupAnnotation, pdfViewerControl);
  734. }
  735. break;
  736. case C_ANNOTATION_TYPE.C_ANNOTATION_UNDERLINE:
  737. {
  738. tempAnnotationPanel = new CPDFMarkupUI();
  739. (tempAnnotationPanel as CPDFMarkupUI).InitWithAnnotationType(CPDFAnnotationType.Underline);
  740. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  741. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  742. baseAnnot.GetAnnotData().PageIndex,
  743. baseAnnot.GetAnnotData().Annot);
  744. (tempAnnotationPanel as CPDFMarkupUI).SetPresentAnnotAttrib(annotParam, baseAnnot.GetAnnotData().Annot as CPDFMarkupAnnotation, pdfViewerControl);
  745. }
  746. break;
  747. case C_ANNOTATION_TYPE.C_ANNOTATION_STRIKEOUT:
  748. {
  749. tempAnnotationPanel = new CPDFMarkupUI();
  750. (tempAnnotationPanel as CPDFMarkupUI).InitWithAnnotationType(CPDFAnnotationType.Strikeout);
  751. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  752. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  753. baseAnnot.GetAnnotData().PageIndex,
  754. baseAnnot.GetAnnotData().Annot);
  755. (tempAnnotationPanel as CPDFMarkupUI).SetPresentAnnotAttrib(annotParam, baseAnnot.GetAnnotData().Annot as CPDFMarkupAnnotation, pdfViewerControl);
  756. }
  757. break;
  758. case C_ANNOTATION_TYPE.C_ANNOTATION_SQUIGGLY:
  759. {
  760. tempAnnotationPanel = new CPDFMarkupUI();
  761. (tempAnnotationPanel as CPDFMarkupUI).InitWithAnnotationType(CPDFAnnotationType.Squiggly);
  762. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  763. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  764. baseAnnot.GetAnnotData().PageIndex,
  765. baseAnnot.GetAnnotData().Annot);
  766. (tempAnnotationPanel as CPDFMarkupUI).SetPresentAnnotAttrib(annotParam, baseAnnot.GetAnnotData().Annot as CPDFMarkupAnnotation, pdfViewerControl);
  767. }
  768. break;
  769. case C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE:
  770. {
  771. tempAnnotationPanel = new CPDFShapeUI();
  772. (tempAnnotationPanel as CPDFShapeUI).InitWithAnnotationType(CPDFAnnotationType.Square);
  773. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  774. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  775. baseAnnot.GetAnnotData().PageIndex,
  776. baseAnnot.GetAnnotData().Annot);
  777. (tempAnnotationPanel as CPDFShapeUI).SetPresentAnnotAttrib(annotParam, baseAnnot.GetAnnotData().Annot, pdfViewerControl);
  778. }
  779. break;
  780. case C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE:
  781. {
  782. tempAnnotationPanel = new CPDFShapeUI();
  783. (tempAnnotationPanel as CPDFShapeUI).InitWithAnnotationType(CPDFAnnotationType.Circle);
  784. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  785. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  786. baseAnnot.GetAnnotData().PageIndex,
  787. baseAnnot.GetAnnotData().Annot);
  788. (tempAnnotationPanel as CPDFShapeUI).SetPresentAnnotAttrib(annotParam, baseAnnot.GetAnnotData().Annot, pdfViewerControl);
  789. }
  790. break;
  791. case C_ANNOTATION_TYPE.C_ANNOTATION_LINE:
  792. {
  793. tempAnnotationPanel = new CPDFShapeUI();
  794. (tempAnnotationPanel as CPDFShapeUI).InitWithAnnotationType(CPDFAnnotationType.Line);
  795. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  796. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  797. baseAnnot.GetAnnotData().PageIndex,
  798. baseAnnot.GetAnnotData().Annot);
  799. (tempAnnotationPanel as CPDFShapeUI).SetPresentAnnotAttrib(annotParam, baseAnnot.GetAnnotData().Annot, pdfViewerControl);
  800. }
  801. break;
  802. case C_ANNOTATION_TYPE.C_ANNOTATION_INK:
  803. {
  804. CPDFFreehandUI tempFreehandPanel = new CPDFFreehandUI();
  805. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  806. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  807. baseAnnot.GetAnnotData().PageIndex,
  808. baseAnnot.GetAnnotData().Annot);
  809. tempFreehandPanel.SetPresentAnnotAttrib(annotParam, baseAnnot.GetAnnotData().Annot, pdfViewerControl.PDFToolManager.GetDocument(), pdfViewerControl);
  810. tempFreehandPanel.EraseClickHandler += PdfFreehandUI_EraseClickHandler;
  811. tempFreehandPanel.EraseChangeHandler += PdfFreehandUI_EraseChangeHandler;
  812. tempAnnotationPanel = tempFreehandPanel;
  813. }
  814. break;
  815. case C_ANNOTATION_TYPE.C_ANNOTATION_FREETEXT:
  816. {
  817. tempAnnotationPanel = new CPDFFreeTextUI();
  818. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  819. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  820. baseAnnot.GetAnnotData().PageIndex,
  821. baseAnnot.GetAnnotData().Annot);
  822. (tempAnnotationPanel as CPDFFreeTextUI).SetPresentAnnotAttrib(annotParam as FreeTextParam, baseAnnot.GetAnnotData().Annot as CPDFFreeTextAnnotation, pdfViewerControl);
  823. }
  824. break;
  825. case C_ANNOTATION_TYPE.C_ANNOTATION_TEXT:
  826. {
  827. tempAnnotationPanel = new CPDFNoteUI();
  828. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  829. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  830. baseAnnot.GetAnnotData().PageIndex,
  831. baseAnnot.GetAnnotData().Annot);
  832. (tempAnnotationPanel as CPDFNoteUI).SetPresentAnnotAttrib(annotParam as StickyNoteParam, baseAnnot.GetAnnotData().Annot as CPDFTextAnnotation, pdfViewerControl);
  833. }
  834. break;
  835. case C_ANNOTATION_TYPE.C_ANNOTATION_STAMP:
  836. {
  837. tempAnnotationPanel = new CPDFTempStampUI();
  838. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  839. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  840. baseAnnot.GetAnnotData().PageIndex,
  841. baseAnnot.GetAnnotData().Annot);
  842. (tempAnnotationPanel as CPDFTempStampUI).SetPresentAnnotAttrib(annotParam as StampParam , baseAnnot.GetAnnotData().Annot as CPDFStampAnnotation , pdfViewerControl.PDFToolManager.GetDocument(), pdfViewerControl);
  843. }
  844. break;
  845. case C_ANNOTATION_TYPE.C_ANNOTATION_LINK:
  846. {
  847. tempAnnotationPanel = new CPDFLinkUI();
  848. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  849. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  850. baseAnnot.GetAnnotData().PageIndex,
  851. baseAnnot.GetAnnotData().Annot);
  852. (tempAnnotationPanel as CPDFLinkUI).SetPresentAnnotAttrib(annotParam as LinkParam, baseAnnot.GetAnnotData().Annot as CPDFLinkAnnotation, pdfViewerControl, pdfViewerControl.PDFToolManager.GetDocument().PageCount);
  853. }
  854. break;
  855. case C_ANNOTATION_TYPE.C_ANNOTATION_SOUND:
  856. tempAnnotationPanel = null;
  857. break;
  858. default:
  859. break;
  860. }
  861. }
  862. public void LoadAnnotationPanel(CPDFAnnotationType annotationType)
  863. {
  864. this.pdfViewerControl.PDFToolManager.SetToolType(ToolType.Pan);
  865. currentAnnotationType = annotationType;
  866. annotationPanel = GetAnnotationPanel();
  867. InitAnnotationPanel(annotationType);
  868. ShowCurrentAnnotPanel();
  869. }
  870. private void ShowCurrentAnnotPanel()
  871. {
  872. if (annotationPanel != null)
  873. {
  874. if (annotationPanel is CPDFFreehandUI)
  875. {
  876. (annotationPanel as CPDFFreehandUI)?.SetEraseCheck(false);
  877. }
  878. SetAnnotationPanel(annotationPanel);
  879. ExpandPanel();
  880. ChangeAnnotationData();
  881. EmptyMessage.Visibility = Visibility.Collapsed;
  882. }
  883. else
  884. {
  885. EmptyMessage.Visibility = Visibility.Visible;
  886. SetAnnotationPanel(null);
  887. if (pdfViewerControl != null)
  888. {
  889. EmptyMessage.Visibility = Visibility.Collapsed;
  890. }
  891. }
  892. }
  893. private void ShowTempAnnotPanel()
  894. {
  895. BaseAnnot baseAnnot = pdfViewerControl.PDFToolManager.GetCacheHitTestAnnot();
  896. if (baseAnnot != null)
  897. {
  898. CreatTempAnnotationPanel(baseAnnot);
  899. SetAnnotationPanel(tempAnnotationPanel);
  900. ExpandPanel();
  901. if (tempAnnotationPanel != null)
  902. {
  903. EmptyMessage.Visibility = Visibility.Collapsed;
  904. }
  905. else
  906. {
  907. EmptyMessage.Visibility = Visibility.Visible;
  908. }
  909. }
  910. }
  911. private void PDFToolManager_MouseLeftButtonDownHandler(object sender, MouseEventObject e)
  912. {
  913. SetAnnotEventData();
  914. }
  915. public void ClearPanel()
  916. {
  917. annotationPanel = null;
  918. SetAnnotationPanel(annotationPanel);
  919. EmptyMessage.Visibility = Visibility.Visible;
  920. }
  921. public void SetAnnotEventData()
  922. {
  923. if (pdfViewerControl.PDFToolManager != null)
  924. {
  925. if (pdfViewerControl.PDFToolManager.GetCacheHitTestAnnot() == null && isTempPanel)
  926. {
  927. ShowCurrentAnnotPanel();
  928. isTempPanel = false;
  929. }
  930. else if (pdfViewerControl.PDFToolManager.GetCacheHitTestAnnot() != null)
  931. {
  932. ShowTempAnnotPanel();
  933. isTempPanel = true;
  934. }
  935. }
  936. else
  937. {
  938. if (pdfViewerControl != null && pdfViewerControl.PDFToolManager.GetToolType() == ToolType.CreateAnnot)
  939. {
  940. ShowCurrentAnnotPanel();
  941. isTempPanel = false;
  942. }
  943. else if (annotationPanel is CPDFStampUI && currentAnnotationType == CPDFAnnotationType.Stamp)
  944. {
  945. ShowCurrentAnnotPanel();
  946. }
  947. else if (annotationPanel is CPDFSignatureUI && currentAnnotationType == CPDFAnnotationType.Signature)
  948. {
  949. ShowCurrentAnnotPanel();
  950. }
  951. else if (disableClean == false)
  952. {
  953. ClearPanel();
  954. }
  955. }
  956. }
  957. }
  958. }