CPDFAnnotationControl.xaml.cs 54 KB

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