CPDFAnnotationControl.xaml.cs 59 KB

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