CPDFAnnotationControl.xaml.cs 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189
  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. {
  416. AnnotParam signatureParam = new AnnotParam();
  417. CPDFSignatureData SignatureData = pdfAnnotationData as CPDFSignatureData;
  418. SetSignature(ref signatureParam, SignatureData);
  419. BitmapDecoder decoder = null;
  420. switch (signatureParam.CurrentType)
  421. {
  422. case C_ANNOTATION_TYPE.C_ANNOTATION_STAMP:
  423. StampParam stampParam = (StampParam)signatureParam;
  424. stampParam.ImageStream.Seek(0, SeekOrigin.Begin);
  425. decoder = BitmapDecoder.Create(stampParam.ImageStream, BitmapCreateOptions.None, BitmapCacheOption.Default);
  426. break;
  427. case C_ANNOTATION_TYPE.C_ANNOTATION_INK:
  428. if (!string.IsNullOrEmpty(SignatureData.SourcePath))
  429. {
  430. BitmapImage image = new BitmapImage(new Uri(SignatureData.SourcePath));
  431. PngBitmapEncoder encoder = new PngBitmapEncoder();
  432. encoder.Frames.Add(BitmapFrame.Create(image));
  433. MemoryStream memoryStream = new MemoryStream();
  434. encoder.Save(memoryStream);
  435. decoder = BitmapDecoder.Create(memoryStream, BitmapCreateOptions.None, BitmapCacheOption.Default);
  436. }
  437. break;
  438. default:
  439. return;
  440. }
  441. BitmapFrame frame = null;
  442. if (decoder != null && decoder.Frames.Count > 0)
  443. {
  444. frame = decoder.Frames[0];
  445. }
  446. if (frame != null)
  447. {
  448. byte[] imageArray = new byte[frame.PixelWidth * frame.PixelHeight * 4];
  449. if (frame.Format != PixelFormats.Bgra32)
  450. {
  451. FormatConvertedBitmap covert = new FormatConvertedBitmap(
  452. frame,
  453. PixelFormats.Bgra32,
  454. frame.Palette,
  455. 0);
  456. covert.CopyPixels(imageArray, frame.PixelWidth * 4, 0);
  457. }
  458. else
  459. {
  460. frame.CopyPixels(imageArray, frame.PixelWidth * 4, 0);
  461. }
  462. pdfViewerControl.PDFViewTool.GetCPDFViewer().SetStampMouseImage(imageArray, frame.PixelWidth, frame.PixelHeight);
  463. pdfViewerControl.PDFViewTool.GetCPDFViewer().SetIsVisibleCustomMouse(true);
  464. pdfViewerControl.PDFViewTool.GetCPDFViewer().SetIsShowStampMouse(true);
  465. annotHandlerEventArgs = signatureParam;
  466. }
  467. }
  468. break;
  469. case CPDFAnnotationType.Link:
  470. if (annotHandlerEventArgs != null)
  471. {
  472. annotHandlerEventArgs.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_LINK;
  473. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_LINK);
  474. }
  475. break;
  476. case CPDFAnnotationType.Unknow:
  477. pdfViewerControl.PDFToolManager.SetToolType(ToolType.Pan);
  478. return;
  479. default:
  480. break;
  481. }
  482. pdfViewerControl.PDFToolManager.SetToolType(ToolType.CreateAnnot);
  483. if (annotationType != CPDFAnnotationType.Stamp && annotationType != CPDFAnnotationType.Signature)
  484. {
  485. pdfViewerControl.PDFViewTool.GetCPDFViewer().SetIsShowStampMouse(false);
  486. }
  487. DefaultSettingParam defaultSettingParam = pdfViewerControl.PDFViewTool.GetDefaultSettingParam();
  488. defaultSettingParam.SetAnnotParam(annotHandlerEventArgs);
  489. }
  490. public void SetSignature(ref AnnotParam annotParam, CPDFSignatureData stamp)
  491. {
  492. switch (stamp.Type)
  493. {
  494. case SignatureType.TextType:
  495. case SignatureType.ImageType:
  496. {
  497. annotParam = new StampParam();
  498. annotParam.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_STAMP;
  499. (annotParam as StampParam).Transparency = 255;
  500. (annotParam as StampParam).StampType = C_STAMP_TYPE.IMAGE_STAMP;
  501. if (!string.IsNullOrEmpty(stamp.SourcePath))
  502. {
  503. BitmapImage image = new BitmapImage(new Uri(stamp.SourcePath));
  504. PngBitmapEncoder encoder = new PngBitmapEncoder();
  505. encoder.Frames.Add(BitmapFrame.Create(image));
  506. MemoryStream memoryStream = new MemoryStream();
  507. encoder.Save(memoryStream);
  508. (annotParam as StampParam).ImageStream = memoryStream;
  509. }
  510. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_STAMP);
  511. }
  512. break;
  513. case SignatureType.Drawing:
  514. {
  515. annotParam = new InkParam();
  516. (annotParam as InkParam).Transparency = stamp.inkColor.A;
  517. annotParam.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_INK;
  518. List<List<Point>> RawPointList = GetPoints(stamp.DrawingPath);
  519. List<CPoint> linqList = new List<CPoint>();
  520. if (RawPointList != null && RawPointList.Count > 0)
  521. {
  522. List<List<CPoint>> inkPath = new List<List<CPoint>>();
  523. foreach (List<Point> inkPoints in RawPointList)
  524. {
  525. List<CPoint> ink = new List<CPoint>();
  526. foreach (Point point in inkPoints)
  527. {
  528. ink.Add(new CPoint((float)point.X, (float)point.Y));
  529. linqList.Add(new CPoint((float)point.X, (float)point.Y));
  530. }
  531. if (ink.Count > 0)
  532. {
  533. inkPath.Add(ink);
  534. }
  535. }
  536. if (inkPath.Count > 0)
  537. {
  538. (annotParam as InkParam).InkPath = inkPath;
  539. }
  540. }
  541. (annotParam as InkParam).Thickness = stamp.inkThickness;
  542. byte[] InkColor = new byte[] { stamp.inkColor.R, stamp.inkColor.G, stamp.inkColor.B };
  543. (annotParam as InkParam).InkColor = InkColor;
  544. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_INK);
  545. }
  546. break;
  547. default:
  548. break;
  549. }
  550. }
  551. private List<List<Point>> GetPoints(string Path)
  552. {
  553. StrokeCollection Strokes;
  554. List<List<Point>> RawPointList = new List<List<Point>>();
  555. using (FileStream strokeStream = File.OpenRead(Path))
  556. {
  557. Strokes = new StrokeCollection(strokeStream);
  558. }
  559. for (int kk = 0; kk < Strokes.Count; kk++)
  560. {
  561. List<Point> p = new List<Point>();
  562. RawPointList.Add(p);
  563. for (int gg = 0; gg < Strokes[kk].StylusPoints.Count; gg++)
  564. {
  565. var point = Strokes[kk].StylusPoints[gg].ToPoint();
  566. if (point.X >= 0 && point.Y >= 0)
  567. RawPointList[kk].Add(point);
  568. }
  569. }
  570. return RawPointList;
  571. }
  572. private void SetStamp(ref StampParam stampParam, CPDFStampData stamp)
  573. {
  574. stampParam.StampText = stamp.StampText;
  575. stampParam.Author = stamp.Author;
  576. stampParam.Transparency = Convert.ToByte(stamp.Opacity * 255);
  577. stampParam.DateText = stamp.StampTextDate;
  578. stampParam.TextStampColor = stamp.TextColor;
  579. stampParam.TextStampShape = stamp.TextSharp;
  580. if (!string.IsNullOrEmpty(stamp.SourcePath))
  581. {
  582. BitmapImage image = new BitmapImage(new Uri(stamp.SourcePath));
  583. PngBitmapEncoder encoder = new PngBitmapEncoder();
  584. encoder.Frames.Add(BitmapFrame.Create(image));
  585. MemoryStream memoryStream = new MemoryStream();
  586. encoder.Save(memoryStream);
  587. stampParam.ImageStream = memoryStream;
  588. }
  589. else
  590. {
  591. var i = pdfStampUI.CustomStampList.IndexOf(stamp);
  592. Settings.Default.CustomStampList.RemoveAt(i);
  593. Settings.Default.Save();
  594. pdfStampUI.LoadSettings();
  595. return;
  596. }
  597. stampParam.StampType = stamp.Type;
  598. }
  599. public void AnnotationCancel()
  600. {
  601. this.pdfViewerControl.PDFToolManager.SetToolType(ToolType.Pan);
  602. pdfViewerControl.PDFViewTool.GetCPDFViewer().SetIsShowStampMouse(false);
  603. ClearPanel();
  604. }
  605. private void CPDFAnnotationControl_PropertyChanged(object sender, CPDFAnnotationData e)
  606. {
  607. SetAnnotationProperty(e);
  608. }
  609. public void InitAnnotationPanel(CPDFAnnotationType annotationType)
  610. {
  611. switch (annotationType)
  612. {
  613. case CPDFAnnotationType.Highlight:
  614. if (pdfHighlightUI == null)
  615. {
  616. pdfHighlightUI = new CPDFMarkupUI();
  617. }
  618. annotationPanel = pdfHighlightUI;
  619. (annotationPanel as CPDFMarkupUI).InitWithAnnotationType(annotationType);
  620. break;
  621. case CPDFAnnotationType.Underline:
  622. if (pdfUnderlineUI == null)
  623. {
  624. pdfUnderlineUI = new CPDFMarkupUI();
  625. }
  626. annotationPanel = pdfUnderlineUI;
  627. (annotationPanel as CPDFMarkupUI).InitWithAnnotationType(annotationType);
  628. break;
  629. case CPDFAnnotationType.Strikeout:
  630. if (pdfStrikeoutUI == null)
  631. {
  632. pdfStrikeoutUI = new CPDFMarkupUI();
  633. }
  634. annotationPanel = pdfStrikeoutUI;
  635. (annotationPanel as CPDFMarkupUI).InitWithAnnotationType(annotationType);
  636. break;
  637. case CPDFAnnotationType.Squiggly:
  638. if (pdfSquigglyUI == null)
  639. {
  640. pdfSquigglyUI = new CPDFMarkupUI();
  641. }
  642. annotationPanel = pdfSquigglyUI;
  643. (annotationPanel as CPDFMarkupUI).InitWithAnnotationType(annotationType);
  644. break;
  645. case CPDFAnnotationType.Square:
  646. if (pdfSquareUI == null)
  647. {
  648. pdfSquareUI = new CPDFShapeUI();
  649. }
  650. annotationPanel = pdfSquareUI;
  651. (annotationPanel as CPDFShapeUI).InitWithAnnotationType(annotationType);
  652. break;
  653. case CPDFAnnotationType.Circle:
  654. if (pdfCircleUI == null)
  655. {
  656. pdfCircleUI = new CPDFShapeUI();
  657. }
  658. annotationPanel = pdfCircleUI;
  659. (annotationPanel as CPDFShapeUI).InitWithAnnotationType(annotationType);
  660. break;
  661. case CPDFAnnotationType.Arrow:
  662. if (pdfArrowUI == null)
  663. {
  664. pdfArrowUI = new CPDFShapeUI();
  665. }
  666. annotationPanel = pdfArrowUI;
  667. (annotationPanel as CPDFShapeUI).InitWithAnnotationType(annotationType);
  668. break;
  669. case CPDFAnnotationType.Line:
  670. if (pdfLineUI == null)
  671. {
  672. pdfLineUI = new CPDFShapeUI();
  673. }
  674. annotationPanel = pdfLineUI;
  675. (annotationPanel as CPDFShapeUI).InitWithAnnotationType(annotationType);
  676. break;
  677. case CPDFAnnotationType.Freehand:
  678. if (pdfFreehandUI == null)
  679. {
  680. pdfFreehandUI = new CPDFFreehandUI();
  681. pdfFreehandUI.EraseClickHandler += PdfFreehandUI_EraseClickHandler;
  682. pdfFreehandUI.EraseChangeHandler += PdfFreehandUI_EraseChangeHandler;
  683. }
  684. annotationPanel = pdfFreehandUI;
  685. break;
  686. case CPDFAnnotationType.FreeText:
  687. if (pdfFreeTextUI == null)
  688. {
  689. pdfFreeTextUI = new CPDFFreeTextUI();
  690. }
  691. annotationPanel = pdfFreeTextUI;
  692. break;
  693. case CPDFAnnotationType.Note:
  694. if (pdfNoteUI == null)
  695. {
  696. pdfNoteUI = new CPDFNoteUI();
  697. }
  698. annotationPanel = pdfNoteUI;
  699. break;
  700. case CPDFAnnotationType.Stamp:
  701. if (pdfStampUI == null)
  702. {
  703. pdfStampUI = new CPDFStampUI();
  704. }
  705. annotationPanel = pdfStampUI;
  706. break;
  707. case CPDFAnnotationType.Signature:
  708. if (pdfSignatureUI == null)
  709. {
  710. pdfSignatureUI = new CPDFSignatureUI();
  711. }
  712. annotationPanel = pdfSignatureUI;
  713. break;
  714. case CPDFAnnotationType.Link:
  715. if (pdfLinkUI == null)
  716. {
  717. pdfLinkUI = new CPDFLinkUI();
  718. }
  719. LinkParam linkAnnotArgs = new LinkParam();
  720. if (this.pdfViewerControl != null && pdfViewerControl.PDFViewTool != null && pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument() != null)
  721. {
  722. pdfViewerControl.PDFToolManager.SetToolType(ToolType.CreateAnnot);
  723. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_LINK);
  724. pdfLinkUI.InitLinkAnnotArgs(linkAnnotArgs, pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument().PageCount);
  725. }
  726. annotationPanel = pdfLinkUI;
  727. break;
  728. case CPDFAnnotationType.Audio:
  729. //SoundAnnotArgs soundArgs = new SoundAnnotArgs();
  730. //OpenFileDialog openAudioDialog = new OpenFileDialog();
  731. //openAudioDialog.Filter = "Wave Files(*.wav)|*.wav|All Files(*.*;)|*.*;";
  732. //if (openAudioDialog.ShowDialog() == true)
  733. //{
  734. // soundArgs.SoundFilePath = openAudioDialog.FileName;
  735. // this.pdfViewerControl.SetMouseMode(MouseModes.AnnotCreate);
  736. // pdfViewerControl.SetToolParam(soundArgs);
  737. //}
  738. //else
  739. //{
  740. // this.pdfViewerControl.SetMouseMode(MouseModes.PanTool);
  741. // ClearAnnotationBar?.Invoke(this, EventArgs.Empty);
  742. //}
  743. ClearPanel();
  744. break;
  745. case CPDFAnnotationType.Image:
  746. StampParam stampParam = new StampParam();
  747. OpenFileDialog openFileDialog = new OpenFileDialog();
  748. openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
  749. if (openFileDialog.ShowDialog() == true)
  750. {
  751. try
  752. {
  753. BitmapImage image = new BitmapImage(new Uri(openFileDialog.FileName));
  754. PngBitmapEncoder encoder = new PngBitmapEncoder();
  755. encoder.Frames.Add(BitmapFrame.Create(image));
  756. MemoryStream memoryStream = new MemoryStream();
  757. encoder.Save(memoryStream);
  758. stampParam.ImageStream = memoryStream;
  759. stampParam.Transparency = 255;
  760. stampParam.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_STAMP;
  761. stampParam.StampType = C_STAMP_TYPE.IMAGE_STAMP;
  762. BitmapDecoder decoder = BitmapDecoder.Create(stampParam.ImageStream, BitmapCreateOptions.None, BitmapCacheOption.Default);
  763. BitmapFrame frame = null;
  764. if (decoder != null && decoder.Frames.Count > 0)
  765. {
  766. frame = decoder.Frames[0];
  767. }
  768. if (frame != null)
  769. {
  770. byte[] imageArray = new byte[frame.PixelWidth * frame.PixelHeight * 4];
  771. if (frame.Format != PixelFormats.Bgra32)
  772. {
  773. FormatConvertedBitmap covert = new FormatConvertedBitmap(
  774. frame,
  775. PixelFormats.Bgra32,
  776. frame.Palette,
  777. 0);
  778. covert.CopyPixels(imageArray, frame.PixelWidth * 4, 0);
  779. }
  780. else
  781. {
  782. frame.CopyPixels(imageArray, frame.PixelWidth * 4, 0);
  783. }
  784. pdfViewerControl.PDFViewTool.GetCPDFViewer().SetStampMouseImage(imageArray, frame.PixelWidth, frame.PixelHeight);
  785. pdfViewerControl.PDFViewTool.GetCPDFViewer().SetIsVisibleCustomMouse(true);
  786. pdfViewerControl.PDFViewTool.GetCPDFViewer().SetIsShowStampMouse(true);
  787. }
  788. DefaultSettingParam defaultSettingParam = pdfViewerControl.PDFViewTool.GetDefaultSettingParam();
  789. defaultSettingParam.SetAnnotParam(stampParam);
  790. pdfViewerControl.PDFToolManager.SetToolType(ToolType.CreateAnnot);
  791. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_STAMP);
  792. }
  793. catch
  794. {
  795. }
  796. }
  797. else
  798. {
  799. pdfViewerControl.PDFToolManager.SetToolType(ToolType.Pan);
  800. ClearAnnotationBar?.Invoke(this, EventArgs.Empty);
  801. }
  802. ClearPanel();
  803. break;
  804. default:
  805. break;
  806. }
  807. }
  808. private void PdfFreehandUI_EraseChangeHandler(object sender, double e)
  809. {
  810. if (pdfViewerControl != null)
  811. {
  812. pdfViewerControl.PDFViewTool.SetEraseZoom(e);
  813. }
  814. }
  815. private void PdfFreehandUI_EraseClickHandler(object sender, bool e)
  816. {
  817. if (e)
  818. {
  819. pdfViewerControl.PDFViewTool.SetViewerModel(MouseModess.kCustomizeTool);
  820. }
  821. else
  822. {
  823. pdfViewerControl.PDFToolManager.SetToolType(ToolType.CreateAnnot);
  824. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_INK);
  825. }
  826. //if (pdfViewerControl != null)
  827. //{
  828. // CPDFFreehandUI freehandUI = sender as CPDFFreehandUI;
  829. // if (e)
  830. // {
  831. // annotArgs = pdfViewerControl.ToolManager.CurrentAnnotArgs;
  832. // eraseArgs = new EraseArgs();
  833. // eraseArgs.UIBorderColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
  834. // eraseArgs.UIFillColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
  835. // if (freehandUI != null)
  836. // {
  837. // eraseArgs.Thickness = freehandUI.GetEraseThickness();
  838. // }
  839. // else
  840. // {
  841. // eraseArgs.Thickness = 1;
  842. // }
  843. // disableClean = true;
  844. // pdfViewerControl.PDFToolManager.SetToolType(ToolType.CreateAnnot);
  845. // pdfViewerControl.SetToolParam(eraseArgs);
  846. // disableClean = false;
  847. // EmptyMessage.Visibility = Visibility.Collapsed;
  848. // }
  849. // else
  850. // {
  851. // pdfViewerControl.PDFToolManager.SetToolType(ToolType.CreateAnnot);
  852. // FreehandAnnotArgs freehandAnnotArgs = annotArgs as FreehandAnnotArgs;
  853. // if (freehandAnnotArgs == null)
  854. // {
  855. // freehandAnnotArgs = new FreehandAnnotArgs();
  856. // freehandAnnotArgs.InkColor = Colors.Red;
  857. // freehandAnnotArgs.Transparency = 1;
  858. // freehandAnnotArgs.LineWidth = 1;
  859. // annotArgs = freehandAnnotArgs;
  860. // }
  861. // if (freehandUI != null)
  862. // {
  863. // freehandUI.PropertyChanged -= CPDFAnnotationControl_PropertyChanged;
  864. // Dictionary<AnnotAttrib, object> attribDict = new Dictionary<AnnotAttrib, object>();
  865. // attribDict[AnnotAttrib.Color] = freehandAnnotArgs.InkColor;
  866. // attribDict[AnnotAttrib.Transparency] = freehandAnnotArgs.Transparency;
  867. // attribDict[AnnotAttrib.Thickness] = freehandAnnotArgs.LineWidth;
  868. // attribDict[AnnotAttrib.NoteText] = freehandAnnotArgs.Content;
  869. // AnnotAttribEvent annotEvent = AnnotAttribEvent.GetAnnotAttribEvent(freehandAnnotArgs, attribDict);
  870. // freehandUI.SetPresentAnnotAttrib(annotEvent);
  871. // freehandUI.PropertyChanged += CPDFAnnotationControl_PropertyChanged;
  872. // freehandUI.ClearAnnotAttribEvent();
  873. // }
  874. // pdfViewerControl.SetToolParam(freehandAnnotArgs);
  875. // }
  876. //}
  877. }
  878. public void CreatTempAnnotationPanel(BaseAnnot baseAnnot)
  879. {
  880. switch (baseAnnot.CurrentType)
  881. {
  882. case C_ANNOTATION_TYPE.C_ANNOTATION_HIGHLIGHT:
  883. {
  884. tempAnnotationPanel = new CPDFMarkupUI();
  885. (tempAnnotationPanel as CPDFMarkupUI).InitWithAnnotationType(CPDFAnnotationType.Highlight);
  886. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  887. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  888. baseAnnot.GetAnnotData().PageIndex,
  889. baseAnnot.GetAnnotData().Annot);
  890. (tempAnnotationPanel as CPDFMarkupUI).SetPresentAnnotAttrib(annotParam, baseAnnot.GetAnnotData().Annot as CPDFMarkupAnnotation, pdfViewerControl);
  891. }
  892. break;
  893. case C_ANNOTATION_TYPE.C_ANNOTATION_UNDERLINE:
  894. {
  895. tempAnnotationPanel = new CPDFMarkupUI();
  896. (tempAnnotationPanel as CPDFMarkupUI).InitWithAnnotationType(CPDFAnnotationType.Underline);
  897. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  898. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  899. baseAnnot.GetAnnotData().PageIndex,
  900. baseAnnot.GetAnnotData().Annot);
  901. (tempAnnotationPanel as CPDFMarkupUI).SetPresentAnnotAttrib(annotParam, baseAnnot.GetAnnotData().Annot as CPDFMarkupAnnotation, pdfViewerControl);
  902. }
  903. break;
  904. case C_ANNOTATION_TYPE.C_ANNOTATION_STRIKEOUT:
  905. {
  906. tempAnnotationPanel = new CPDFMarkupUI();
  907. (tempAnnotationPanel as CPDFMarkupUI).InitWithAnnotationType(CPDFAnnotationType.Strikeout);
  908. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  909. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  910. baseAnnot.GetAnnotData().PageIndex,
  911. baseAnnot.GetAnnotData().Annot);
  912. (tempAnnotationPanel as CPDFMarkupUI).SetPresentAnnotAttrib(annotParam, baseAnnot.GetAnnotData().Annot as CPDFMarkupAnnotation, pdfViewerControl);
  913. }
  914. break;
  915. case C_ANNOTATION_TYPE.C_ANNOTATION_SQUIGGLY:
  916. {
  917. tempAnnotationPanel = new CPDFMarkupUI();
  918. (tempAnnotationPanel as CPDFMarkupUI).InitWithAnnotationType(CPDFAnnotationType.Squiggly);
  919. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  920. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  921. baseAnnot.GetAnnotData().PageIndex,
  922. baseAnnot.GetAnnotData().Annot);
  923. (tempAnnotationPanel as CPDFMarkupUI).SetPresentAnnotAttrib(annotParam, baseAnnot.GetAnnotData().Annot as CPDFMarkupAnnotation, pdfViewerControl);
  924. }
  925. break;
  926. case C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE:
  927. {
  928. tempAnnotationPanel = new CPDFShapeUI();
  929. (tempAnnotationPanel as CPDFShapeUI).InitWithAnnotationType(CPDFAnnotationType.Square);
  930. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  931. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  932. baseAnnot.GetAnnotData().PageIndex,
  933. baseAnnot.GetAnnotData().Annot);
  934. (tempAnnotationPanel as CPDFShapeUI).SetPresentAnnotAttrib(annotParam, baseAnnot.GetAnnotData().Annot, pdfViewerControl);
  935. }
  936. break;
  937. case C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE:
  938. {
  939. tempAnnotationPanel = new CPDFShapeUI();
  940. (tempAnnotationPanel as CPDFShapeUI).InitWithAnnotationType(CPDFAnnotationType.Circle);
  941. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  942. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  943. baseAnnot.GetAnnotData().PageIndex,
  944. baseAnnot.GetAnnotData().Annot);
  945. (tempAnnotationPanel as CPDFShapeUI).SetPresentAnnotAttrib(annotParam, baseAnnot.GetAnnotData().Annot, pdfViewerControl);
  946. }
  947. break;
  948. case C_ANNOTATION_TYPE.C_ANNOTATION_LINE:
  949. {
  950. tempAnnotationPanel = new CPDFShapeUI();
  951. (tempAnnotationPanel as CPDFShapeUI).InitWithAnnotationType(CPDFAnnotationType.Line);
  952. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  953. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  954. baseAnnot.GetAnnotData().PageIndex,
  955. baseAnnot.GetAnnotData().Annot);
  956. (tempAnnotationPanel as CPDFShapeUI).SetPresentAnnotAttrib(annotParam, baseAnnot.GetAnnotData().Annot, pdfViewerControl);
  957. }
  958. break;
  959. case C_ANNOTATION_TYPE.C_ANNOTATION_INK:
  960. {
  961. CPDFFreehandUI tempFreehandPanel = new CPDFFreehandUI();
  962. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  963. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  964. baseAnnot.GetAnnotData().PageIndex,
  965. baseAnnot.GetAnnotData().Annot);
  966. tempFreehandPanel.SetPresentAnnotAttrib(annotParam, baseAnnot.GetAnnotData().Annot, pdfViewerControl.PDFToolManager.GetDocument(), pdfViewerControl);
  967. tempFreehandPanel.EraseClickHandler += PdfFreehandUI_EraseClickHandler;
  968. tempFreehandPanel.EraseChangeHandler += PdfFreehandUI_EraseChangeHandler;
  969. tempAnnotationPanel = tempFreehandPanel;
  970. }
  971. break;
  972. case C_ANNOTATION_TYPE.C_ANNOTATION_FREETEXT:
  973. {
  974. tempAnnotationPanel = new CPDFFreeTextUI();
  975. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  976. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  977. baseAnnot.GetAnnotData().PageIndex,
  978. baseAnnot.GetAnnotData().Annot);
  979. (tempAnnotationPanel as CPDFFreeTextUI).SetPresentAnnotAttrib(annotParam as FreeTextParam, baseAnnot.GetAnnotData().Annot as CPDFFreeTextAnnotation, pdfViewerControl);
  980. }
  981. break;
  982. case C_ANNOTATION_TYPE.C_ANNOTATION_TEXT:
  983. {
  984. tempAnnotationPanel = new CPDFNoteUI();
  985. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  986. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  987. baseAnnot.GetAnnotData().PageIndex,
  988. baseAnnot.GetAnnotData().Annot);
  989. (tempAnnotationPanel as CPDFNoteUI).SetPresentAnnotAttrib(annotParam as StickyNoteParam, baseAnnot.GetAnnotData().Annot as CPDFTextAnnotation, pdfViewerControl);
  990. }
  991. break;
  992. case C_ANNOTATION_TYPE.C_ANNOTATION_STAMP:
  993. {
  994. tempAnnotationPanel = new CPDFTempStampUI();
  995. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  996. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  997. baseAnnot.GetAnnotData().PageIndex,
  998. baseAnnot.GetAnnotData().Annot);
  999. (tempAnnotationPanel as CPDFTempStampUI).SetPresentAnnotAttrib(annotParam as StampParam, baseAnnot.GetAnnotData().Annot as CPDFStampAnnotation, pdfViewerControl.PDFToolManager.GetDocument(), pdfViewerControl);
  1000. }
  1001. break;
  1002. case C_ANNOTATION_TYPE.C_ANNOTATION_LINK:
  1003. {
  1004. tempAnnotationPanel = new CPDFLinkUI();
  1005. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  1006. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  1007. baseAnnot.GetAnnotData().PageIndex,
  1008. baseAnnot.GetAnnotData().Annot);
  1009. (tempAnnotationPanel as CPDFLinkUI).SetPresentAnnotAttrib(annotParam as LinkParam, baseAnnot.GetAnnotData().Annot as CPDFLinkAnnotation, pdfViewerControl, pdfViewerControl.PDFToolManager.GetDocument().PageCount);
  1010. }
  1011. break;
  1012. case C_ANNOTATION_TYPE.C_ANNOTATION_SOUND:
  1013. tempAnnotationPanel = null;
  1014. break;
  1015. default:
  1016. break;
  1017. }
  1018. }
  1019. public void LoadAnnotationPanel(CPDFAnnotationType annotationType)
  1020. {
  1021. this.pdfViewerControl.PDFToolManager.SetToolType(ToolType.Pan);
  1022. currentAnnotationType = annotationType;
  1023. annotationPanel = GetAnnotationPanel();
  1024. InitAnnotationPanel(annotationType);
  1025. ShowCurrentAnnotPanel();
  1026. }
  1027. private void ShowCurrentAnnotPanel()
  1028. {
  1029. if (annotationPanel != null)
  1030. {
  1031. if (annotationPanel is CPDFFreehandUI)
  1032. {
  1033. (annotationPanel as CPDFFreehandUI)?.SetEraseCheck(false);
  1034. }
  1035. SetAnnotationPanel(annotationPanel);
  1036. ExpandPanel();
  1037. ChangeAnnotationData();
  1038. EmptyMessage.Visibility = Visibility.Collapsed;
  1039. }
  1040. else
  1041. {
  1042. EmptyMessage.Visibility = Visibility.Visible;
  1043. SetAnnotationPanel(null);
  1044. if (pdfViewerControl != null)
  1045. {
  1046. EmptyMessage.Visibility = Visibility.Collapsed;
  1047. }
  1048. }
  1049. }
  1050. private void ShowTempAnnotPanel()
  1051. {
  1052. BaseAnnot baseAnnot = pdfViewerControl.PDFToolManager.GetCacheHitTestAnnot();
  1053. if (baseAnnot != null)
  1054. {
  1055. CreatTempAnnotationPanel(baseAnnot);
  1056. SetAnnotationPanel(tempAnnotationPanel);
  1057. ExpandPanel();
  1058. if (tempAnnotationPanel != null)
  1059. {
  1060. EmptyMessage.Visibility = Visibility.Collapsed;
  1061. }
  1062. else
  1063. {
  1064. EmptyMessage.Visibility = Visibility.Visible;
  1065. }
  1066. }
  1067. }
  1068. private void PDFToolManager_MouseLeftButtonDownHandler(object sender, MouseEventObject e)
  1069. {
  1070. SetAnnotEventData();
  1071. }
  1072. public void ClearPanel()
  1073. {
  1074. annotationPanel = null;
  1075. SetAnnotationPanel(annotationPanel);
  1076. EmptyMessage.Visibility = Visibility.Visible;
  1077. }
  1078. public void SetAnnotEventData()
  1079. {
  1080. if (pdfViewerControl.PDFToolManager != null)
  1081. {
  1082. if (pdfViewerControl.PDFToolManager.GetCacheHitTestAnnot() == null && isTempPanel)
  1083. {
  1084. ShowCurrentAnnotPanel();
  1085. isTempPanel = false;
  1086. }
  1087. else if (pdfViewerControl.PDFToolManager.GetCacheHitTestAnnot() != null)
  1088. {
  1089. ShowTempAnnotPanel();
  1090. isTempPanel = true;
  1091. }
  1092. }
  1093. else
  1094. {
  1095. if (pdfViewerControl != null && pdfViewerControl.PDFToolManager.GetToolType() == ToolType.CreateAnnot)
  1096. {
  1097. ShowCurrentAnnotPanel();
  1098. isTempPanel = false;
  1099. }
  1100. else if (annotationPanel is CPDFStampUI && currentAnnotationType == CPDFAnnotationType.Stamp)
  1101. {
  1102. ShowCurrentAnnotPanel();
  1103. }
  1104. else if (annotationPanel is CPDFSignatureUI && currentAnnotationType == CPDFAnnotationType.Signature)
  1105. {
  1106. ShowCurrentAnnotPanel();
  1107. }
  1108. else if (disableClean == false)
  1109. {
  1110. ClearPanel();
  1111. }
  1112. }
  1113. }
  1114. }
  1115. }